discourse/spec/support/site_settings_provider.rb
Jarek Radosz 960f34da9d
DEV: Finish extracting rails spec helpers (#40552)
Also move matchers to a subdirectory
2026-06-04 14:11:14 +02:00

28 lines
1 KiB
Ruby
Vendored

# frozen_string_literal: true
# In-memory site-settings storage provider for specs, replacing the DB-backed
# one. `install!` is called from before(:suite) after plugins/themes/settings
# have loaded — ordering matters, so the call stays in rails_helper.
class TestLocalProcessProvider < SiteSettings::LocalProcessProvider
attr_accessor :current_site
def initialize
super
self.current_site = "test"
end
# We nuke the DB storage provider from site settings, so we yank out the
# existing (seeded) settings and pretend they're defaults, then swap in this
# in-memory provider.
def self.install!
SiteSetting.current.each do |k, v|
# skip setting defaults for settings that are in unloaded plugins
SiteSetting.defaults.set_regardless_of_locale(k, v) if SiteSetting.respond_to? k
end
# Gravatar downloads hit the network, so force the default off.
SiteSetting.defaults.set_regardless_of_locale(:automatically_download_gravatars, false)
SiteSetting.provider = new
end
end