mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 04:51:17 +08:00
DEV: introduce new API to look up dynamic site setting
This removes all uses of both `send` and `public_send` from consumers of SiteSetting and instead introduces a `get` helper for dynamic lookup This leads to much cleaner and safer code long term as we are always explicit to test that a site setting is really there before sending an arbitrary string to the class It also removes a couple of risky stubs from the auth provider test
This commit is contained in:
@ -130,10 +130,11 @@ describe Plugin::Instance do
|
||||
end
|
||||
|
||||
it 'patches the enabled? function for auth_providers if not defined' do
|
||||
SiteSetting.stubs(:ubuntu_login_enabled).returns(false)
|
||||
|
||||
plugin = Plugin::Instance.new
|
||||
|
||||
# lets piggy back on another boolean setting, so we don't dirty our SiteSetting object
|
||||
SiteSetting.enable_badges = false
|
||||
|
||||
# No enabled_site_setting
|
||||
authenticator = Auth::Authenticator.new
|
||||
plugin.auth_provider(authenticator: authenticator)
|
||||
@ -143,26 +144,28 @@ describe Plugin::Instance do
|
||||
# With enabled site setting
|
||||
plugin = Plugin::Instance.new
|
||||
authenticator = Auth::Authenticator.new
|
||||
plugin.auth_provider(enabled_setting: 'ubuntu_login_enabled', authenticator: authenticator)
|
||||
plugin.auth_provider(enabled_setting: 'enable_badges', authenticator: authenticator)
|
||||
plugin.notify_before_auth
|
||||
expect(authenticator.enabled?).to eq(false)
|
||||
|
||||
# Defines own method
|
||||
plugin = Plugin::Instance.new
|
||||
SiteSetting.stubs(:ubuntu_login_enabled).returns(true)
|
||||
|
||||
SiteSetting.enable_badges = true
|
||||
authenticator = Class.new(Auth::Authenticator) do
|
||||
def enabled?
|
||||
false
|
||||
end
|
||||
end.new
|
||||
plugin.auth_provider(enabled_setting: 'ubuntu_login_enabled', authenticator: authenticator)
|
||||
plugin.auth_provider(enabled_setting: 'enable_badges', authenticator: authenticator)
|
||||
plugin.notify_before_auth
|
||||
expect(authenticator.enabled?).to eq(false)
|
||||
end
|
||||
|
||||
context "activate!" do
|
||||
before do
|
||||
SiteSetting.stubs(:ubuntu_login_enabled).returns(false)
|
||||
# lets piggy back on another boolean setting, so we don't dirty our SiteSetting object
|
||||
SiteSetting.enable_badges = false
|
||||
end
|
||||
|
||||
it "can activate plugins correctly" do
|
||||
|
Reference in New Issue
Block a user