allow protected keys to be set/unset + config_db tests
This commit is contained in:
parent
9beaac2627
commit
6115979bae
7 changed files with 179 additions and 13 deletions
|
|
@ -13,6 +13,9 @@ default: &defaults
|
|||
contact:
|
||||
email: fc@minimal.test
|
||||
|
||||
# required by configuration form (but otherwise not)
|
||||
homepage: http://www.minimal.test/
|
||||
|
||||
# true by default to keep compat with older installations, but test with false here
|
||||
use_nick: false
|
||||
|
||||
|
|
|
|||
45
spec/integration/config_spec.rb
Normal file
45
spec/integration/config_spec.rb
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe 'admin/configs', type: :feature do
|
||||
let(:name) { Faker::Lorem.words(rand(2..4)).join(' ') }
|
||||
|
||||
describe type: :feature, js: true do
|
||||
let(:admin) { create :admin }
|
||||
before { login admin }
|
||||
|
||||
it 'has initial value' do
|
||||
FoodsoftConfig[:name] = name
|
||||
visit admin_config_path
|
||||
within('form.config') do
|
||||
expect(find_field('config_name').value).to eq name
|
||||
end
|
||||
end
|
||||
|
||||
it 'can modify a value' do
|
||||
visit admin_config_path
|
||||
fill_in 'config_name', with: name
|
||||
within('form.config') do
|
||||
find('input[type="submit"]').click
|
||||
expect(find_field('config_name').value).to eq name
|
||||
end
|
||||
expect(FoodsoftConfig[:name]).to eq name
|
||||
end
|
||||
|
||||
it 'keeps config the same without changes' do
|
||||
orig_values = get_full_config
|
||||
visit admin_config_path
|
||||
within('form.config') do
|
||||
find('input[type="submit"]').click
|
||||
expect(find_field('config_name').value).to eq FoodsoftConfig[:name]
|
||||
end
|
||||
expect(get_full_config).to eq orig_values
|
||||
end
|
||||
|
||||
def get_full_config
|
||||
cfg = FoodsoftConfig.to_hash.deep_dup
|
||||
cfg.each {|k,v| v.reject! {|k,v| v.blank?} if v.is_a? Hash}
|
||||
cfg
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
85
spec/lib/foodsoft_config_spec.rb
Normal file
85
spec/lib/foodsoft_config_spec.rb
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe FoodsoftConfig do
|
||||
let(:name) { Faker::Lorem.words(rand(2..4)).join(' ') }
|
||||
let(:other_name) { Faker::Lorem.words(rand(2..4)).join(' ') }
|
||||
|
||||
it 'returns a default value' do
|
||||
expect(FoodsoftConfig[:protected][:database]).to be_true
|
||||
end
|
||||
|
||||
it 'returns an empty default value' do
|
||||
expect(FoodsoftConfig[:protected][:LIUhniuyGNKUQTWfbiOQIWYexngo78hqexul]).to be_false
|
||||
end
|
||||
|
||||
it 'returns a configuration value' do
|
||||
FoodsoftConfig.config[:name] = name
|
||||
expect(FoodsoftConfig[:name]).to eq name
|
||||
end
|
||||
|
||||
it 'can set a configuration value' do
|
||||
FoodsoftConfig[:name] = name
|
||||
expect(FoodsoftConfig[:name]).to eq name
|
||||
end
|
||||
|
||||
it 'can override a configuration value' do
|
||||
FoodsoftConfig.config[:name] = name
|
||||
FoodsoftConfig[:name] = other_name
|
||||
expect(FoodsoftConfig[:name]).to eq other_name
|
||||
end
|
||||
|
||||
it 'cannot set a default protected value' do
|
||||
old = FoodsoftConfig[:database]
|
||||
FoodsoftConfig[:database] = name
|
||||
expect(FoodsoftConfig.config[:database]).to eq old
|
||||
end
|
||||
|
||||
it 'can unprotect a default protected value' do
|
||||
FoodsoftConfig.config[:protected][:database] = false
|
||||
old = FoodsoftConfig[:database]
|
||||
FoodsoftConfig[:database] = name
|
||||
expect(FoodsoftConfig[:database]).to eq name
|
||||
end
|
||||
|
||||
describe 'can protect a value', type: :feature do
|
||||
before do
|
||||
FoodsoftConfig.config[:protected][:name] = true
|
||||
end
|
||||
|
||||
it 'can protect a value' do
|
||||
old_name = FoodsoftConfig[:name]
|
||||
FoodsoftConfig[:name] = name
|
||||
expect(FoodsoftConfig[:name]).to eq old_name
|
||||
end
|
||||
|
||||
it 'and unprotect it again' do
|
||||
old_name = FoodsoftConfig[:name]
|
||||
FoodsoftConfig.config[:protected][:name] = false
|
||||
FoodsoftConfig[:name] = name
|
||||
expect(FoodsoftConfig[:name]).to eq name
|
||||
end
|
||||
end
|
||||
|
||||
describe 'has indifferent access', type: :feature do
|
||||
it 'with symbol' do
|
||||
FoodsoftConfig[:name] = name
|
||||
expect(FoodsoftConfig[:name]).to eq FoodsoftConfig['name']
|
||||
end
|
||||
|
||||
it 'with string' do
|
||||
FoodsoftConfig['name'] = name
|
||||
expect(FoodsoftConfig['name']).to eq FoodsoftConfig[:name]
|
||||
end
|
||||
|
||||
it 'with nested symbol' do
|
||||
FoodsoftConfig[:protected][:database] = true
|
||||
expect(FoodsoftConfig[:protected]['database']).to eq FoodsoftConfig[:protected][:database]
|
||||
end
|
||||
|
||||
it 'with nested string' do
|
||||
FoodsoftConfig[:protected]['database'] = true
|
||||
expect(FoodsoftConfig[:protected]['database']).to eq FoodsoftConfig[:protected][:database]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -35,6 +35,8 @@ RSpec.configure do |config|
|
|||
end
|
||||
config.after(:each) do
|
||||
DatabaseCleaner.clean
|
||||
# Need to clear cache for RailsSettings::CachedSettings
|
||||
Rails.cache.clear
|
||||
end
|
||||
|
||||
# reload foodsoft configuration, so that tests can use FoodsoftConfig.config[:foo]=x
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue