diff options
author | Heinrich Lee Yu <heinrich@gitlab.com> | 2019-02-06 10:31:46 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-02-06 10:31:46 +0000 |
commit | a04d9ba90c0d1df02f613b7aa01ef598e1ac5b28 (patch) | |
tree | 4a8889592e2290160926ede70aa0cf37bd93519f /spec/services/notes | |
parent | c5f1b8346860aa764369a3d156047c9e2c7317ca (diff) | |
download | gitlab-ce-a04d9ba90c0d1df02f613b7aa01ef598e1ac5b28.tar.gz |
Add reply to notes to turn into discussions
Diffstat (limited to 'spec/services/notes')
-rw-r--r-- | spec/services/notes/build_service_spec.rb | 40 | ||||
-rw-r--r-- | spec/services/notes/create_service_spec.rb | 37 |
2 files changed, 77 insertions, 0 deletions
diff --git a/spec/services/notes/build_service_spec.rb b/spec/services/notes/build_service_spec.rb index 9aaccb4bffe..af4daff336b 100644 --- a/spec/services/notes/build_service_spec.rb +++ b/spec/services/notes/build_service_spec.rb @@ -123,6 +123,46 @@ describe Notes::BuildService do end end + context 'when replying to individual note' do + let(:note) { create(:note_on_issue) } + + subject { described_class.new(project, author, note: 'Test', in_reply_to_discussion_id: note.discussion_id).execute } + + shared_examples 'an individual note reply' do + it 'builds another individual note' do + expect(subject).to be_valid + expect(subject).to be_a(Note) + expect(subject.discussion_id).not_to eq(note.discussion_id) + end + end + + context 'when reply_to_individual_notes is disabled' do + before do + stub_feature_flags(reply_to_individual_notes: false) + end + + it_behaves_like 'an individual note reply' + end + + context 'when reply_to_individual_notes is enabled' do + before do + stub_feature_flags(reply_to_individual_notes: true) + end + + it 'sets the note up to be in reply to that note' do + expect(subject).to be_valid + expect(subject).to be_a(DiscussionNote) + expect(subject.discussion_id).to eq(note.discussion_id) + end + + context 'when noteable does not support replies' do + let(:note) { create(:note_on_commit) } + + it_behaves_like 'an individual note reply' + end + end + end + it 'builds a note without saving it' do new_note = described_class.new(project, author, diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index 1b9ba42cfd6..48f1d696ff6 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -278,5 +278,42 @@ describe Notes::CreateService do expect(note.note).to eq(':smile:') end end + + context 'reply to individual note' do + let(:existing_note) { create(:note_on_issue, noteable: issue, project: project) } + let(:reply_opts) { opts.merge(in_reply_to_discussion_id: existing_note.discussion_id) } + + subject { described_class.new(project, user, reply_opts).execute } + + context 'when reply_to_individual_notes is disabled' do + before do + stub_feature_flags(reply_to_individual_notes: false) + end + + it 'creates an individual note' do + expect(subject.type).to eq(nil) + expect(subject.discussion_id).not_to eq(existing_note.discussion_id) + end + + it 'does not convert existing note' do + expect { subject }.not_to change { existing_note.reload.type } + end + end + + context 'when reply_to_individual_notes is enabled' do + before do + stub_feature_flags(reply_to_individual_notes: true) + end + + it 'creates a DiscussionNote in reply to existing note' do + expect(subject).to be_a(DiscussionNote) + expect(subject.discussion_id).to eq(existing_note.discussion_id) + end + + it 'converts existing note to DiscussionNote' do + expect { subject }.to change { existing_note.reload.type }.from(nil).to('DiscussionNote') + end + end + end end end |