REFACTOR: DRY up code and add better test coverage.

This commit is contained in:
Guo Xiang Tan
2017-10-23 11:16:14 +08:00
parent 87e4c2a90f
commit e91a631978
2 changed files with 27 additions and 12 deletions

View File

@@ -110,15 +110,15 @@ class UserUpdater
update_muted_users(attributes[:muted_usernames])
end
saved = (!save_options || user.user_option.save) && user_profile.save && user.save
if (saved = (!save_options || user.user_option.save) && user_profile.save && user.save) &&
(attributes[:name].present? && old_user_name.casecmp(attributes.fetch(:name)) != 0) ||
(attributes[:name].blank? && old_user_name.present?)
if saved
# log name changes
if attributes[:name].present? && old_user_name.downcase != attributes.fetch(:name).downcase
StaffActionLogger.new(@actor).log_name_change(user.id, old_user_name, attributes.fetch(:name))
elsif attributes[:name].blank? && old_user_name.present?
StaffActionLogger.new(@actor).log_name_change(user.id, old_user_name, "")
end
StaffActionLogger.new(@actor).log_name_change(
user.id,
old_user_name,
attributes.fetch(:name) { '' }
)
end
end