2014-06-25 16:21:36 +02:00
|
|
|
require_relative '../spec_helper'
|
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
feature 'admin/configs' do
|
2019-10-28 09:40:43 +01:00
|
|
|
let(:name) { Faker::Lorem.words(number: rand(2..4)).join(' ') }
|
2014-09-02 16:19:08 +02:00
|
|
|
let(:email) { Faker::Internet.email }
|
2015-04-24 15:19:57 +02:00
|
|
|
let(:admin) { create :admin }
|
2014-06-25 16:21:36 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
before { login admin }
|
2014-06-25 16:21:36 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
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
|
2014-06-25 16:21:36 +02:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
end
|
2014-06-25 16:21:36 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
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
|
2014-06-25 16:21:36 +02:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(FoodsoftConfig[:name]).to eq name
|
|
|
|
end
|
2014-06-25 16:21:36 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
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]
|
2014-06-25 16:21:36 +02:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(get_full_config).to eq orig_values
|
|
|
|
end
|
2014-06-25 16:21:36 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
it 'can modify a nested value' do
|
|
|
|
visit admin_config_path
|
|
|
|
fill_in 'config_contact_email', with: email
|
|
|
|
within('form.config') do
|
|
|
|
find('input[type="submit"]').click
|
|
|
|
expect(find_field('config_contact_email').value).to eq email
|
2014-09-02 16:19:08 +02:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
expect(FoodsoftConfig[:contact][:email]).to eq email
|
|
|
|
end
|
2014-09-02 16:19:08 +02:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
def get_full_config
|
|
|
|
cfg = FoodsoftConfig.to_hash.deep_dup
|
|
|
|
compact_hash_deep!(cfg)
|
|
|
|
end
|
2014-11-22 00:33:16 +01:00
|
|
|
|
2015-04-24 15:19:57 +02:00
|
|
|
def compact_hash_deep!(h)
|
|
|
|
h.each do |k,v|
|
|
|
|
if v.is_a? Hash
|
|
|
|
compact_hash_deep!(v)
|
|
|
|
v.reject! {|k,v| v.blank?}
|
2014-11-22 00:33:16 +01:00
|
|
|
end
|
2014-06-25 16:21:36 +02:00
|
|
|
end
|
2015-04-24 15:19:57 +02:00
|
|
|
h.reject! {|k,v| v.blank?}
|
|
|
|
h
|
2014-06-25 16:21:36 +02:00
|
|
|
end
|
|
|
|
end
|