FIX: email always settings were not being respected

https://meta.discourse.org/t/email-notification-for-messages/163937/10?u=techapj
This commit is contained in:
Arpit Jalan 2020-09-23 21:43:21 +05:30
parent 214b4c3910
commit 3684337e4a
2 changed files with 17 additions and 2 deletions

View File

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

View File

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