diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-07-13 18:28:10 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-07-13 21:31:00 -0400 |
commit | e4c698fd5ce77e46e3851384c14271eb74c3c9ee (patch) | |
tree | ab0d59f0a789dfca1c25d4ec3b265225a7860bb3 /spec/models/concerns/mentionable_spec.rb | |
parent | 59d7f4c97ff2869824cb5b1b0fbe14c983dab75d (diff) | |
download | gitlab-ce-e4c698fd5ce77e46e3851384c14271eb74c3c9ee.tar.gz |
Refactor Mentionable#notice_added_references
It now accounts for models that have changed but have already been
persisted, such as when called from an UpdateService.
Closes #1773
Diffstat (limited to 'spec/models/concerns/mentionable_spec.rb')
-rw-r--r-- | spec/models/concerns/mentionable_spec.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/models/concerns/mentionable_spec.rb b/spec/models/concerns/mentionable_spec.rb index f7f66987b5f..82e8a83bb3d 100644 --- a/spec/models/concerns/mentionable_spec.rb +++ b/spec/models/concerns/mentionable_spec.rb @@ -28,4 +28,53 @@ describe Issue, "Mentionable" do issue.create_cross_references!(project, author, [commit2]) end end + + describe '#notice_added_references' do + let(:project) { create(:project) } + let(:issues) { create_list(:issue, 2, project: project) } + + context 'before changes are persisted' do + it 'ignores pre-existing references' do + issue = create_issue(description: issues[0].to_reference) + + expect(SystemNoteService).not_to receive(:cross_reference) + + issue.description = 'New description' + issue.notice_added_references + end + + it 'notifies new references' do + issue = create_issue(description: issues[0].to_reference) + + expect(SystemNoteService).to receive(:cross_reference).with(issues[1], any_args) + + issue.description = issues[1].to_reference + issue.notice_added_references + end + end + + context 'after changes are persisted' do + it 'ignores pre-existing references' do + issue = create_issue(description: issues[0].to_reference) + + expect(SystemNoteService).not_to receive(:cross_reference) + + issue.update_attributes(description: 'New description') + issue.notice_added_references + end + + it 'notifies new references' do + issue = create_issue(description: issues[0].to_reference) + + expect(SystemNoteService).to receive(:cross_reference).with(issues[1], any_args) + + issue.update_attributes(description: issues[1].to_reference) + issue.notice_added_references + end + end + + def create_issue(description:) + create(:issue, project: project, description: description) + end + end end |