Commit de437f75cc3ad4a97116d438984d0496e051b937
1 parent
e15c8cea
Exists in
master
and in
29 other branches
rails3: fix tests related to TaskMailer
Showing
8 changed files
with
41 additions
and
20 deletions
Show diff stats
test/unit/add_friend_test.rb
... | ... | @@ -64,7 +64,9 @@ class AddFriendTest < ActiveSupport::TestCase |
64 | 64 | end |
65 | 65 | |
66 | 66 | should 'send e-mails' do |
67 | - TaskMailer.expects(:deliver_target_notification).at_least_once | |
67 | + mailer = mock | |
68 | + mailer.expects(:deliver).at_least_once | |
69 | + TaskMailer.expects(:target_notification).returns(mailer).at_least_once | |
68 | 70 | |
69 | 71 | task = AddFriend.create!(:person => person1, :friend => person2) |
70 | 72 | end | ... | ... |
test/unit/add_member_test.rb
... | ... | @@ -56,7 +56,9 @@ class AddMemberTest < ActiveSupport::TestCase |
56 | 56 | community.update_attribute(:closed, true) |
57 | 57 | community.stubs(:notification_emails).returns(["adm@example.com"]) |
58 | 58 | |
59 | - TaskMailer.expects(:deliver_target_notification).at_least_once | |
59 | + mailer = mock | |
60 | + mailer.expects(:deliver).at_least_once | |
61 | + TaskMailer.expects(:target_notification).returns(mailer).at_least_once | |
60 | 62 | |
61 | 63 | task = AddMember.create!(:person => person, :organization => community) |
62 | 64 | end | ... | ... |
test/unit/approve_comment_test.rb
... | ... | @@ -99,7 +99,9 @@ class ApproveCommentTest < ActiveSupport::TestCase |
99 | 99 | end |
100 | 100 | |
101 | 101 | should 'send e-mails' do |
102 | - TaskMailer.expects(:deliver_target_notification).at_least_once | |
102 | + mailer = mock | |
103 | + mailer.expects(:deliver).at_least_once | |
104 | + TaskMailer.expects(:target_notification).returns(mailer).at_least_once | |
103 | 105 | |
104 | 106 | task = ApproveComment.create!(:target => @community, :comment_attributes => @comment.attributes.to_json, :requestor => @profile) |
105 | 107 | |
... | ... | @@ -115,7 +117,7 @@ class ApproveCommentTest < ActiveSupport::TestCase |
115 | 117 | should 'deliver target notification message' do |
116 | 118 | task = ApproveComment.new(:target => @community, :comment_attributes => @comment.attributes.to_json, :requestor => @profile) |
117 | 119 | |
118 | - email = TaskMailer.deliver_target_notification(task, task.target_notification_message) | |
120 | + email = TaskMailer.target_notification(task, task.target_notification_message).deliver | |
119 | 121 | assert_match(/\[#{task.environment.name}\] #{task.requestor.name} wants to comment the article: #{task.article_name}/, email.subject) |
120 | 122 | end |
121 | 123 | ... | ... |
test/unit/change_password_test.rb
... | ... | @@ -67,7 +67,7 @@ class ChangePasswordTest < ActiveSupport::TestCase |
67 | 67 | |
68 | 68 | should 'deliver task created message' do |
69 | 69 | task = ChangePassword.create!(:requestor => person) |
70 | - email = TaskMailer.deliver_task_created(task) | |
70 | + email = TaskMailer.generic_message('task_created', task) | |
71 | 71 | assert_match(/#{task.requestor.name} wants to change its password/, email.subject) |
72 | 72 | end |
73 | 73 | ... | ... |
test/unit/create_enterprise_test.rb
... | ... | @@ -274,7 +274,7 @@ class CreateEnterpriseTest < ActiveSupport::TestCase |
274 | 274 | should 'deliver target notification message' do |
275 | 275 | task = CreateEnterprise.new(:name => 'My enterprise', :requestor => person, :target => Environment.default) |
276 | 276 | |
277 | - email = TaskMailer.deliver_target_notification(task, task.target_notification_message) | |
277 | + email = TaskMailer.target_notification(task, task.target_notification_message).deliver | |
278 | 278 | |
279 | 279 | assert_match(/#{task.requestor.name} wants to create enterprise #{task.subject}/, email.subject) |
280 | 280 | end | ... | ... |
test/unit/invite_friend_test.rb
... | ... | @@ -91,7 +91,9 @@ class InviteFriendTest < ActiveSupport::TestCase |
91 | 91 | should 'send e-mails to friend if friend_email given' do |
92 | 92 | p1 = create_user('testuser1').person |
93 | 93 | |
94 | - TaskMailer.expects(:deliver_invitation_notification).once | |
94 | + mailer = mock | |
95 | + mailer.expects(:deliver).at_least_once | |
96 | + TaskMailer.expects(:invitation_notification).returns(mailer).once | |
95 | 97 | |
96 | 98 | task = InviteFriend.create!(:person => p1, :friend_email => 'test@test.com', :message => '<url>') |
97 | 99 | end | ... | ... |
test/unit/invite_member_test.rb
... | ... | @@ -71,7 +71,9 @@ class InviteMemberTest < ActiveSupport::TestCase |
71 | 71 | should 'send e-mails to friend if friend_email given' do |
72 | 72 | p1 = create_user('testuser1').person |
73 | 73 | |
74 | - TaskMailer.expects(:deliver_invitation_notification).once | |
74 | + mailer = mock | |
75 | + mailer.expects(:deliver).at_least_once | |
76 | + TaskMailer.expects(:invitation_notification).returns(mailer).once | |
75 | 77 | |
76 | 78 | task = InviteMember.create!(:person => p1, :friend_email => 'test@test.com', :message => '<url>', :community_id => fast_create(Community).id) |
77 | 79 | end | ... | ... |
test/unit/task_test.rb
... | ... | @@ -29,7 +29,7 @@ class TaskTest < ActiveSupport::TestCase |
29 | 29 | end |
30 | 30 | |
31 | 31 | def test_should_call_perform_in_finish |
32 | - TaskMailer.expects(:deliver_task_finished) | |
32 | + TaskMailer.expects(:generic_message).with('task_finished', anything) | |
33 | 33 | t = Task.create |
34 | 34 | t.requestor = sample_user |
35 | 35 | t.expects(:perform) |
... | ... | @@ -38,7 +38,7 @@ class TaskTest < ActiveSupport::TestCase |
38 | 38 | end |
39 | 39 | |
40 | 40 | def test_should_have_cancelled_status_after_cancel |
41 | - TaskMailer.expects(:deliver_task_cancelled) | |
41 | + TaskMailer.expects(:generic_message).with('task_cancelled', anything) | |
42 | 42 | t = Task.create |
43 | 43 | t.requestor = sample_user |
44 | 44 | t.cancel |
... | ... | @@ -54,7 +54,7 @@ class TaskTest < ActiveSupport::TestCase |
54 | 54 | t = Task.create |
55 | 55 | t.requestor = sample_user |
56 | 56 | |
57 | - TaskMailer.expects(:deliver_task_finished).with(t) | |
57 | + TaskMailer.expects(:generic_message).with('task_finished', t) | |
58 | 58 | |
59 | 59 | t.finish |
60 | 60 | end |
... | ... | @@ -63,7 +63,7 @@ class TaskTest < ActiveSupport::TestCase |
63 | 63 | t = Task.create |
64 | 64 | t.requestor = sample_user |
65 | 65 | |
66 | - TaskMailer.expects(:deliver_task_cancelled).with(t) | |
66 | + TaskMailer.expects(:generic_message).with('task_cancelled', t) | |
67 | 67 | |
68 | 68 | t.cancel |
69 | 69 | end |
... | ... | @@ -93,7 +93,7 @@ class TaskTest < ActiveSupport::TestCase |
93 | 93 | task = Task.new |
94 | 94 | task.requestor = sample_user |
95 | 95 | |
96 | - TaskMailer.expects(:deliver_task_created).with(task) | |
96 | + TaskMailer.expects(:generic_message).with('task_created', task) | |
97 | 97 | task.save! |
98 | 98 | end |
99 | 99 | |
... | ... | @@ -101,7 +101,7 @@ class TaskTest < ActiveSupport::TestCase |
101 | 101 | task = build(Task, :status => Task::Status::HIDDEN) |
102 | 102 | task.requestor = sample_user |
103 | 103 | |
104 | - TaskMailer.expects(:deliver_task_created).never | |
104 | + TaskMailer.expects(:generic_message).with('task_created', anything).never | |
105 | 105 | task.save! |
106 | 106 | end |
107 | 107 | |
... | ... | @@ -164,14 +164,21 @@ class TaskTest < ActiveSupport::TestCase |
164 | 164 | target.stubs(:notification_emails).returns(['adm@example.com']) |
165 | 165 | task.target = target |
166 | 166 | task.stubs(:target_notification_message).returns('some non nil message to be sent to target') |
167 | - TaskMailer.expects(:deliver_target_notification).once | |
167 | + | |
168 | + mailer = mock | |
169 | + mailer.expects(:deliver).once | |
170 | + TaskMailer.expects(:target_notification).returns(mailer).once | |
168 | 171 | task.save! |
169 | 172 | end |
170 | 173 | |
171 | 174 | should 'not send notification to target if the task is hidden' do |
172 | 175 | task = build(Task, :status => Task::Status::HIDDEN) |
176 | + target = fast_create(Profile) | |
177 | + target.stubs(:notification_emails).returns(['adm@example.com']) | |
178 | + task.target = target | |
173 | 179 | task.stubs(:target_notification_message).returns('some non nil message to be sent to target') |
174 | - TaskMailer.expects(:deliver_target_notification).never | |
180 | + | |
181 | + TaskMailer.expects(:target_notification).never | |
175 | 182 | task.save! |
176 | 183 | end |
177 | 184 | |
... | ... | @@ -227,7 +234,7 @@ class TaskTest < ActiveSupport::TestCase |
227 | 234 | should 'not notify target if message is nil' do |
228 | 235 | task = Task.new |
229 | 236 | task.stubs(:target_notification_message).returns(nil) |
230 | - TaskMailer.expects(:deliver_target_notification).never | |
237 | + TaskMailer.expects(:target_notification).never | |
231 | 238 | task.save! |
232 | 239 | end |
233 | 240 | |
... | ... | @@ -237,7 +244,7 @@ class TaskTest < ActiveSupport::TestCase |
237 | 244 | target.stubs(:notification_emails).returns([]) |
238 | 245 | task.target = target |
239 | 246 | task.stubs(:target_notification_message).returns('some non nil message to be sent to target') |
240 | - TaskMailer.expects(:deliver_target_notification).never | |
247 | + TaskMailer.expects(:target_notification).never | |
241 | 248 | task.save! |
242 | 249 | end |
243 | 250 | |
... | ... | @@ -272,8 +279,9 @@ class TaskTest < ActiveSupport::TestCase |
272 | 279 | should 'notify just after the task is activated' do |
273 | 280 | task = build(Task, :status => Task::Status::HIDDEN) |
274 | 281 | task.requestor = sample_user |
282 | + task.save! | |
275 | 283 | |
276 | - TaskMailer.expects(:deliver_task_activated).with(task) | |
284 | + TaskMailer.expects(:generic_message).with('task_activated', task) | |
277 | 285 | task.activate |
278 | 286 | end |
279 | 287 | |
... | ... | @@ -284,7 +292,10 @@ class TaskTest < ActiveSupport::TestCase |
284 | 292 | task.target = target |
285 | 293 | task.save! |
286 | 294 | task.stubs(:target_notification_message).returns('some non nil message to be sent to target') |
287 | - TaskMailer.expects(:deliver_target_notification).once | |
295 | + | |
296 | + mailer = mock | |
297 | + mailer.expects(:deliver).once | |
298 | + TaskMailer.expects(:target_notification).returns(mailer).once | |
288 | 299 | task.activate |
289 | 300 | end |
290 | 301 | ... | ... |