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