use NotificationService for handle notify logic when MR created

This commit is contained in:
Dmitriy Zaporozhets 2013-03-26 17:16:06 +02:00
parent 58a1ed6dd3
commit 38ffb8220c
4 changed files with 33 additions and 18 deletions

View file

@ -10,7 +10,8 @@ describe MergeRequestObserver do
let(:closed_assigned_mr) { create(:closed_merge_request, assignee: assignee, author: author) }
let(:closed_unassigned_mr) { create(:closed_merge_request, author: author) }
before(:each) { subject.stub(:current_user).and_return(some_user) }
before { subject.stub(:current_user).and_return(some_user) }
before { subject.stub(notification: mock('NotificationService').as_null_object) }
subject { MergeRequestObserver.instance }
@ -18,21 +19,11 @@ describe MergeRequestObserver do
it 'is called when a merge request is created' do
subject.should_receive(:after_create)
MergeRequest.observers.enable :merge_request_observer do
create(:merge_request, project: create(:project))
end
create(:merge_request, project: create(:project))
end
it 'sends an email to the assignee' do
Notify.should_receive(:new_merge_request_email).with(mr_mock.id)
subject.after_create(mr_mock)
end
it 'does not send an email to the assignee if assignee created the merge request' do
subject.stub(:current_user).and_return(assignee)
Notify.should_not_receive(:new_merge_request_email)
it 'trigger notification service' do
subject.should_receive(:notification)
subject.after_create(mr_mock)
end
end

View file

@ -44,4 +44,20 @@ describe NotificationService do
end
end
end
describe 'Merge Requests' do
let(:merge_request) { create :merge_request, assignee: create(:user) }
describe :new_merge_request do
it 'should send email to merge_request assignee' do
Notify.should_receive(:new_merge_request_email).with(merge_request.id)
notification.new_merge_request(merge_request, merge_request.author)
end
it 'should not send email to merge_request assignee if he is current_user' do
Notify.should_not_receive(:new_merge_request_email).with(merge_request.id)
notification.new_merge_request(merge_request, merge_request.assignee)
end
end
end
end