gitlab-org--gitlab-foss/spec/observers/issue_observer_spec.rb

74 lines
2.1 KiB
Ruby
Raw Normal View History

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) { create(:issue, assignee: assignee, author: author) }
2013-02-18 04:10:58 -05: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) }
subject { IssueObserver.instance }
describe '#after_create' do
2013-03-26 08:41:57 -04:00
it 'trigger notification to send emails' do
subject.should_receive(:notification)
2013-02-18 04:10:58 -05:00
subject.after_create(mock_issue)
end
end
2013-02-18 04:10:58 -05:00
context '#after_close' do
context 'a status "closed"' do
before { mock_issue.stub(state: 'closed') }
it 'note is created if the issue is being closed' do
Note.should_receive(:create_status_change_note).with(mock_issue, some_user, 'closed')
subject.after_close(mock_issue, nil)
end
2013-03-26 08:41:57 -04:00
it 'trigger notification to send emails' do
subject.notification.should_receive(:close_issue).with(mock_issue, some_user)
subject.after_close(mock_issue, nil)
end
end
context 'a status "reopened"' do
before { mock_issue.stub(state: 'reopened') }
it 'note is created if the issue is being reopened' do
Note.should_receive(:create_status_change_note).with(mock_issue, some_user, 'reopened')
subject.after_reopen(mock_issue, nil)
end
2013-02-18 04:10:58 -05:00
end
end
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)
2013-02-18 04:10:58 -05:00
subject.after_update(mock_issue)
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)
2013-02-18 04:10:58 -05:00
subject.after_update(mock_issue)
end
end
end
end