FIX: update `email_digests` user option when `default_email_digest_frequency` updated.

This commit is contained in:
Vinoth Kannan 2020-03-20 00:55:47 +05:30
parent 86eb03af85
commit f3ddc36ac6
2 changed files with 13 additions and 6 deletions

View File

@ -37,12 +37,10 @@ class Admin::SiteSettingsController < Admin::AdminController
new_value = UserOption.title_count_modes[new_value.to_sym]
end
UserOption.where(user_option => previous_value).update_all(user_option => new_value)
attrs = { user_option => new_value }
attrs[:email_digests] = (new_value.to_i != 0) if id == "default_email_digest_frequency"
if id == "default_email_digest_frequency"
disable_digests = new_value == 0
UserOption.where(user_option => 0, email_digests: !disable_digests).update_all(email_digests: disable_digests)
end
UserOption.where(user_option => previous_value).update_all(attrs)
elsif id.start_with?("default_categories_")
previous_category_ids = previous_value.split("|")
new_category_ids = new_value.split("|")

View File

@ -77,7 +77,16 @@ describe Admin::SiteSettingsController do
}.to change { UserOption.where(email_in_reply_to: false).count }.by(0)
end
it 'should disable email digests in existing user options' do
it 'should update `email_digests` column in existing user options' do
UserOption.last.update(email_digests: false)
expect {
put "/admin/site_settings/default_email_digest_frequency.json", params: {
default_email_digest_frequency: 30,
updateExistingUsers: true
}
}.to change { UserOption.where(email_digests: true).count }.by(1)
expect {
put "/admin/site_settings/default_email_digest_frequency.json", params: {
default_email_digest_frequency: 0,