1
0
REI-Fixed/spec/support/examples/lib/settings/scoped_settings.rb

75 lines
2.0 KiB
Ruby
Raw Normal View History

2017-06-05 00:07:39 +09:00
# frozen_string_literal: true
shared_examples 'ScopedSettings' do
describe '[]' do
it 'inherits default settings' do
2023-02-20 14:14:50 +09:00
expect(Setting.boost_modal).to be false
expect(Setting.interactions['must_be_follower']).to be false
2017-06-05 00:07:39 +09:00
settings = create!
2023-02-20 14:14:50 +09:00
expect(settings['boost_modal']).to be false
expect(settings['interactions']['must_be_follower']).to be false
2017-06-05 00:07:39 +09:00
end
end
describe 'all_as_records' do
# expecting [] and []= works
it 'returns records merged with default values except hashes' do
2023-02-20 14:14:50 +09:00
expect(Setting.boost_modal).to be false
expect(Setting.delete_modal).to be true
2017-06-05 00:07:39 +09:00
settings = create!
settings['boost_modal'] = true
records = settings.all_as_records
2023-02-20 14:14:50 +09:00
expect(records['boost_modal'].value).to be true
expect(records['delete_modal'].value).to be true
2017-06-05 00:07:39 +09:00
end
end
describe 'missing methods' do
# expecting [] and []= works.
it 'reads settings' do
2023-02-20 14:14:50 +09:00
expect(Setting.boost_modal).to be false
2017-06-05 00:07:39 +09:00
settings = create!
2023-02-20 14:14:50 +09:00
expect(settings.boost_modal).to be false
2017-06-05 00:07:39 +09:00
end
it 'updates settings' do
settings = fabricate
settings.boost_modal = true
2023-02-20 14:14:50 +09:00
expect(settings['boost_modal']).to be true
2017-06-05 00:07:39 +09:00
end
end
it 'can update settings with [] and can read with []=' do
settings = fabricate
settings['boost_modal'] = true
settings['interactions'] = settings['interactions'].merge('must_be_follower' => true)
Setting.save!
2023-02-20 14:14:50 +09:00
expect(settings['boost_modal']).to be true
expect(settings['interactions']['must_be_follower']).to be true
2017-06-05 00:07:39 +09:00
Rails.cache.clear
2023-02-20 14:14:50 +09:00
expect(settings['boost_modal']).to be true
expect(settings['interactions']['must_be_follower']).to be true
2017-06-05 00:07:39 +09:00
end
xit 'does not mutate defaults via the cache' do
fabricate['interactions']['must_be_follower'] = true
# TODO
# This mutates the global settings default such that future
# instances will inherit the incorrect starting values
2023-02-20 14:14:50 +09:00
expect(fabricate.settings['interactions']['must_be_follower']).to be false
2017-06-05 00:07:39 +09:00
end
end