diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-18 21:06:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-18 21:06:21 +0300 |
commit | 6d59e989185a7d2645792b713d1b5d95d46651fd (patch) | |
tree | f89d869a6c557a3e6e0b9305290259ab1d6fb589 /spec/finders/snippets_finder_spec.rb | |
parent | 5c521d1f9b1e389e2f9b2b5fccf3798159a10f8d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders/snippets_finder_spec.rb')
-rw-r--r-- | spec/finders/snippets_finder_spec.rb | 59 |
1 files changed, 43 insertions, 16 deletions
diff --git a/spec/finders/snippets_finder_spec.rb b/spec/finders/snippets_finder_spec.rb index e7372189d17..bcb762664f7 100644 --- a/spec/finders/snippets_finder_spec.rb +++ b/spec/finders/snippets_finder_spec.rb @@ -17,16 +17,27 @@ describe SnippetsFinder do end describe '#execute' do - set(:user) { create(:user) } - set(:private_personal_snippet) { create(:personal_snippet, :private, author: user) } - set(:internal_personal_snippet) { create(:personal_snippet, :internal, author: user) } - set(:public_personal_snippet) { create(:personal_snippet, :public, author: user) } + let_it_be(:user) { create(:user) } + let_it_be(:admin) { create(:admin) } + let_it_be(:group) { create(:group, :public) } + let_it_be(:project) { create(:project, :public, group: group) } + + let_it_be(:private_personal_snippet) { create(:personal_snippet, :private, author: user) } + let_it_be(:internal_personal_snippet) { create(:personal_snippet, :internal, author: user) } + let_it_be(:public_personal_snippet) { create(:personal_snippet, :public, author: user) } + + let_it_be(:private_project_snippet) { create(:project_snippet, :private, project: project) } + let_it_be(:internal_project_snippet) { create(:project_snippet, :internal, project: project) } + let_it_be(:public_project_snippet) { create(:project_snippet, :public, project: project) } context 'filter by scope' do it "returns all snippets for 'all' scope" do snippets = described_class.new(user, scope: :all).execute - expect(snippets).to contain_exactly(private_personal_snippet, internal_personal_snippet, public_personal_snippet) + expect(snippets).to contain_exactly( + private_personal_snippet, internal_personal_snippet, public_personal_snippet, + internal_project_snippet, public_project_snippet + ) end it "returns all snippets for 'are_private' scope" do @@ -38,13 +49,13 @@ describe SnippetsFinder do it "returns all snippets for 'are_internal' scope" do snippets = described_class.new(user, scope: :are_internal).execute - expect(snippets).to contain_exactly(internal_personal_snippet) + expect(snippets).to contain_exactly(internal_personal_snippet, internal_project_snippet) end - it "returns all snippets for 'are_private' scope" do + it "returns all snippets for 'are_public' scope" do snippets = described_class.new(user, scope: :are_public).execute - expect(snippets).to contain_exactly(public_personal_snippet) + expect(snippets).to contain_exactly(public_personal_snippet, public_project_snippet) end end @@ -86,7 +97,6 @@ describe SnippetsFinder do end it 'returns all snippets for an admin' do - admin = create(:user, :admin) snippets = described_class.new(admin, author: user).execute expect(snippets).to contain_exactly(private_personal_snippet, internal_personal_snippet, public_personal_snippet) @@ -94,12 +104,6 @@ describe SnippetsFinder do end context 'project snippets' do - let(:group) { create(:group, :public) } - let(:project) { create(:project, :public, group: group) } - let!(:private_project_snippet) { create(:project_snippet, :private, project: project) } - let!(:internal_project_snippet) { create(:project_snippet, :internal, project: project) } - let!(:public_project_snippet) { create(:project_snippet, :public, project: project) } - it 'returns public personal and project snippets for unauthorized user' do snippets = described_class.new(nil, project: project).execute @@ -147,7 +151,6 @@ describe SnippetsFinder do end it 'returns all snippets for an admin' do - admin = create(:user, :admin) snippets = described_class.new(admin, project: project).execute expect(snippets).to contain_exactly(private_project_snippet, internal_project_snippet, public_project_snippet) @@ -174,6 +177,30 @@ describe SnippetsFinder do end end + context 'explore snippets' do + it 'returns only public personal snippets for unauthenticated users' do + snippets = described_class.new(nil, explore: true).execute + + expect(snippets).to contain_exactly(public_personal_snippet) + end + + it 'also returns internal personal snippets for authenticated users' do + snippets = described_class.new(user, explore: true).execute + + expect(snippets).to contain_exactly( + internal_personal_snippet, public_personal_snippet + ) + end + + it 'returns all personal snippets for admins' do + snippets = described_class.new(admin, explore: true).execute + + expect(snippets).to contain_exactly( + private_personal_snippet, internal_personal_snippet, public_personal_snippet + ) + end + end + context 'when the user cannot read cross project' do before do allow(Ability).to receive(:allowed?).and_call_original |