FIX: Site setting changes for boolean should be logged as true/false (#16888)

Previously true/false sometimes was logged as t or f
This commit is contained in:
Gerhard Schlager 2022-05-23 05:23:10 +02:00 committed by GitHub
parent 049f6e58c8
commit 1e1b85c214
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -182,8 +182,8 @@ class StaffActionLogger
UserHistory.create!(params(opts).merge(
action: UserHistory.actions[:change_site_setting],
subject: setting_name,
previous_value: previous_value,
new_value: new_value
previous_value: previous_value&.to_s,
new_value: new_value&.to_s
))
end

View File

@ -145,6 +145,18 @@ describe StaffActionLogger do
it "creates a new UserHistory record" do
expect { logger.log_site_setting_change('title', 'Discourse', 'My Site') }.to change { UserHistory.count }.by(1)
end
it "logs boolean values" do
log_record = logger.log_site_setting_change("allow_user_locale", true, false)
expect(log_record.previous_value).to eq("true")
expect(log_record.new_value).to eq("false")
end
it "logs nil values" do
log_record = logger.log_site_setting_change("title", nil, nil)
expect(log_record.previous_value).to be_nil
expect(log_record.new_value).to be_nil
end
end
describe "log_theme_change" do