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 }
|
|
|
|
let(:mock_issue) { double(:issue, id: 42, assignee: assignee, author: author) }
|
|
|
|
let(:assigned_issue) { create(:issue, assignee: assignee, author: author) }
|
|
|
|
let(:unassigned_issue) { create(:issue, author: author) }
|
|
|
|
let(:closed_assigned_issue) { create(:closed_issue, assignee: assignee, author: author) }
|
|
|
|
let(:closed_unassigned_issue) { create(:closed_issue, author: author) }
|
|
|
|
|
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) }
|
|
|
|
before { subject.stub(notification: mock('NotificationService').as_null_object) }
|
|
|
|
|
2012-05-17 17:23:34 -04:00
|
|
|
|
|
|
|
subject { IssueObserver.instance }
|
|
|
|
|
2012-05-21 13:30:53 -04:00
|
|
|
describe '#after_create' do
|
|
|
|
|
|
|
|
it 'is called when an issue is created' do
|
|
|
|
subject.should_receive(:after_create)
|
2012-06-12 14:27:03 -04:00
|
|
|
|
|
|
|
Issue.observers.enable :issue_observer do
|
2012-11-05 22:31:55 -05:00
|
|
|
create(:issue, project: create(:project))
|
2012-06-12 14:27:03 -04:00
|
|
|
end
|
2012-05-21 13:30:53 -04:00
|
|
|
end
|
2012-05-17 17:23:34 -04:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
it 'note is created if the issue is being closed' do
|
2013-02-18 04:10:58 -05:00
|
|
|
Note.should_receive(:create_status_change_note).with(assigned_issue, some_user, 'closed')
|
2012-05-17 17:23:34 -04:00
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
assigned_issue.close
|
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
|
|
|
|
subject.should_receive(:notification)
|
2012-08-29 03:48:17 -04:00
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
assigned_issue.close
|
2012-08-29 03:48:17 -04:00
|
|
|
end
|
|
|
|
|
2013-03-26 08:41:57 -04:00
|
|
|
it 'creates a note' do
|
2013-02-18 04:10:58 -05:00
|
|
|
Note.should_receive(:create_status_change_note).with(unassigned_issue, some_user, 'closed')
|
|
|
|
unassigned_issue.close
|
2012-08-29 03:48:17 -04:00
|
|
|
end
|
2012-05-21 13:30:53 -04:00
|
|
|
end
|
|
|
|
|
2012-08-29 03:48:17 -04:00
|
|
|
context 'a status "reopened"' do
|
|
|
|
it 'note is created if the issue is being reopened' do
|
2013-02-18 04:10:58 -05:00
|
|
|
Note.should_receive(:create_status_change_note).with(closed_assigned_issue, some_user, 'reopened')
|
|
|
|
|
|
|
|
closed_assigned_issue.reopen
|
|
|
|
end
|
|
|
|
|
2013-03-26 08:41:57 -04:00
|
|
|
it 'trigger notification to send emails' do
|
|
|
|
subject.should_receive(:notification)
|
2012-05-21 13:30:53 -04:00
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
closed_assigned_issue.reopen
|
2012-05-21 13:30:53 -04:00
|
|
|
end
|
|
|
|
|
2013-03-26 08:41:57 -04:00
|
|
|
it 'create a note' do
|
2013-02-18 04:10:58 -05:00
|
|
|
Note.should_receive(:create_status_change_note).with(closed_unassigned_issue, some_user, 'reopened')
|
2012-05-21 13:30:53 -04:00
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
closed_unassigned_issue.reopen
|
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
|
|
|
|
|
|
|
|
it 'is called when an issue is changed' do
|
|
|
|
changed = create(:issue, project: create(:project))
|
|
|
|
subject.should_receive(:after_update)
|
2012-08-29 03:48:17 -04:00
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
Issue.observers.enable :issue_observer do
|
|
|
|
changed.description = 'I changed'
|
|
|
|
changed.save
|
2012-08-29 03:48:17 -04:00
|
|
|
end
|
2013-02-18 04:10:58 -05:00
|
|
|
end
|
2012-08-29 03:48:17 -04:00
|
|
|
|
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
|
|
|
|
end
|
2012-05-17 17:23:34 -04:00
|
|
|
end
|