FIX: email always settings were not being respected

FIX: email always settings were not being respected

https://meta.discourse.org/t/email-notification-for-messages/163937/10?u=techapj

diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rb
index 20edc25..d39e02c 100644
--- a/app/jobs/regular/user_email.rb
+++ b/app/jobs/regular/user_email.rb
@@ -244,11 +244,11 @@ module Jobs
     end
 
     def always_email_private_message?(user, type)
-      type == :user_private_message && user.user_option.email_messages_level == UserOption.email_level_types[:always]
+      type.to_s == "user_private_message" && user.user_option.email_messages_level == UserOption.email_level_types[:always]
     end
 
     def always_email_regular?(user, type)
-      type != :user_private_message && user.user_option.email_level == UserOption.email_level_types[:always]
+      type.to_s != "user_private_message" && user.user_option.email_level == UserOption.email_level_types[:always]
     end
   end
 
diff --git a/spec/jobs/user_email_spec.rb b/spec/jobs/user_email_spec.rb
index 0c22877..a716f52 100644
--- a/spec/jobs/user_email_spec.rb
+++ b/spec/jobs/user_email_spec.rb
@@ -174,6 +174,21 @@ describe Jobs::UserEmail do
       MD
     end
 
+    it "sends a PM email to a user that's been recently seen and has email_messages_level set to always" do
+      user.user_option.update(email_messages_level: UserOption.email_level_types[:always])
+      user.user_option.update(email_level: UserOption.email_level_types[:never])
+      Jobs::UserEmail.new.execute(
+        type: :user_private_message,
+        user_id: user.id,
+        post_id: post.id,
+        notification_id: notification.id
+      )
+
+      expect(ActionMailer::Base.deliveries.first.to).to contain_exactly(
+        user.email
+      )
+    end
+
     it "doesn't send a PM email to a user that's been recently seen and has email_messages_level set to never" do
       user.user_option.update(email_messages_level: UserOption.email_level_types[:never])
       user.user_option.update(email_level: UserOption.email_level_types[:always])

GitHub sha: 3684337e

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/email-notification-for-messages/163937/13