2018-03-29 05:47:54 -04:00
|
|
|
require 'active_support/core_ext/hash/transform_values'
|
|
|
|
require 'active_support/hash_with_indifferent_access'
|
|
|
|
|
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
|
2017-07-20 04:50:07 -04:00
|
|
|
allow_any_instance_of(ApplicationSetting).to receive_messages(to_settings(messages))
|
2017-06-21 09:48:12 -04:00
|
|
|
allow(Gitlab::CurrentSettings.current_application_settings)
|
2017-07-20 04:50:07 -04:00
|
|
|
.to receive_messages(to_settings(messages))
|
2017-12-15 05:23:11 -05:00
|
|
|
|
|
|
|
# Ensure that we don't use the Markdown cache when stubbing these values
|
|
|
|
allow_any_instance_of(ApplicationSetting).to receive(:cached_html_up_to_date?).and_return(false)
|
2015-06-29 15:04:57 -04:00
|
|
|
end
|
|
|
|
|
2017-07-18 10:32:34 -04:00
|
|
|
def stub_not_protect_default_branch
|
|
|
|
stub_application_setting(
|
|
|
|
default_branch_protection: Gitlab::Access::PROTECTION_NONE)
|
|
|
|
end
|
|
|
|
|
2015-06-29 15:04:57 -04:00
|
|
|
def stub_config_setting(messages)
|
2017-07-20 04:50:07 -04:00
|
|
|
allow(Gitlab.config.gitlab).to receive_messages(to_settings(messages))
|
2015-06-29 15:04:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def stub_gravatar_setting(messages)
|
2017-07-20 04:50:07 -04:00
|
|
|
allow(Gitlab.config.gravatar).to receive_messages(to_settings(messages))
|
2015-06-29 15:04:57 -04:00
|
|
|
end
|
2015-07-01 17:21:51 -04:00
|
|
|
|
2015-09-21 03:46:47 -04:00
|
|
|
def stub_incoming_email_setting(messages)
|
2017-07-20 04:50:07 -04:00
|
|
|
allow(Gitlab.config.incoming_email).to receive_messages(to_settings(messages))
|
2015-08-20 16:21:22 -04:00
|
|
|
end
|
|
|
|
|
2017-03-28 08:12:32 -04:00
|
|
|
def stub_mattermost_setting(messages)
|
2017-07-20 04:50:07 -04:00
|
|
|
allow(Gitlab.config.mattermost).to receive_messages(to_settings(messages))
|
2017-03-28 08:12:32 -04:00
|
|
|
end
|
|
|
|
|
2017-03-23 09:49:59 -04:00
|
|
|
def stub_omniauth_setting(messages)
|
2017-07-20 04:50:07 -04:00
|
|
|
allow(Gitlab.config.omniauth).to receive_messages(to_settings(messages))
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_backup_setting(messages)
|
|
|
|
allow(Gitlab.config.backup).to receive_messages(to_settings(messages))
|
2017-03-23 09:49:59 -04:00
|
|
|
end
|
|
|
|
|
2017-11-03 09:59:47 -04:00
|
|
|
def stub_lfs_setting(messages)
|
|
|
|
allow(Gitlab.config.lfs).to receive_messages(to_settings(messages))
|
|
|
|
end
|
|
|
|
|
2018-04-03 12:47:33 -04:00
|
|
|
def stub_artifacts_setting(messages)
|
|
|
|
allow(Gitlab.config.artifacts).to receive_messages(to_settings(messages))
|
|
|
|
end
|
|
|
|
|
2017-08-07 16:06:11 -04:00
|
|
|
def stub_storage_settings(messages)
|
2017-11-13 10:52:07 -05:00
|
|
|
messages.deep_stringify_keys!
|
|
|
|
|
2017-08-13 08:52:44 -04:00
|
|
|
# Default storage is always required
|
|
|
|
messages['default'] ||= Gitlab.config.repositories.storages.default
|
2018-03-14 09:42:49 -04:00
|
|
|
messages.each do |storage_name, storage_hash|
|
|
|
|
if !storage_hash.key?('path') || storage_hash['path'] == Gitlab::GitalyClient::StorageSettings::Deprecated
|
|
|
|
storage_hash['path'] = TestEnv.repos_path
|
|
|
|
end
|
|
|
|
|
|
|
|
messages[storage_name] = Gitlab::GitalyClient::StorageSettings.new(storage_hash.to_h)
|
2017-08-07 16:06:11 -04:00
|
|
|
end
|
|
|
|
|
2017-08-13 08:52:44 -04:00
|
|
|
allow(Gitlab.config.repositories).to receive(:storages).and_return(Settingslogic.new(messages))
|
2017-08-07 16:06:11 -04:00
|
|
|
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
|
2017-07-20 04:50:07 -04:00
|
|
|
|
|
|
|
# Support nested hashes by converting all values into Settingslogic objects
|
|
|
|
def to_settings(hash)
|
|
|
|
hash.transform_values do |value|
|
|
|
|
if value.is_a? Hash
|
|
|
|
Settingslogic.new(value.deep_stringify_keys)
|
|
|
|
else
|
|
|
|
value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-06-29 15:04:57 -04:00
|
|
|
end
|