Permalink
Browse files

use NotificationService for handle notify logic when MR created

  • Loading branch information...
1 parent 58a1ed6 commit 38ffb8220c8d8ae030b762f7b2d244eabe8cc0bf @randx randx committed Mar 26, 2013
@@ -2,9 +2,7 @@ class MergeRequestObserver < ActiveRecord::Observer
cattr_accessor :current_user
def after_create(merge_request)
- if merge_request.assignee && merge_request.assignee != current_user
- Notify.delay.new_merge_request_email(merge_request.id)
- end
+ notification.new_merge_request(merge_request, current_user)
end
def after_close(merge_request, transition)
@@ -47,7 +47,7 @@ def reassigned_issue(issue, current_user)
end
end
- # When we reassign an issue we should send next emails:
+ # When create an issue we should send next emails:
#
# * issue assignee if his notification level is not Disabled
#
@@ -56,4 +56,14 @@ def new_issue(issue, current_user)
Notify.delay.new_issue_email(issue.id)
end
end
+
+ # When create a merge request we should send next emails:
+ #
+ # * mr assignee if his notification level is not Disabled
+ #
+ def new_merge_request(merge_request, current_user)
+ if merge_request.assignee && merge_request.assignee != current_user
+ Notify.delay.new_merge_request_email(merge_request.id)
+ end
+ end
end
@@ -10,29 +10,20 @@
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 }
describe '#after_create' 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
@@ -44,4 +44,20 @@
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

0 comments on commit 38ffb82

Please sign in to comment.