Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-06-22 23:44:24 +0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-06-22 23:44:24 +0300
commit8f9b64c720d55ee40066d5a6b1017ab95dbd9781 (patch)
treef7550c3a2353946f7524065ac2919a59ee6867f2 /spec/models/snippet_spec.rb
parent1d9bbb0b8ef4d67833fc99a5c6ffcdafa43a38d6 (diff)
Fix internal snippets can be searched by anyone
Diffstat (limited to 'spec/models/snippet_spec.rb')
-rw-r--r--spec/models/snippet_spec.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index 789816bf2c7..57365571a7b 100644
--- a/spec/models/snippet_spec.rb
+++ b/spec/models/snippet_spec.rb
@@ -72,7 +72,7 @@ describe Snippet, models: true do
end
end
- describe '#search_code' do
+ describe '.search_code' do
let(:snippet) { create(:snippet, content: 'class Foo; end') }
it 'returns snippets with matching content' do
@@ -88,6 +88,26 @@ describe Snippet, models: true do
end
end
+ describe '.accessible_to' do
+ let(:author) { create(:author) }
+ let(:user) { create(:user) }
+ let!(:public_snippet) { create(:snippet, :public) }
+ let!(:internal_snippet) { create(:snippet, :internal) }
+ let!(:private_snippet) { create(:snippet, :private, author: author) }
+
+ it 'returns only public snippets when user is nil' do
+ expect(described_class.accessible_to(nil)).to eq [public_snippet]
+ end
+
+ it 'returns only public, and internal snippets when user is not nil' do
+ expect(described_class.accessible_to(user)).to match_array [public_snippet, internal_snippet]
+ end
+
+ it 'returns snippets where the user is the author' do
+ expect(described_class.accessible_to(author)).to match_array [public_snippet, internal_snippet, private_snippet]
+ end
+ end
+
describe '#participants' do
let(:project) { create(:project, :public) }
let(:snippet) { create(:snippet, content: 'foo', project: project) }