FIX: handle cases where we only pass the notification type rather than the notification id when sending user email

This commit is contained in:
Régis Hanol 2016-02-05 20:07:30 +01:00
parent 91ec2c5171
commit ea0e63b150
2 changed files with 11 additions and 7 deletions

View file

@ -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])

View file

@ -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