fixed with_settings helper so that it works with Setting.self_registration too

before this change using `with_settings: { self_registration: '3' }`
would only mock `Setting.self_registration` correctly but would omit
`Setting.self_registration?`.
pull/7249/head
Markus Kahl 6 years ago
parent 2308592305
commit d8c9e6e2cb
  1. 18
      spec/support/shared/with_settings.rb

@ -46,21 +46,15 @@ RSpec.configure do |config|
if settings.present?
settings = aggregate_mocked_settings(example, settings)
allow(Setting).to receive(:[]).and_call_original
settings.each do |k, v|
bare, questionmarked = if k.to_s.ends_with?('?')
[k.to_s[0..-2].to_sym, k]
else
[k, "#{k}?".to_sym]
end
name = k.to_s.sub(/\?\Z/, '') # remove trailing question mark if present to get setting name
raise "#{k} is not a valid setting" unless Setting.respond_to?(bare)
raise "#{k} is not a valid setting" unless Setting.respond_to?(name)
if Setting.available_settings[bare.to_s] && Setting.available_settings[bare.to_s]['format'] == 'boolean'
allow(Setting).to receive(bare).and_return(v)
allow(Setting).to receive(questionmarked).and_return(v)
else
allow(Setting).to receive(k).and_return(v)
end
allow(Setting).to receive(:[]).with(name).and_return v
allow(Setting).to receive(:[]).with(name.to_sym).and_return v
end
end
end

Loading…
Cancel
Save