mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Create plugin outlet for console site setting logging (#31564)
This change allows plugins to customize the description for site setting logs that occur via site setting changes via the rails console.
This commit is contained in:
@ -1142,5 +1142,49 @@ RSpec.describe SiteSettingExtension do
|
||||
expect(logger_spy).not_to have_received(:log_site_setting_change)
|
||||
end
|
||||
end
|
||||
|
||||
context "with plugin modifiers for log details" do
|
||||
before do
|
||||
settings.setting(:plugin_test, "initial")
|
||||
settings.refresh!
|
||||
end
|
||||
|
||||
it "uses the default log details when no plugin modifiers exist" do
|
||||
logger_spy = instance_spy(StaffActionLogger)
|
||||
allow(StaffActionLogger).to receive(:new).with(Discourse.system_user).and_return(logger_spy)
|
||||
|
||||
settings.plugin_test = "changed"
|
||||
expect(settings.plugin_test).to eq("changed")
|
||||
expect(logger_spy).to have_received(:log_site_setting_change).with(
|
||||
:plugin_test,
|
||||
"initial",
|
||||
"changed",
|
||||
{ details: "Updated via Rails console" },
|
||||
).once
|
||||
end
|
||||
|
||||
it "applies plugin modifiers to log details" do
|
||||
# Allow all apply_modifier calls to pass through normally
|
||||
allow(DiscoursePluginRegistry).to receive(:apply_modifier).and_call_original
|
||||
|
||||
# But specifically mock our target call
|
||||
allow(DiscoursePluginRegistry).to receive(:apply_modifier).with(
|
||||
:site_setting_log_details,
|
||||
"Updated via Rails console",
|
||||
).and_return("Updated via Rails console via test plugin")
|
||||
|
||||
logger_spy = instance_spy(StaffActionLogger)
|
||||
allow(StaffActionLogger).to receive(:new).with(Discourse.system_user).and_return(logger_spy)
|
||||
|
||||
settings.plugin_test = "changed"
|
||||
expect(settings.plugin_test).to eq("changed")
|
||||
expect(logger_spy).to have_received(:log_site_setting_change).with(
|
||||
:plugin_test,
|
||||
"initial",
|
||||
"changed",
|
||||
{ details: "Updated via Rails console via test plugin" },
|
||||
).once
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user