From 813fcebdd12dbb525945c0b47aaafe9ebca258bd Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 1 Jul 2016 11:22:07 +1000 Subject: [PATCH] FIX: email_always was not respected correctly In the past email always meant, email me even if active UNLESS I read post Now emails always means, always, even if I read the post --- app/jobs/regular/user_email.rb | 6 +++++- spec/jobs/user_email_spec.rb | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rb index aba01b83c..bb6b8cc1d 100644 --- a/app/jobs/regular/user_email.rb +++ b/app/jobs/regular/user_email.rb @@ -179,7 +179,11 @@ module Jobs return I18n.t('email_log.post_user_deleted') if post.user.blank? return I18n.t('email_log.post_deleted') if post.user_deleted? return I18n.t('email_log.user_suspended') if (user.suspended? && !post.user.try(:staff?)) - return I18n.t('email_log.already_read') if PostTiming.where(topic_id: post.topic_id, post_number: post.post_number, user_id: user.id).present? + + if !user.user_option.email_always? && + PostTiming.where(topic_id: post.topic_id, post_number: post.post_number, user_id: user.id).present? + return I18n.t('email_log.already_read') + end else false end diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rb index e6e2dfb6c..4f4d07d22 100644 --- a/spec/jobs/user_email_spec.rb +++ b/spec/jobs/user_email_spec.rb @@ -57,6 +57,8 @@ describe Jobs::UserEmail do it "does send an email to a user that's been recently seen but has email_always set" do user.update_attributes(last_seen_at: 9.minutes.ago) user.user_option.update_attributes(email_always: true) + PostTiming.create!(topic_id: post.topic_id, post_number: post.post_number, user_id: user.id, msecs: 100) + Email::Sender.any_instance.expects(:send) Jobs::UserEmail.new.execute(type: :user_replied, user_id: user.id, post_id: post.id) end