FIX: update `email_digests` user option when `default_email_digest_frequency` updated.
This commit is contained in:
parent
86eb03af85
commit
f3ddc36ac6
|
@ -37,12 +37,10 @@ class Admin::SiteSettingsController < Admin::AdminController
|
||||||
new_value = UserOption.title_count_modes[new_value.to_sym]
|
new_value = UserOption.title_count_modes[new_value.to_sym]
|
||||||
end
|
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"
|
UserOption.where(user_option => previous_value).update_all(attrs)
|
||||||
disable_digests = new_value == 0
|
|
||||||
UserOption.where(user_option => 0, email_digests: !disable_digests).update_all(email_digests: disable_digests)
|
|
||||||
end
|
|
||||||
elsif id.start_with?("default_categories_")
|
elsif id.start_with?("default_categories_")
|
||||||
previous_category_ids = previous_value.split("|")
|
previous_category_ids = previous_value.split("|")
|
||||||
new_category_ids = new_value.split("|")
|
new_category_ids = new_value.split("|")
|
||||||
|
|
|
@ -77,7 +77,16 @@ describe Admin::SiteSettingsController do
|
||||||
}.to change { UserOption.where(email_in_reply_to: false).count }.by(0)
|
}.to change { UserOption.where(email_in_reply_to: false).count }.by(0)
|
||||||
end
|
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 {
|
expect {
|
||||||
put "/admin/site_settings/default_email_digest_frequency.json", params: {
|
put "/admin/site_settings/default_email_digest_frequency.json", params: {
|
||||||
default_email_digest_frequency: 0,
|
default_email_digest_frequency: 0,
|
||||||
|
|
Loading…
Reference in New Issue