2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-10-03 17:21:20 +08:00

DEV: Properly clean up global setting overrides in specs (#35058)

In the `SiteSettingExtension`, when calling
`SiteSetting.send(:setting_name, value)`,
if the setting counts as a global one, we add it to the list of hidden
and shadowed site settings in memory. However, when using the
`global_setting` helper in specs, we were not cleaning up these
overrides after the spec finished, leading to potential flakiness
in tests that rely on the visibility of site settings.

The fix is to just remove the setting from the hidden and shadowed
list after the spec is done.
This commit is contained in:
Martin Brennan 2025-09-30 17:44:41 +10:00 committed by GitHub
parent 14ee6bd67d
commit ac1d0e38ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -939,11 +939,17 @@ def before_next_spec(&callback)
end

def global_setting(name, value)
SiteSetting.hidden_settings_provider.remove_hidden(name)
SiteSetting.shadowed_settings.delete(name)
GlobalSetting.reset_s3_cache!

GlobalSetting.stubs(name).returns(value)

before_next_spec { GlobalSetting.reset_s3_cache! }
before_next_spec do
SiteSetting.hidden_settings_provider.remove_hidden(name)
SiteSetting.shadowed_settings.delete(name)
GlobalSetting.reset_s3_cache!
end
end

def set_cdn_url(cdn_url)