diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-28 15:06:57 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-28 15:06:57 +0000 |
commit | 7cdd70dcec27402e89e65451b4b1feb75b5eb267 (patch) | |
tree | 1691c8e1afd469fa426ecf5bc127de8df16d4855 /spec/finders | |
parent | 79348faced5e7e62103ad27f6a6594dfdca463e2 (diff) | |
download | gitlab-ce-7cdd70dcec27402e89e65451b4b1feb75b5eb267.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders')
-rw-r--r-- | spec/finders/snippets_finder_spec.rb | 87 |
1 files changed, 80 insertions, 7 deletions
diff --git a/spec/finders/snippets_finder_spec.rb b/spec/finders/snippets_finder_spec.rb index bcb762664f7..8f83cb77709 100644 --- a/spec/finders/snippets_finder_spec.rb +++ b/spec/finders/snippets_finder_spec.rb @@ -60,10 +60,20 @@ describe SnippetsFinder do end context 'filter by author' do - it 'returns all public and internal snippets' do - snippets = described_class.new(create(:user), author: user).execute + context 'when the author is a User object' do + it 'returns all public and internal snippets' do + snippets = described_class.new(create(:user), author: user).execute - expect(snippets).to contain_exactly(internal_personal_snippet, public_personal_snippet) + expect(snippets).to contain_exactly(internal_personal_snippet, public_personal_snippet) + end + end + + context 'when the author is the User id' do + it 'returns all public and internal snippets' do + snippets = described_class.new(create(:user), author: user.id).execute + + expect(snippets).to contain_exactly(internal_personal_snippet, public_personal_snippet) + end end it 'returns internal snippets' do @@ -101,13 +111,33 @@ describe SnippetsFinder do expect(snippets).to contain_exactly(private_personal_snippet, internal_personal_snippet, public_personal_snippet) end + + context 'when author is not valid' do + it 'returns quickly' do + finder = described_class.new(admin, author: 1234) + + expect(finder).not_to receive(:init_collection) + expect(Snippet).to receive(:none).and_call_original + expect(finder.execute).to be_empty + end + end end - context 'project snippets' do - it 'returns public personal and project snippets for unauthorized user' do - snippets = described_class.new(nil, project: project).execute + context 'filter by project' do + context 'when project is a Project object' do + it 'returns public personal and project snippets for unauthorized user' do + snippets = described_class.new(nil, project: project).execute - expect(snippets).to contain_exactly(public_project_snippet) + expect(snippets).to contain_exactly(public_project_snippet) + end + end + + context 'when project is a Project id' do + it 'returns public personal and project snippets for unauthorized user' do + snippets = described_class.new(nil, project: project.id).execute + + expect(snippets).to contain_exactly(public_project_snippet) + end end it 'returns public and internal snippets for non project members' do @@ -175,6 +205,49 @@ describe SnippetsFinder do ) end end + + context 'when project is not valid' do + it 'returns quickly' do + finder = described_class.new(admin, project: 1234) + + expect(finder).not_to receive(:init_collection) + expect(Snippet).to receive(:none).and_call_original + expect(finder.execute).to be_empty + end + end + end + + context 'filter by snippet type' do + context 'when filtering by only_personal snippet' do + it 'returns only personal snippet' do + snippets = described_class.new(admin, only_personal: true).execute + + expect(snippets).to contain_exactly(private_personal_snippet, + internal_personal_snippet, + public_personal_snippet) + end + end + + context 'when filtering by only_project snippet' do + it 'returns only project snippet' do + snippets = described_class.new(admin, only_project: true).execute + + expect(snippets).to contain_exactly(private_project_snippet, + internal_project_snippet, + public_project_snippet) + end + end + end + + context 'filtering by ids' do + it 'returns only personal snippet' do + snippets = described_class.new( + admin, ids: [private_personal_snippet.id, + internal_personal_snippet.id] + ).execute + + expect(snippets).to contain_exactly(private_personal_snippet, internal_personal_snippet) + end end context 'explore snippets' do |