diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-06 21:08:48 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-06 21:08:48 +0000 |
commit | a89cb5cbdd832d4d9e80517973aceda6bc0a3856 (patch) | |
tree | 574475bd0901a2f8906d36a4728b8bbb95b41e1c /spec/serializers | |
parent | 0d6fa033121a9bef708b8f2de186c4034c61d4a3 (diff) | |
download | gitlab-ce-a89cb5cbdd832d4d9e80517973aceda6bc0a3856.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/serializers')
-rw-r--r-- | spec/serializers/container_repositories_serializer_spec.rb | 84 | ||||
-rw-r--r-- | spec/serializers/diff_file_entity_spec.rb | 2 |
2 files changed, 85 insertions, 1 deletions
diff --git a/spec/serializers/container_repositories_serializer_spec.rb b/spec/serializers/container_repositories_serializer_spec.rb new file mode 100644 index 00000000000..382778389b3 --- /dev/null +++ b/spec/serializers/container_repositories_serializer_spec.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ContainerRepositoriesSerializer do + let(:user) { create(:user) } + let(:project) { create(:project) } + let(:resource) { create(:container_repository, name: 'image', project: project) } + let(:params) { { current_user: user, project: project } } + + before do + project.add_developer(user) + + stub_container_registry_config(enabled: true) + stub_container_registry_tags(repository: /image/, tags: %w(rootA latest)) + end + + describe '#represent' do + subject do + described_class.new(params).represent(resource) + end + + it 'has basic attributes' do + expect(subject).to include(:id, :name, :path, :location, :created_at, :tags_path, :destroy_path) + end + end + + describe '#represent_read_only' do + subject do + described_class.new(current_user: user, project: project).represent_read_only(resource) + end + + it 'does not include destroy_path' do + expect(subject).to include(:id, :name, :path, :location, :created_at, :tags_path) + expect(subject).not_to include(:destroy_path) + end + end + + describe '#with_pagination' do + let(:request) do + double( + url: "#{Gitlab.config.gitlab.url}:8080/#{project.namespace_id}/#{project.id}/container_registry?#{query.to_query}", + query_parameters: query + ) + end + + let(:response) { spy('response') } + let(:resource) { ContainerRepository.all } + let(:query) { { page: 1, per_page: 2 } } + + let(:serializer) do + described_class + .new(current_user: user, project: project) + .with_pagination(request, response) + end + + subject do + serializer.represent(resource) + end + + it 'creates a paginated serializer' do + expect(serializer).to be_paginated + end + + context 'when multiple ContainerRepository objects are serialized' do + before do + create_list(:container_repository, 5, project: project) + end + + it 'serializes appropriate number of objects' do + expect(subject.count).to be 2 + end + + it 'appends relevant headers' do + expect(response).to include_pagination_headers + expect(response).to receive(:[]=).with('X-Total', '5') + expect(response).to receive(:[]=).with('X-Total-Pages', '3') + expect(response).to receive(:[]=).with('X-Per-Page', '2') + + subject + end + end + end +end diff --git a/spec/serializers/diff_file_entity_spec.rb b/spec/serializers/diff_file_entity_spec.rb index 65b62f8aa16..3e341a58a15 100644 --- a/spec/serializers/diff_file_entity_spec.rb +++ b/spec/serializers/diff_file_entity_spec.rb @@ -49,7 +49,7 @@ describe DiffFileEntity do end end - context '#parallel_diff_lines' do + describe '#parallel_diff_lines' do let(:options) { { diff_view: :parallel } } it 'exposes parallel diff lines correctly' do |