From 7a1ff59822b3ad22c17b86745755ceff519b841f Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Thu, 5 Jan 2017 13:45:55 +0530 Subject: [PATCH] FIX: PM email to suspended member was broken --- app/jobs/regular/user_email.rb | 2 +- spec/jobs/user_email_spec.rb | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rb index 3f6193501df..3214055563b 100644 --- a/app/jobs/regular/user_email.rb +++ b/app/jobs/regular/user_email.rb @@ -74,7 +74,7 @@ module Jobs set_skip_context(type, user.id, to_address || user.email, post.try(:id)) return skip_message(I18n.t("email_log.anonymous_user")) if user.anonymous? - return skip_message(I18n.t("email_log.suspended_not_pm")) if user.suspended? && type != :user_private_message + return skip_message(I18n.t("email_log.suspended_not_pm")) if user.suspended? && type.to_s != "user_private_message" return if user.staged && type == :digest diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rb index a1af812c12d..e596a63b311 100644 --- a/spec/jobs/user_email_spec.rb +++ b/spec/jobs/user_email_spec.rb @@ -110,21 +110,21 @@ describe Jobs::UserEmail do let(:post) { Fabricate(:post, user: user) } it 'passes a post as an argument when a post_id is present' do - UserNotifications.expects(:private_message).with(user, {post: post}).returns(mailer) + UserNotifications.expects(:user_private_message).with(user, {post: post}).returns(mailer) Email::Sender.any_instance.expects(:send) - Jobs::UserEmail.new.execute(type: :private_message, user_id: user.id, post_id: post.id) + Jobs::UserEmail.new.execute(type: :user_private_message, user_id: user.id, post_id: post.id) end it "doesn't send the email if you've seen the post" do Email::Sender.any_instance.expects(:send).never PostTiming.record_timing(topic_id: post.topic_id, user_id: user.id, post_number: post.post_number, msecs: 6666) - Jobs::UserEmail.new.execute(type: :private_message, user_id: user.id, post_id: post.id) + Jobs::UserEmail.new.execute(type: :user_private_message, user_id: user.id, post_id: post.id) end it "doesn't send the email if the user deleted the post" do Email::Sender.any_instance.expects(:send).never post.update_column(:user_deleted, true) - Jobs::UserEmail.new.execute(type: :private_message, user_id: user.id, post_id: post.id) + Jobs::UserEmail.new.execute(type: :user_private_message, user_id: user.id, post_id: post.id) end it "doesn't send the email if user of the post has been deleted" do @@ -136,14 +136,14 @@ describe Jobs::UserEmail do context 'user is suspended' do it "doesn't send email for a pm from a regular user" do Email::Sender.any_instance.expects(:send).never - Jobs::UserEmail.new.execute(type: :private_message, user_id: suspended.id, post_id: post.id) + Jobs::UserEmail.new.execute(type: :user_private_message, user_id: suspended.id, post_id: post.id) end - it "doesn't send email for a pm from a staff user" do + it "does send an email for a pm from a staff user" do pm_from_staff = Fabricate(:post, user: Fabricate(:moderator)) pm_from_staff.topic.topic_allowed_users.create!(user_id: suspended.id) - Email::Sender.any_instance.expects(:send).never - Jobs::UserEmail.new.execute(type: :private_message, user_id: suspended.id, post_id: pm_from_staff.id) + Email::Sender.any_instance.expects(:send) + Jobs::UserEmail.new.execute(type: :user_private_message, user_id: suspended.id, post_id: pm_from_staff.id) end end @@ -152,14 +152,14 @@ describe Jobs::UserEmail do it "doesn't send email for a pm from a regular user" do Email::Sender.any_instance.expects(:send).never - Jobs::UserEmail.new.execute(type: :private_message, user_id: anonymous.id, post_id: post.id) + Jobs::UserEmail.new.execute(type: :user_private_message, user_id: anonymous.id, post_id: post.id) end it "doesn't send email for a pm from a staff user" do pm_from_staff = Fabricate(:post, user: Fabricate(:moderator)) pm_from_staff.topic.topic_allowed_users.create!(user_id: anonymous.id) Email::Sender.any_instance.expects(:send).never - Jobs::UserEmail.new.execute(type: :private_message, user_id: anonymous.id, post_id: pm_from_staff.id) + Jobs::UserEmail.new.execute(type: :user_private_message, user_id: anonymous.id, post_id: pm_from_staff.id) end end end