2014-10-29 09:46:42 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-17 17:08:14 -05:00
|
|
|
describe Mentionable do
|
|
|
|
include Mentionable
|
|
|
|
|
2015-12-24 14:34:13 -05:00
|
|
|
def author
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2015-12-17 17:08:14 -05:00
|
|
|
describe :references do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
it 'excludes JIRA references' do
|
|
|
|
allow(project).to receive_messages(jira_tracker?: true)
|
|
|
|
expect(referenced_mentionables(project, 'JIRA-123')).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-29 09:46:42 -04:00
|
|
|
describe Issue, "Mentionable" do
|
2015-06-08 18:13:14 -04:00
|
|
|
describe '#mentioned_users' do
|
2014-10-29 09:46:42 -04:00
|
|
|
let!(:user) { create(:user, username: 'stranger') }
|
|
|
|
let!(:user2) { create(:user, username: 'john') }
|
2015-06-08 18:13:14 -04:00
|
|
|
let!(:issue) { create(:issue, description: "#{user.to_reference} mentioned") }
|
2014-10-29 09:46:42 -04:00
|
|
|
|
|
|
|
subject { issue.mentioned_users }
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to include(user) }
|
|
|
|
it { is_expected.not_to include(user2) }
|
2014-10-29 09:46:42 -04:00
|
|
|
end
|
2015-06-08 18:13:14 -04:00
|
|
|
|
|
|
|
describe '#create_cross_references!' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:author) { double('author') }
|
|
|
|
let(:commit) { project.commit }
|
|
|
|
let(:commit2) { project.commit }
|
|
|
|
|
|
|
|
let!(:issue) do
|
|
|
|
create(:issue, project: project, description: commit.to_reference)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly removes already-mentioned Commits' do
|
2015-06-17 20:59:19 -04:00
|
|
|
expect(SystemNoteService).not_to receive(:cross_reference)
|
2015-06-08 18:13:14 -04:00
|
|
|
|
2015-10-12 05:54:46 -04:00
|
|
|
issue.create_cross_references!(author, [commit2])
|
2015-06-08 18:13:14 -04:00
|
|
|
end
|
|
|
|
end
|
2015-07-13 18:28:10 -04:00
|
|
|
|
2015-07-13 18:33:50 -04:00
|
|
|
describe '#create_new_cross_references!' do
|
2015-07-13 18:28:10 -04:00
|
|
|
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'
|
2015-07-13 18:33:50 -04:00
|
|
|
issue.create_new_cross_references!
|
2015-07-13 18:28:10 -04:00
|
|
|
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
|
2015-07-13 18:33:50 -04:00
|
|
|
issue.create_new_cross_references!
|
2015-07-13 18:28:10 -04:00
|
|
|
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')
|
2015-07-13 18:33:50 -04:00
|
|
|
issue.create_new_cross_references!
|
2015-07-13 18:28:10 -04:00
|
|
|
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)
|
2015-07-13 18:33:50 -04:00
|
|
|
issue.create_new_cross_references!
|
2015-07-13 18:28:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_issue(description:)
|
|
|
|
create(:issue, project: project, description: description)
|
|
|
|
end
|
|
|
|
end
|
2014-10-29 09:46:42 -04:00
|
|
|
end
|