2015-06-29 15:04:57 -04:00
|
|
|
module StubConfiguration
|
|
|
|
def stub_application_setting(messages)
|
2015-07-01 17:21:51 -04:00
|
|
|
add_predicates(messages)
|
|
|
|
|
|
|
|
# Stubbing both of these because we're not yet consistent with how we access
|
|
|
|
# current application settings
|
|
|
|
allow_any_instance_of(ApplicationSetting).to receive_messages(messages)
|
2015-06-29 15:04:57 -04:00
|
|
|
allow(Gitlab::CurrentSettings.current_application_settings).
|
|
|
|
to receive_messages(messages)
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_config_setting(messages)
|
|
|
|
allow(Gitlab.config.gitlab).to receive_messages(messages)
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_gravatar_setting(messages)
|
|
|
|
allow(Gitlab.config.gravatar).to receive_messages(messages)
|
|
|
|
end
|
2015-07-01 17:21:51 -04:00
|
|
|
|
2015-09-21 03:46:47 -04:00
|
|
|
def stub_incoming_email_setting(messages)
|
|
|
|
allow(Gitlab.config.incoming_email).to receive_messages(messages)
|
2015-08-20 16:21:22 -04:00
|
|
|
end
|
|
|
|
|
2017-03-28 08:12:32 -04:00
|
|
|
def stub_mattermost_setting(messages)
|
|
|
|
allow(Gitlab.config.mattermost).to receive_messages(messages)
|
|
|
|
end
|
|
|
|
|
2017-03-23 09:49:59 -04:00
|
|
|
def stub_omniauth_setting(messages)
|
|
|
|
allow(Gitlab.config.omniauth).to receive_messages(messages)
|
|
|
|
end
|
|
|
|
|
2015-07-01 17:21:51 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
# Modifies stubbed messages to also stub possible predicate versions
|
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
#
|
|
|
|
# add_predicates(foo: true)
|
|
|
|
# # => {foo: true, foo?: true}
|
|
|
|
#
|
|
|
|
# add_predicates(signup_enabled?: false)
|
|
|
|
# # => {signup_enabled? false}
|
|
|
|
def add_predicates(messages)
|
|
|
|
# Only modify keys that aren't already predicates
|
|
|
|
keys = messages.keys.map(&:to_s).reject { |k| k.end_with?('?') }
|
|
|
|
|
|
|
|
keys.each do |key|
|
|
|
|
predicate = key + '?'
|
|
|
|
messages[predicate.to_sym] = messages[key.to_sym]
|
|
|
|
end
|
|
|
|
end
|
2015-06-29 15:04:57 -04:00
|
|
|
end
|