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:
authorJarka Kadlecova <jarka@gitlab.com>2017-05-03 11:48:01 +0300
committerJarka Kadlecova <jarka@gitlab.com>2017-05-05 16:45:49 +0300
commite4f7b87ddb4ba83456871eb83b841192b1b56799 (patch)
treecf79d159784d2c5573acf8a56a8ea09bccaf2d81 /spec/services/notes
parent729c006ff82fcb87afe8eb3e6a21254892f43afd (diff)
Support comments for personal snippets
Diffstat (limited to 'spec/services/notes')
-rw-r--r--spec/services/notes/build_service_spec.rb74
1 files changed, 73 insertions, 1 deletions
diff --git a/spec/services/notes/build_service_spec.rb b/spec/services/notes/build_service_spec.rb
index f9dd5541b10..133175769ca 100644
--- a/spec/services/notes/build_service_spec.rb
+++ b/spec/services/notes/build_service_spec.rb
@@ -29,10 +29,82 @@ describe Notes::BuildService, services: true do
expect(new_note.errors[:base]).to include('Discussion to reply to cannot be found')
end
end
+
+ context 'personal snippet note' do
+ def reply(note, user = nil)
+ user ||= create(:user)
+
+ described_class.new(nil,
+ user,
+ note: 'Test',
+ in_reply_to_discussion_id: note.discussion_id).execute
+ end
+
+ let(:snippet_author) { create(:user) }
+
+ context 'when a snippet is public' do
+ it 'creates a reply note' do
+ snippet = create(:personal_snippet, :public)
+ note = create(:discussion_note_on_personal_snippet, noteable: snippet)
+
+ new_note = reply(note)
+
+ expect(new_note).to be_valid
+ expect(new_note.in_reply_to?(note)).to be_truthy
+ end
+ end
+
+ context 'when a snippet is private' do
+ let(:snippet) { create(:personal_snippet, :private, author: snippet_author) }
+ let(:note) { create(:discussion_note_on_personal_snippet, noteable: snippet) }
+
+ it 'creates a reply note when the author replies' do
+ new_note = reply(note, snippet_author)
+
+ expect(new_note).to be_valid
+ expect(new_note.in_reply_to?(note)).to be_truthy
+ end
+
+ it 'sets an error when another user replies' do
+ new_note = reply(note)
+
+ expect(new_note.errors[:base]).to include('Discussion to reply to cannot be found')
+ end
+ end
+
+ context 'when a snippet is internal' do
+ let(:snippet) { create(:personal_snippet, :internal, author: snippet_author) }
+ let(:note) { create(:discussion_note_on_personal_snippet, noteable: snippet) }
+
+ it 'creates a reply note when the author replies' do
+ new_note = reply(note, snippet_author)
+
+ expect(new_note).to be_valid
+ expect(new_note.in_reply_to?(note)).to be_truthy
+ end
+
+ it 'creates a reply note when a regular user replies' do
+ new_note = reply(note)
+
+ expect(new_note).to be_valid
+ expect(new_note.in_reply_to?(note)).to be_truthy
+ end
+
+ it 'sets an error when an external user replies' do
+ new_note = reply(note, create(:user, :external))
+
+ expect(new_note.errors[:base]).to include('Discussion to reply to cannot be found')
+ end
+ end
+ end
end
it 'builds a note without saving it' do
- new_note = described_class.new(project, author, noteable_type: note.noteable_type, noteable_id: note.noteable_id, note: 'Test').execute
+ new_note = described_class.new(project,
+ author,
+ noteable_type: note.noteable_type,
+ noteable_id: note.noteable_id,
+ note: 'Test').execute
expect(new_note).to be_valid
expect(new_note).not_to be_persisted
end