FIX: do not log category custom fields changes if the value is unchanged (#16712)

This commit is contained in:
Arpit Jalan 2022-05-11 13:51:51 +05:30 committed by GitHub
parent 631bfb2a23
commit 977da1da77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -455,6 +455,7 @@ class StaffActionLogger
if old_custom_fields && category_params[:custom_fields]
category_params[:custom_fields].each do |key, value|
next if old_custom_fields[key] == value
changed_attributes["custom_fields[#{key}]"] = [old_custom_fields[key], value]
end
end

View File

@ -387,6 +387,38 @@ describe StaffActionLogger do
expect(UserHistory.count).to eq(1)
expect(UserHistory.find_by_subject('name').category).to eq(category)
end
it "logs custom fields changes" do
attributes = {
custom_fields: { "auto_populated" => "t" }
}
category.update!(attributes)
logger.log_category_settings_change(
category,
attributes,
old_permissions: category.permissions_params,
old_custom_fields: {}
)
expect(UserHistory.count).to eq(1)
end
it "does not log custom fields changes if value is unchanged" do
attributes = {
custom_fields: { "auto_populated" => "t" }
}
category.update!(attributes)
logger.log_category_settings_change(
category,
attributes,
old_permissions: category.permissions_params,
old_custom_fields: { "auto_populated" => "t" }
)
expect(UserHistory.count).to eq(0)
end
end
describe 'log_category_deletion' do