summaryrefslogtreecommitdiff
path: root/spec/services/notes
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-03-17 13:25:52 -0600
committerLuke "Jared" Bennett <lbennett@gitlab.com>2017-04-05 17:44:14 +0100
commit79889a6aa3dc878d196d0f2f445ab6b10ef10c74 (patch)
tree25367a69b4a529335e106d0d65c2d9a38e97f092 /spec/services/notes
parent80b2e18fb62b8da7410f90b3e5340b9e63e765a3 (diff)
downloadgitlab-ce-79889a6aa3dc878d196d0f2f445ab6b10ef10c74.tar.gz
Add specs
Diffstat (limited to 'spec/services/notes')
-rw-r--r--spec/services/notes/build_service_spec.rb39
-rw-r--r--spec/services/notes/create_service_spec.rb3
2 files changed, 37 insertions, 5 deletions
diff --git a/spec/services/notes/build_service_spec.rb b/spec/services/notes/build_service_spec.rb
index 065f6eeeacb..464b24cb447 100644
--- a/spec/services/notes/build_service_spec.rb
+++ b/spec/services/notes/build_service_spec.rb
@@ -1,5 +1,40 @@
require 'spec_helper'
-describe Notes::CreateService, services: true do
- # TODO: Test
+describe Notes::BuildService, services: true do
+ let(:note) { create(:discussion_note_on_issue) }
+ let(:project) { note.project }
+ let(:author) { note.author }
+
+ describe '#execute' do
+ context 'when in_reply_to_discussion_id is specified' do
+ context 'when a note with that original discussion ID exists' do
+ it 'sets the note up to be in reply to that note' do
+ new_note = described_class.new(project, author, note: 'Test', in_reply_to_discussion_id: note.original_discussion_id).execute
+ expect(new_note).to be_valid
+ expect(new_note.in_reply_to?(note)).to be_truthy
+ end
+ end
+
+ context 'when a note with that discussion ID exists' do
+ it 'sets the note up to be in reply to that note' do
+ new_note = described_class.new(project, author, note: 'Test', in_reply_to_discussion_id: note.discussion_id).execute
+ expect(new_note).to be_valid
+ expect(new_note.in_reply_to?(note)).to be_truthy
+ end
+ end
+
+ context 'when no note with that discussion ID exists' do
+ it 'sets an error' do
+ new_note = described_class.new(project, author, note: 'Test', in_reply_to_discussion_id: 'foo').execute
+ expect(new_note.errors[:base]).to include('Discussion to reply to cannot be found')
+ 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
+ expect(new_note).to be_valid
+ expect(new_note).not_to be_persisted
+ end
+ end
end
diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb
index b406afeb34d..152c6d20daa 100644
--- a/spec/services/notes/create_service_spec.rb
+++ b/spec/services/notes/create_service_spec.rb
@@ -13,9 +13,6 @@ describe Notes::CreateService, services: true do
project.team << [user, :master]
end
- # TODO: Test in_reply_to_discussion_id
- # TODO: Test new_discussion
-
context "valid params" do
it 'returns a valid note' do
note = described_class.new(project, user, opts).execute