From ea0e63b150f8a8baea62ec86e295efe80368c16e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 5 Feb 2016 20:07:30 +0100 Subject: [PATCH] FIX: handle cases where we only pass the notification type rather than the notification id when sending user email --- app/jobs/regular/user_email.rb | 15 ++++++++------- spec/jobs/user_email_spec.rb | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rb index 54a18809e..14f34b42c 100644 --- a/app/jobs/regular/user_email.rb +++ b/app/jobs/regular/user_email.rb @@ -48,13 +48,7 @@ module Jobs @skip_context = { type: type, user_id: user_id, to_address: to_address } end - NOTIFICATIONS_SENT_BY_MAILING_LIST ||= Set.new [ - Notification.types[:posted], - Notification.types[:replied], - Notification.types[:mentioned], - Notification.types[:group_mentioned], - Notification.types[:quoted], - ] + NOTIFICATIONS_SENT_BY_MAILING_LIST ||= Set.new %w{posted replied mentioned group_mentioned quoted} def message_for_email(user, post, type, notification, notification_type=nil, notification_data_hash=nil, @@ -84,6 +78,13 @@ module Jobs email_args[:notification_type] ||= notification_type || notification.try(:notification_type) email_args[:notification_data_hash] ||= notification_data_hash || notification.try(:data_hash) + unless String === email_args[:notification_type] + if Numeric === email_args[:notification_type] + email_args[:notification_type] = Notification.types[email_args[:notification_type]] + end + email_args[:notification_type] = email_args[:notification_type].to_s + end + if user.mailing_list_mode? && !post.topic.private_message? && NOTIFICATIONS_SENT_BY_MAILING_LIST.include?(email_args[:notification_type]) diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rb index e0dc712d6..c7ab345a1 100644 --- a/spec/jobs/user_email_spec.rb +++ b/spec/jobs/user_email_spec.rb @@ -195,7 +195,10 @@ describe Jobs::UserEmail do it "doesn't send the mail if the user is using mailing list mode" do Email::Sender.any_instance.expects(:send).never user.update_column(:mailing_list_mode, true) + # sometimes, we pass the notification_id Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id) + # other times, we only pass the type of notification + Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_type: "posted", post_id: post.id) end it "doesn't send the email if the post has been user deleted" do