diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-05-26 21:49:04 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-05-26 21:49:04 -0400 |
commit | 1aa3921dd8b0084260fa381ed79580b4b54284b6 (patch) | |
tree | 500c7e3c93af1cc339e3627bb5d4779909c77ec7 /spec/services | |
parent | 0ec1e4c028b6e663929b38f1c90f4158f9a49cc2 (diff) | |
download | gitlab-ce-1aa3921dd8b0084260fa381ed79580b4b54284b6.tar.gz |
Add a note when an Issue or Merge Request's title changes
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/issues/update_service_spec.rb | 25 | ||||
-rw-r--r-- | spec/services/merge_requests/update_service_spec.rb | 25 | ||||
-rw-r--r-- | spec/services/system_note_service_spec.rb | 21 |
3 files changed, 63 insertions, 8 deletions
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index 6fc69e93628..b240d247e73 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Issues::UpdateService do let(:user) { create(:user) } let(:user2) { create(:user) } - let(:issue) { create(:issue) } + let(:issue) { create(:issue, title: 'Old title') } let(:label) { create(:label) } let(:project) { issue.project } @@ -12,7 +12,7 @@ describe Issues::UpdateService do project.team << [user2, :developer] end - describe :execute do + describe 'execute' do context "valid params" do before do opts = { @@ -40,15 +40,32 @@ describe Issues::UpdateService do expect(email.subject).to include(issue.title) end + def find_note(starting_with) + @issue.notes.find do |n| + n && n.note.start_with?(starting_with) + end + end + it 'should create system note about issue reassign' do - note = @issue.notes.last + note = find_note('Reassigned to') + + expect(note).not_to be_nil expect(note.note).to include "Reassigned to \@#{user2.username}" end it 'should create system note about issue label edit' do - note = @issue.notes[1] + note = find_note('Added ~') + + expect(note).not_to be_nil expect(note.note).to include "Added ~#{label.id} label" end + + it 'creates system note about title change' do + note = find_note('Title changed') + + expect(note).not_to be_nil + expect(note.note).to eq 'Title changed from **Old title** to **New title**' + end end end end diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb index 916b01e1c45..bf9790c2beb 100644 --- a/spec/services/merge_requests/update_service_spec.rb +++ b/spec/services/merge_requests/update_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe MergeRequests::UpdateService do let(:user) { create(:user) } let(:user2) { create(:user) } - let(:merge_request) { create(:merge_request, :simple) } + let(:merge_request) { create(:merge_request, :simple, title: 'Old title') } let(:project) { merge_request.project } let(:label) { create(:label) } @@ -12,7 +12,7 @@ describe MergeRequests::UpdateService do project.team << [user2, :developer] end - describe :execute do + describe 'execute' do context 'valid params' do let(:opts) do { @@ -51,15 +51,32 @@ describe MergeRequests::UpdateService do expect(email.subject).to include(merge_request.title) end + def find_note(starting_with) + @merge_request.notes.find do |n| + n && n.note.start_with?(starting_with) + end + end + it 'should create system note about merge_request reassign' do - note = @merge_request.notes.last + note = find_note('Reassigned to') + + expect(note).not_to be_nil expect(note.note).to include "Reassigned to \@#{user2.username}" end it 'should create system note about merge_request label edit' do - note = @merge_request.notes[1] + note = find_note('Added ~') + + expect(note).not_to be_nil expect(note.note).to include "Added ~#{label.id} label" end + + it 'creates system note about title change' do + note = find_note('Title changed') + + expect(note).not_to be_nil + expect(note.note).to eq 'Title changed from **Old title** to **New title**' + end end end end diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 4e4cb6d19ed..6d8c71f94f9 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -207,6 +207,27 @@ describe SystemNoteService do end end + describe '.change_title' do + subject { described_class.change_title(noteable, project, author, 'Old title') } + + context 'when noteable responds to `title`' do + it_behaves_like 'a system note' + + it 'sets the note text' do + expect(subject.note). + to eq "Title changed from **Old title** to **#{noteable.title}**" + end + end + + context 'when noteable does not respond to `title' do + let(:noteable) { double('noteable') } + + it 'returns nil' do + expect(subject).to be_nil + end + end + end + describe '.cross_reference' do subject { described_class.cross_reference(noteable, mentioner, author) } |