FIX: automatically disable digests when enabling mailing list mode

This commit is contained in:
Régis Hanol 2016-11-28 15:52:35 +01:00
parent 671e230490
commit 6edd3c347c
2 changed files with 17 additions and 2 deletions

View File

@ -70,14 +70,13 @@ class UserUpdater
TagUser.batch_set(user, level, attributes[attribute])
end
save_options = false
OPTION_ATTR.each do |attribute|
if attributes.key?(attribute)
save_options = true
if [true,false].include?(user.user_option.send(attribute))
if [true, false].include?(user.user_option.send(attribute))
val = attributes[attribute].to_s == 'true'
user.user_option.send("#{attribute}=", val)
else
@ -86,6 +85,9 @@ class UserUpdater
end
end
# automatically disable digests when mailing_list_mode is enabled
user.user_option.email_digests = false if user.user_option.mailing_list_mode
fields = attributes[:custom_fields]
if fields.present?
user.custom_fields = user.custom_fields.merge(fields)

View File

@ -91,6 +91,19 @@ describe UserUpdater do
expect(user.date_of_birth).to eq(date_of_birth.to_date)
end
it "disables email_digests when enabling mailing_list_mode" do
user = Fabricate(:user)
updater = UserUpdater.new(acting_user, user)
val = updater.update(mailing_list_mode: true, email_digests: true)
expect(val).to be_truthy
user.reload
expect(user.user_option.email_digests).to eq false
expect(user.user_option.mailing_list_mode).to eq true
end
context 'when sso overrides bio' do
it 'does not change bio' do
SiteSetting.enable_sso = true