diff --git a/test/unit/add_friend_test.rb b/test/unit/add_friend_test.rb index e373990..3cf18a5 100644 --- a/test/unit/add_friend_test.rb +++ b/test/unit/add_friend_test.rb @@ -64,7 +64,9 @@ class AddFriendTest < ActiveSupport::TestCase end should 'send e-mails' do - TaskMailer.expects(:deliver_target_notification).at_least_once + mailer = mock + mailer.expects(:deliver).at_least_once + TaskMailer.expects(:target_notification).returns(mailer).at_least_once task = AddFriend.create!(:person => person1, :friend => person2) end diff --git a/test/unit/add_member_test.rb b/test/unit/add_member_test.rb index e0b02cb..a251e97 100644 --- a/test/unit/add_member_test.rb +++ b/test/unit/add_member_test.rb @@ -56,7 +56,9 @@ class AddMemberTest < ActiveSupport::TestCase community.update_attribute(:closed, true) community.stubs(:notification_emails).returns(["adm@example.com"]) - TaskMailer.expects(:deliver_target_notification).at_least_once + mailer = mock + mailer.expects(:deliver).at_least_once + TaskMailer.expects(:target_notification).returns(mailer).at_least_once task = AddMember.create!(:person => person, :organization => community) end diff --git a/test/unit/approve_comment_test.rb b/test/unit/approve_comment_test.rb index 5d2d226..0e0a365 100644 --- a/test/unit/approve_comment_test.rb +++ b/test/unit/approve_comment_test.rb @@ -99,7 +99,9 @@ class ApproveCommentTest < ActiveSupport::TestCase end should 'send e-mails' do - TaskMailer.expects(:deliver_target_notification).at_least_once + mailer = mock + mailer.expects(:deliver).at_least_once + TaskMailer.expects(:target_notification).returns(mailer).at_least_once task = ApproveComment.create!(:target => @community, :comment_attributes => @comment.attributes.to_json, :requestor => @profile) @@ -115,7 +117,7 @@ class ApproveCommentTest < ActiveSupport::TestCase should 'deliver target notification message' do task = ApproveComment.new(:target => @community, :comment_attributes => @comment.attributes.to_json, :requestor => @profile) - email = TaskMailer.deliver_target_notification(task, task.target_notification_message) + email = TaskMailer.target_notification(task, task.target_notification_message).deliver assert_match(/\[#{task.environment.name}\] #{task.requestor.name} wants to comment the article: #{task.article_name}/, email.subject) end diff --git a/test/unit/change_password_test.rb b/test/unit/change_password_test.rb index 61c3d87..1bab714 100644 --- a/test/unit/change_password_test.rb +++ b/test/unit/change_password_test.rb @@ -67,7 +67,7 @@ class ChangePasswordTest < ActiveSupport::TestCase should 'deliver task created message' do task = ChangePassword.create!(:requestor => person) - email = TaskMailer.deliver_task_created(task) + email = TaskMailer.generic_message('task_created', task) assert_match(/#{task.requestor.name} wants to change its password/, email.subject) end diff --git a/test/unit/create_enterprise_test.rb b/test/unit/create_enterprise_test.rb index 3d44b86..9a66d98 100644 --- a/test/unit/create_enterprise_test.rb +++ b/test/unit/create_enterprise_test.rb @@ -274,7 +274,7 @@ class CreateEnterpriseTest < ActiveSupport::TestCase should 'deliver target notification message' do task = CreateEnterprise.new(:name => 'My enterprise', :requestor => person, :target => Environment.default) - email = TaskMailer.deliver_target_notification(task, task.target_notification_message) + email = TaskMailer.target_notification(task, task.target_notification_message).deliver assert_match(/#{task.requestor.name} wants to create enterprise #{task.subject}/, email.subject) end diff --git a/test/unit/invite_friend_test.rb b/test/unit/invite_friend_test.rb index b505061..74e9acd 100644 --- a/test/unit/invite_friend_test.rb +++ b/test/unit/invite_friend_test.rb @@ -91,7 +91,9 @@ class InviteFriendTest < ActiveSupport::TestCase should 'send e-mails to friend if friend_email given' do p1 = create_user('testuser1').person - TaskMailer.expects(:deliver_invitation_notification).once + mailer = mock + mailer.expects(:deliver).at_least_once + TaskMailer.expects(:invitation_notification).returns(mailer).once task = InviteFriend.create!(:person => p1, :friend_email => 'test@test.com', :message => '') end diff --git a/test/unit/invite_member_test.rb b/test/unit/invite_member_test.rb index 7ed549a..a9633f5 100644 --- a/test/unit/invite_member_test.rb +++ b/test/unit/invite_member_test.rb @@ -71,7 +71,9 @@ class InviteMemberTest < ActiveSupport::TestCase should 'send e-mails to friend if friend_email given' do p1 = create_user('testuser1').person - TaskMailer.expects(:deliver_invitation_notification).once + mailer = mock + mailer.expects(:deliver).at_least_once + TaskMailer.expects(:invitation_notification).returns(mailer).once task = InviteMember.create!(:person => p1, :friend_email => 'test@test.com', :message => '', :community_id => fast_create(Community).id) end diff --git a/test/unit/task_test.rb b/test/unit/task_test.rb index 58c7759..1166e9c 100644 --- a/test/unit/task_test.rb +++ b/test/unit/task_test.rb @@ -29,7 +29,7 @@ class TaskTest < ActiveSupport::TestCase end def test_should_call_perform_in_finish - TaskMailer.expects(:deliver_task_finished) + TaskMailer.expects(:generic_message).with('task_finished', anything) t = Task.create t.requestor = sample_user t.expects(:perform) @@ -38,7 +38,7 @@ class TaskTest < ActiveSupport::TestCase end def test_should_have_cancelled_status_after_cancel - TaskMailer.expects(:deliver_task_cancelled) + TaskMailer.expects(:generic_message).with('task_cancelled', anything) t = Task.create t.requestor = sample_user t.cancel @@ -54,7 +54,7 @@ class TaskTest < ActiveSupport::TestCase t = Task.create t.requestor = sample_user - TaskMailer.expects(:deliver_task_finished).with(t) + TaskMailer.expects(:generic_message).with('task_finished', t) t.finish end @@ -63,7 +63,7 @@ class TaskTest < ActiveSupport::TestCase t = Task.create t.requestor = sample_user - TaskMailer.expects(:deliver_task_cancelled).with(t) + TaskMailer.expects(:generic_message).with('task_cancelled', t) t.cancel end @@ -93,7 +93,7 @@ class TaskTest < ActiveSupport::TestCase task = Task.new task.requestor = sample_user - TaskMailer.expects(:deliver_task_created).with(task) + TaskMailer.expects(:generic_message).with('task_created', task) task.save! end @@ -101,7 +101,7 @@ class TaskTest < ActiveSupport::TestCase task = build(Task, :status => Task::Status::HIDDEN) task.requestor = sample_user - TaskMailer.expects(:deliver_task_created).never + TaskMailer.expects(:generic_message).with('task_created', anything).never task.save! end @@ -164,14 +164,21 @@ class TaskTest < ActiveSupport::TestCase target.stubs(:notification_emails).returns(['adm@example.com']) task.target = target task.stubs(:target_notification_message).returns('some non nil message to be sent to target') - TaskMailer.expects(:deliver_target_notification).once + + mailer = mock + mailer.expects(:deliver).once + TaskMailer.expects(:target_notification).returns(mailer).once task.save! end should 'not send notification to target if the task is hidden' do task = build(Task, :status => Task::Status::HIDDEN) + target = fast_create(Profile) + target.stubs(:notification_emails).returns(['adm@example.com']) + task.target = target task.stubs(:target_notification_message).returns('some non nil message to be sent to target') - TaskMailer.expects(:deliver_target_notification).never + + TaskMailer.expects(:target_notification).never task.save! end @@ -227,7 +234,7 @@ class TaskTest < ActiveSupport::TestCase should 'not notify target if message is nil' do task = Task.new task.stubs(:target_notification_message).returns(nil) - TaskMailer.expects(:deliver_target_notification).never + TaskMailer.expects(:target_notification).never task.save! end @@ -237,7 +244,7 @@ class TaskTest < ActiveSupport::TestCase target.stubs(:notification_emails).returns([]) task.target = target task.stubs(:target_notification_message).returns('some non nil message to be sent to target') - TaskMailer.expects(:deliver_target_notification).never + TaskMailer.expects(:target_notification).never task.save! end @@ -272,8 +279,9 @@ class TaskTest < ActiveSupport::TestCase should 'notify just after the task is activated' do task = build(Task, :status => Task::Status::HIDDEN) task.requestor = sample_user + task.save! - TaskMailer.expects(:deliver_task_activated).with(task) + TaskMailer.expects(:generic_message).with('task_activated', task) task.activate end @@ -284,7 +292,10 @@ class TaskTest < ActiveSupport::TestCase task.target = target task.save! task.stubs(:target_notification_message).returns('some non nil message to be sent to target') - TaskMailer.expects(:deliver_target_notification).once + + mailer = mock + mailer.expects(:deliver).once + TaskMailer.expects(:target_notification).returns(mailer).once task.activate end -- libgit2 0.21.2