gitlab-org--gitlab-foss/lib/gitlab/fake_application_settings.rb
Stan Hu 70799b05ab Add additional stub methods for FakeApplicationSetting
In a migration spec, a default ApplicationSetting object may fail to
create due to an unknown attribute and fall back to
FakeApplicationSetting.  FakeApplicationSetting appears to be missing a
number of methods that are needed
(https://gitlab.com/gitlab-org/gitlab-ce/issues/47491). This commit adds
the ones needed to make an EE spec pass.

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/7543
2018-09-10 22:27:21 -07:00

39 lines
1.1 KiB
Ruby

# This class extends an OpenStruct object by adding predicate methods to mimic
# ActiveRecord access. We rely on the initial values being true or false to
# determine whether to define a predicate method because for a newly-added
# column that has not been migrated yet, there is no way to determine the
# column type without parsing db/schema.rb.
module Gitlab
class FakeApplicationSettings < OpenStruct
# Mimic ActiveRecord predicate methods for boolean values
def self.define_predicate_methods(options)
options.each do |key, value|
next if key.to_s.end_with?('?')
next unless [true, false].include?(value)
define_method "#{key}?" do
actual_key = key.to_s.chomp('?')
self[actual_key]
end
end
end
def initialize(options = {})
super
FakeApplicationSettings.define_predicate_methods(options)
end
def key_restriction_for(type)
0
end
def allowed_key_types
ApplicationSetting::SUPPORTED_KEY_TYPES
end
def pick_repository_storage
repository_storages.sample
end
end
end