diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/lib/api/entities | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/lib/api/entities')
-rw-r--r-- | spec/lib/api/entities/branch_spec.rb | 28 | ||||
-rw-r--r-- | spec/lib/api/entities/design_management/design_spec.rb | 19 | ||||
-rw-r--r-- | spec/lib/api/entities/project_repository_storage_move_spec.rb | 21 | ||||
-rw-r--r-- | spec/lib/api/entities/snippet_spec.rb | 94 |
4 files changed, 162 insertions, 0 deletions
diff --git a/spec/lib/api/entities/branch_spec.rb b/spec/lib/api/entities/branch_spec.rb new file mode 100644 index 00000000000..604f56c0cb2 --- /dev/null +++ b/spec/lib/api/entities/branch_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe API::Entities::Branch do + describe '#as_json' do + subject { entity.as_json } + + let(:project) { create(:project, :public, :repository) } + let(:repository) { project.repository } + let(:branch) { repository.find_branch('master') } + let(:entity) { described_class.new(branch, project: project) } + + it 'includes basic fields', :aggregate_failures do + is_expected.to include( + name: 'master', + commit: a_kind_of(Hash), + merged: false, + protected: false, + developers_can_push: false, + developers_can_merge: false, + can_push: false, + default: true, + web_url: Gitlab::Routing.url_helpers.project_tree_url(project, 'master') + ) + end + end +end diff --git a/spec/lib/api/entities/design_management/design_spec.rb b/spec/lib/api/entities/design_management/design_spec.rb new file mode 100644 index 00000000000..50ca3b43c6a --- /dev/null +++ b/spec/lib/api/entities/design_management/design_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe API::Entities::DesignManagement::Design do + let_it_be(:design) { create(:design) } + let(:entity) { described_class.new(design, request: double) } + + subject { entity.as_json } + + it 'has the correct attributes' do + expect(subject).to eq({ + id: design.id, + project_id: design.project_id, + filename: design.filename, + image_url: ::Gitlab::UrlBuilder.build(design) + }) + end +end diff --git a/spec/lib/api/entities/project_repository_storage_move_spec.rb b/spec/lib/api/entities/project_repository_storage_move_spec.rb new file mode 100644 index 00000000000..1c38c8231d4 --- /dev/null +++ b/spec/lib/api/entities/project_repository_storage_move_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe API::Entities::ProjectRepositoryStorageMove do + describe '#as_json' do + subject { entity.as_json } + + let(:storage_move) { build(:project_repository_storage_move, :scheduled, destination_storage_name: 'test_second_storage') } + let(:entity) { described_class.new(storage_move) } + + it 'includes basic fields' do + is_expected.to include( + state: 'scheduled', + source_storage_name: 'default', + destination_storage_name: 'test_second_storage', + project: a_kind_of(Hash) + ) + end + end +end diff --git a/spec/lib/api/entities/snippet_spec.rb b/spec/lib/api/entities/snippet_spec.rb new file mode 100644 index 00000000000..dada0942e49 --- /dev/null +++ b/spec/lib/api/entities/snippet_spec.rb @@ -0,0 +1,94 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ::API::Entities::Snippet do + let_it_be(:user) { create(:user) } + let_it_be(:personal_snippet) { create(:personal_snippet, :repository, author: user ) } + let_it_be(:project_snippet) { create(:project_snippet, :repository, author: user) } + + let(:entity) { described_class.new(snippet) } + + subject { entity.as_json } + + shared_examples 'common attributes' do + it { expect(subject[:id]).to eq snippet.id } + it { expect(subject[:title]).to eq snippet.title } + it { expect(subject[:description]).to eq snippet.description } + it { expect(subject[:updated_at]).to eq snippet.updated_at } + it { expect(subject[:created_at]).to eq snippet.created_at } + it { expect(subject[:project_id]).to eq snippet.project_id } + it { expect(subject[:visibility]).to eq snippet.visibility } + it { expect(subject).to include(:author) } + + describe 'file_name' do + it 'returns attribute from repository' do + expect(subject[:file_name]).to eq snippet.blobs.first.path + end + + context 'when repository is empty' do + it 'returns attribute from db' do + allow(snippet.repository).to receive(:empty?).and_return(true) + + expect(subject[:file_name]).to eq snippet.file_name + end + end + end + + describe 'ssh_url_to_repo' do + it 'returns attribute' do + expect(subject[:ssh_url_to_repo]).to eq snippet.ssh_url_to_repo + end + + context 'when repository does not exist' do + it 'does not include attribute' do + allow(snippet).to receive(:repository_exists?).and_return(false) + + expect(subject).not_to include(:ssh_url_to_repo) + end + end + end + + describe 'http_url_to_repo' do + it 'returns attribute' do + expect(subject[:http_url_to_repo]).to eq snippet.http_url_to_repo + end + + context 'when repository does not exist' do + it 'does not include attribute' do + allow(snippet).to receive(:repository_exists?).and_return(false) + + expect(subject).not_to include(:http_url_to_repo) + end + end + end + end + + context 'with PersonalSnippet' do + let(:snippet) { personal_snippet } + + it_behaves_like 'common attributes' + + it 'returns snippet web_url attribute' do + expect(subject[:web_url]).to match("/snippets/#{snippet.id}") + end + + it 'returns snippet raw_url attribute' do + expect(subject[:raw_url]).to match("/snippets/#{snippet.id}/raw") + end + end + + context 'with ProjectSnippet' do + let(:snippet) { project_snippet } + + it_behaves_like 'common attributes' + + it 'returns snippet web_url attribute' do + expect(subject[:web_url]).to match("#{snippet.project.full_path}/snippets/#{snippet.id}") + end + + it 'returns snippet raw_url attribute' do + expect(subject[:raw_url]).to match("#{snippet.project.full_path}/snippets/#{snippet.id}/raw") + end + end +end |