2012-05-17 17:23:34 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe IssueObserver do
|
2013-02-18 04:10:58 -05:00
|
|
|
let(:some_user) { create :user }
|
|
|
|
let(:assignee) { create :user }
|
|
|
|
let(:author) { create :user }
|
2013-04-10 16:28:42 -04:00
|
|
|
let(:mock_issue) { create(:issue, assignee: assignee, author: author) }
|
2013-02-18 04:10:58 -05:00
|
|
|
|
2012-05-17 17:23:34 -04:00
|
|
|
|
2013-03-26 08:41:57 -04:00
|
|
|
before { subject.stub(:current_user).and_return(some_user) }
|
2013-05-30 19:16:49 -04:00
|
|
|
before { subject.stub(:current_commit).and_return(nil) }
|
2013-03-26 08:41:57 -04:00
|
|
|
before { subject.stub(notification: mock('NotificationService').as_null_object) }
|
2013-05-30 19:16:49 -04:00
|
|
|
before { mock_issue.project.stub_chain(:repository, :commit).and_return(nil) }
|
2012-05-17 17:23:34 -04:00
|
|
|
|
|
|
|
subject { IssueObserver.instance }
|
|
|
|
|
2012-05-21 13:30:53 -04:00
|
|
|
describe '#after_create' do
|
2013-03-26 08:41:57 -04:00
|
|
|
it 'trigger notification to send emails' do
|
|
|
|
subject.should_receive(:notification)
|
2012-05-17 17:23:34 -04:00
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
subject.after_create(mock_issue)
|
2012-05-17 17:23:34 -04:00
|
|
|
end
|
2013-05-30 19:16:49 -04:00
|
|
|
|
|
|
|
it 'should create cross-reference notes' do
|
|
|
|
other_issue = create(:issue)
|
|
|
|
mock_issue.stub(references: [other_issue])
|
|
|
|
|
|
|
|
Note.should_receive(:create_cross_reference_note).with(other_issue, mock_issue,
|
|
|
|
some_user, mock_issue.project)
|
|
|
|
subject.after_create(mock_issue)
|
|
|
|
end
|
2012-05-17 17:23:34 -04:00
|
|
|
end
|
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
context '#after_close' do
|
2012-08-29 03:48:17 -04:00
|
|
|
context 'a status "closed"' do
|
2013-04-10 16:28:42 -04:00
|
|
|
before { mock_issue.stub(state: 'closed') }
|
|
|
|
|
2012-08-29 03:48:17 -04:00
|
|
|
it 'note is created if the issue is being closed' do
|
2013-05-30 19:16:49 -04:00
|
|
|
Note.should_receive(:create_status_change_note).with(mock_issue, mock_issue.project, some_user, 'closed', nil)
|
2012-05-17 17:23:34 -04:00
|
|
|
|
2013-04-10 16:28:42 -04:00
|
|
|
subject.after_close(mock_issue, nil)
|
2012-05-21 13:30:53 -04:00
|
|
|
end
|
2012-08-29 03:48:17 -04:00
|
|
|
|
2013-03-26 08:41:57 -04:00
|
|
|
it 'trigger notification to send emails' do
|
2013-04-10 16:28:42 -04:00
|
|
|
subject.notification.should_receive(:close_issue).with(mock_issue, some_user)
|
|
|
|
subject.after_close(mock_issue, nil)
|
2012-08-29 03:48:17 -04:00
|
|
|
end
|
2013-05-30 19:16:49 -04:00
|
|
|
|
|
|
|
it 'appends a mention to the closing commit if one is present' do
|
|
|
|
commit = double('commit', gfm_reference: 'commit 123456')
|
|
|
|
subject.stub(current_commit: commit)
|
|
|
|
|
|
|
|
Note.should_receive(:create_status_change_note).with(mock_issue, mock_issue.project, some_user, 'closed', commit)
|
|
|
|
|
|
|
|
subject.after_close(mock_issue, nil)
|
|
|
|
end
|
2012-05-21 13:30:53 -04:00
|
|
|
end
|
|
|
|
|
2012-08-29 03:48:17 -04:00
|
|
|
context 'a status "reopened"' do
|
2013-04-10 16:28:42 -04:00
|
|
|
before { mock_issue.stub(state: 'reopened') }
|
2012-05-21 13:30:53 -04:00
|
|
|
|
2013-04-10 16:28:42 -04:00
|
|
|
it 'note is created if the issue is being reopened' do
|
2013-05-30 19:16:49 -04:00
|
|
|
Note.should_receive(:create_status_change_note).with(mock_issue, mock_issue.project, some_user, 'reopened', nil)
|
|
|
|
|
2013-04-10 16:28:42 -04:00
|
|
|
subject.after_reopen(mock_issue, nil)
|
2012-05-20 15:06:13 -04:00
|
|
|
end
|
2013-02-18 04:10:58 -05:00
|
|
|
end
|
|
|
|
end
|
2012-08-29 03:48:17 -04:00
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
context '#after_update' do
|
|
|
|
before(:each) do
|
|
|
|
mock_issue.stub(:is_being_reassigned?).and_return(false)
|
|
|
|
end
|
|
|
|
|
2013-03-26 08:41:57 -04:00
|
|
|
context 'notification' do
|
|
|
|
it 'triggered if the issue is being reassigned' do
|
2013-02-18 04:10:58 -05:00
|
|
|
mock_issue.should_receive(:is_being_reassigned?).and_return(true)
|
2013-03-26 08:41:57 -04:00
|
|
|
subject.should_receive(:notification)
|
2012-08-29 03:48:17 -04:00
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
subject.after_update(mock_issue)
|
2012-08-29 03:48:17 -04:00
|
|
|
end
|
|
|
|
|
2013-03-26 08:41:57 -04:00
|
|
|
it 'is not triggered if the issue is not being reassigned' do
|
2013-02-18 04:10:58 -05:00
|
|
|
mock_issue.should_receive(:is_being_reassigned?).and_return(false)
|
2013-03-26 08:41:57 -04:00
|
|
|
subject.should_not_receive(:notification)
|
2012-08-29 03:48:17 -04:00
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
subject.after_update(mock_issue)
|
2012-08-29 03:48:17 -04:00
|
|
|
end
|
2012-05-20 14:25:34 -04:00
|
|
|
end
|
2013-05-30 19:16:49 -04:00
|
|
|
|
|
|
|
context 'cross-references' do
|
|
|
|
it 'notices added references' do
|
|
|
|
mock_issue.should_receive(:notice_added_references)
|
|
|
|
|
|
|
|
subject.after_update(mock_issue)
|
|
|
|
end
|
|
|
|
end
|
2012-05-20 14:25:34 -04:00
|
|
|
end
|
2012-05-17 17:23:34 -04:00
|
|
|
end
|