summaryrefslogtreecommitdiff
path: root/spec/policies
diff options
context:
space:
mode:
authorJarka Kadlecova <jarka@gitlab.com>2017-09-01 14:03:57 +0200
committerJarka Kadlecova <jarka@gitlab.com>2017-09-14 14:50:32 +0200
commit994e7d135947ca162c147c5e0992a0190de22808 (patch)
treecd9ea4d93269c8597541f8c59e89a83ca2b56d2b /spec/policies
parent2b82f907abf2074ac332531d6142893d081f44b9 (diff)
downloadgitlab-ce-994e7d135947ca162c147c5e0992a0190de22808.tar.gz
Create system notes for MR too, improve doc + clean up code
Diffstat (limited to 'spec/policies')
-rw-r--r--spec/policies/issuable_policy_spec.rb2
-rw-r--r--spec/policies/note_policy_spec.rb23
2 files changed, 21 insertions, 4 deletions
diff --git a/spec/policies/issuable_policy_spec.rb b/spec/policies/issuable_policy_spec.rb
index 9b399d764ea..2cf669e8191 100644
--- a/spec/policies/issuable_policy_spec.rb
+++ b/spec/policies/issuable_policy_spec.rb
@@ -16,7 +16,7 @@ describe IssuablePolicy, models: true do
context 'when the user is a project member' do
before do
- project.team << [user, :guest]
+ project.add_guest(user)
end
it 'can create a note' do
diff --git a/spec/policies/note_policy_spec.rb b/spec/policies/note_policy_spec.rb
index 70a99ed0198..58d36a2c84e 100644
--- a/spec/policies/note_policy_spec.rb
+++ b/spec/policies/note_policy_spec.rb
@@ -5,9 +5,15 @@ describe NotePolicy, mdoels: true do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let(:issue) { create(:issue, project: project) }
- let(:note) { create(:note, noteable: issue, author: user, project: project) }
- let(:policies) { described_class.new(user, note) }
+ def policies(noteable = nil)
+ return @policies if @policies
+
+ noteable ||= issue
+ note = create(:note, noteable: noteable, author: user, project: project)
+
+ @policies = described_class.new(user, note)
+ end
context 'when the project is public' do
context 'when the note author is not a project member' do
@@ -19,6 +25,17 @@ describe NotePolicy, mdoels: true do
end
end
+ context 'when the noteable is a snippet' do
+ it 'can edit note' do
+ policies = policies(create(:project_snippet, project: project))
+
+ expect(policies).to be_allowed(:update_note)
+ expect(policies).to be_allowed(:admin_note)
+ expect(policies).to be_allowed(:resolve_note)
+ expect(policies).to be_allowed(:read_note)
+ end
+ end
+
context 'when a discussion is locked' do
before do
issue.update_attribute(:discussion_locked, true)
@@ -29,7 +46,7 @@ describe NotePolicy, mdoels: true do
project.add_developer(user)
end
- it 'can eddit a note' do
+ it 'can edit a note' do
expect(policies).to be_allowed(:update_note)
expect(policies).to be_allowed(:admin_note)
expect(policies).to be_allowed(:resolve_note)