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

110 lines
3.2 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) { 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) }
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
it 'is called when an issue is created' do
subject.should_receive(:after_create)
Issue.observers.enable :issue_observer do
create(:issue, project: create(:project))
end
end
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
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')
2013-02-18 04:10:58 -05:00
assigned_issue.close
end
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
assigned_issue.close
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
end
end
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)
2013-02-18 04:10:58 -05:00
closed_assigned_issue.reopen
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')
2013-02-18 04:10:58 -05:00
closed_unassigned_issue.reopen
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
it 'is called when an issue is changed' do
changed = create(:issue, project: create(:project))
subject.should_receive(:after_update)
2013-02-18 04:10:58 -05:00
Issue.observers.enable :issue_observer do
changed.description = 'I changed'
changed.save
end
2013-02-18 04:10:58 -05:00
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