summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorJarka Kadlecova <jarka@gitlab.com>2017-01-05 14:36:06 +0100
committerJarka Kadlecova <jarka@gitlab.com>2017-01-18 18:38:17 -0500
commitd6b11dafd37e78c12c982c42f274928293cdfa53 (patch)
treee20c62bc3b11b77e366bce2251146d5f5ec86e0c /spec/models
parent270dc22658424ee7f279db99e56c6fc69acd3eb7 (diff)
downloadgitlab-ce-d6b11dafd37e78c12c982c42f274928293cdfa53.tar.gz
Support notes without project
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/ability_spec.rb30
-rw-r--r--spec/models/concerns/mentionable_spec.rb10
-rw-r--r--spec/models/note_spec.rb13
3 files changed, 53 insertions, 0 deletions
diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb
index 1bdf005c823..0b138405f02 100644
--- a/spec/models/ability_spec.rb
+++ b/spec/models/ability_spec.rb
@@ -171,6 +171,36 @@ describe Ability, lib: true do
end
end
+ describe '.users_that_can_read_personal_snippet' do
+ subject { Ability.users_that_can_read_personal_snippet(users, snippet) }
+ let(:users) { create_list(:user, 3) }
+ let(:author) { users[0] }
+
+ context 'private snippet' do
+ let(:snippet) { create(:personal_snippet, :private, author: author) }
+
+ it 'is readable only by its author' do
+ expect(subject).to match_array([author])
+ end
+ end
+
+ context 'internal snippet' do
+ let(:snippet) { create(:personal_snippet, :public, author: author) }
+
+ it 'is readable by all registered users' do
+ expect(subject).to match_array(users)
+ end
+ end
+
+ context 'public snippet' do
+ let(:snippet) { create(:personal_snippet, :public, author: author) }
+
+ it 'is readable by all users' do
+ expect(subject).to match_array(users)
+ end
+ end
+ end
+
describe '.issues_readable_by_user' do
context 'with an admin user' do
it 'returns all given issues' do
diff --git a/spec/models/concerns/mentionable_spec.rb b/spec/models/concerns/mentionable_spec.rb
index 132858950d5..8321e0b89f8 100644
--- a/spec/models/concerns/mentionable_spec.rb
+++ b/spec/models/concerns/mentionable_spec.rb
@@ -138,6 +138,16 @@ describe Issue, "Mentionable" do
issue.update_attributes(description: issues[1].to_reference)
issue.create_new_cross_references!
end
+
+ it 'notifies new references from project snippet note' do
+ snippet = create(:snippet, project: project)
+ note = create(:note, note: issues[0].to_reference, noteable: snippet, project: project, author: author)
+
+ expect(SystemNoteService).to receive(:cross_reference).with(issues[1], any_args)
+
+ note.update_attributes(note: issues[1].to_reference)
+ note.create_new_cross_references!
+ end
end
def create_issue(description:)
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 310fecd8a5c..ddd62d7f0e6 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -52,6 +52,19 @@ describe Note, models: true do
subject { create(:note) }
it { is_expected.to be_valid }
end
+
+ context 'when project is missing for a project related note' do
+ subject { build(:note, project: nil, noteable: build_stubbed(:issue)) }
+ it { is_expected.to be_invalid }
+ end
+
+ context 'when noteable is a personal snippet' do
+ subject { create(:note_on_personal_snippet) }
+
+ it 'is valid without project' do
+ is_expected.to be_valid
+ end
+ end
end
describe "Commit notes" do