Commit c04120c1c512bd515fceccc70d0c7cf0a6bf4cb7
1 parent
f49a2ac0
Exists in
master
and in
4 other branches
Improve notification service tests
Showing
3 changed files
with
22 additions
and
11 deletions
Show diff stats
app/mailers/emails/issues.rb
| ... | ... | @@ -13,7 +13,7 @@ module Emails |
| 13 | 13 | mail(to: recipient(recipient_id), subject: subject("changed issue ##{@issue.id}", @issue.title)) |
| 14 | 14 | end |
| 15 | 15 | |
| 16 | - def close_issue_email(recipient_id, issue_id, updated_by_user_id) | |
| 16 | + def closed_issue_email(recipient_id, issue_id, updated_by_user_id) | |
| 17 | 17 | @issue = Issue.find issue_id |
| 18 | 18 | @project = @issue.project |
| 19 | 19 | @updated_by = User.find updated_by_user_id | ... | ... |
app/services/notification_service.rb
| ... | ... | @@ -33,7 +33,7 @@ class NotificationService |
| 33 | 33 | # * project team members with notification level higher then Participating |
| 34 | 34 | # |
| 35 | 35 | def close_issue(issue, current_user) |
| 36 | - close_resource_email(issue, current_user, 'close_issue_email') | |
| 36 | + close_resource_email(issue, current_user, 'closed_issue_email') | |
| 37 | 37 | end |
| 38 | 38 | |
| 39 | 39 | # When we reassign an issue we should send next emails: | ... | ... |
spec/services/notification_service_spec.rb
| ... | ... | @@ -28,9 +28,20 @@ describe NotificationService do |
| 28 | 28 | end |
| 29 | 29 | |
| 30 | 30 | describe :new_issue do |
| 31 | - it 'should sent email to issue assignee' do | |
| 32 | - Notify.should_receive(:new_issue_email).with(issue.id) | |
| 33 | - notification.new_issue(issue, nil) | |
| 31 | + it do | |
| 32 | + should_email(issue.assignee_id) | |
| 33 | + should_email(@u_watcher.id) | |
| 34 | + should_not_email(@u_participating.id) | |
| 35 | + should_not_email(@u_disabled.id) | |
| 36 | + notification.new_issue(issue, @u_disabled) | |
| 37 | + end | |
| 38 | + | |
| 39 | + def should_email(user_id) | |
| 40 | + Notify.should_receive(:new_issue_email).with(user_id, issue.id) | |
| 41 | + end | |
| 42 | + | |
| 43 | + def should_not_email(user_id) | |
| 44 | + Notify.should_not_receive(:new_issue_email).with(user_id, issue.id) | |
| 34 | 45 | end |
| 35 | 46 | end |
| 36 | 47 | |
| ... | ... | @@ -65,11 +76,11 @@ describe NotificationService do |
| 65 | 76 | end |
| 66 | 77 | |
| 67 | 78 | def should_email(user_id) |
| 68 | - Notify.should_receive(:closed_issue_email).with(user_id, issue.id, issue.assignee_id) | |
| 79 | + Notify.should_receive(:closed_issue_email).with(user_id, issue.id, @u_disabled.id) | |
| 69 | 80 | end |
| 70 | 81 | |
| 71 | 82 | def should_not_email(user_id) |
| 72 | - Notify.should_not_receive(:closed_issue_email).with(user_id, issue.id, issue.assignee_id) | |
| 83 | + Notify.should_not_receive(:closed_issue_email).with(user_id, issue.id, @u_disabled.id) | |
| 73 | 84 | end |
| 74 | 85 | end |
| 75 | 86 | end |
| ... | ... | @@ -91,11 +102,11 @@ describe NotificationService do |
| 91 | 102 | end |
| 92 | 103 | |
| 93 | 104 | def should_email(user_id) |
| 94 | - Notify.should_receive(:new_merge_request_email).with(merge_request.id) | |
| 105 | + Notify.should_receive(:new_merge_request_email).with(user_id, merge_request.id) | |
| 95 | 106 | end |
| 96 | 107 | |
| 97 | 108 | def should_not_email(user_id) |
| 98 | - Notify.should_not_receive(:new_merge_request_email).with(merge_request.id) | |
| 109 | + Notify.should_not_receive(:new_merge_request_email).with(user_id, merge_request.id) | |
| 99 | 110 | end |
| 100 | 111 | end |
| 101 | 112 | |
| ... | ... | @@ -127,11 +138,11 @@ describe NotificationService do |
| 127 | 138 | end |
| 128 | 139 | |
| 129 | 140 | def should_email(user_id) |
| 130 | - Notify.should_receive(:closed_merge_request_email).with(user_id, merge_request.id) | |
| 141 | + Notify.should_receive(:closed_merge_request_email).with(user_id, merge_request.id, @u_disabled.id) | |
| 131 | 142 | end |
| 132 | 143 | |
| 133 | 144 | def should_not_email(user_id) |
| 134 | - Notify.should_not_receive(:closed_merge_request_email).with(user_id, merge_request.id) | |
| 145 | + Notify.should_not_receive(:closed_merge_request_email).with(user_id, merge_request.id, @u_disabled.id) | |
| 135 | 146 | end |
| 136 | 147 | end |
| 137 | 148 | ... | ... |