Bundle update & restructure tests (RSpec 3)
This commit is contained in:
parent
7b2bcedb16
commit
aa7a2a31ae
14 changed files with 412 additions and 413 deletions
|
|
@ -1,66 +1,63 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe 'admin/configs', type: :feature do
|
||||
feature 'admin/configs' do
|
||||
let(:name) { Faker::Lorem.words(rand(2..4)).join(' ') }
|
||||
let(:email) { Faker::Internet.email }
|
||||
let(:admin) { create :admin }
|
||||
|
||||
describe type: :feature, js: true do
|
||||
let(:admin) { create :admin }
|
||||
before { login 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
|
||||
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
|
||||
|
||||
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
|
||||
end
|
||||
expect(FoodsoftConfig[:contact][:email]).to eq email
|
||||
end
|
||||
|
||||
def get_full_config
|
||||
cfg = FoodsoftConfig.to_hash.deep_dup
|
||||
compact_hash_deep!(cfg)
|
||||
end
|
||||
|
||||
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?}
|
||||
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
|
||||
|
||||
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
|
||||
end
|
||||
expect(FoodsoftConfig[:contact][:email]).to eq email
|
||||
end
|
||||
|
||||
def get_full_config
|
||||
cfg = FoodsoftConfig.to_hash.deep_dup
|
||||
compact_hash_deep!(cfg)
|
||||
end
|
||||
|
||||
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?}
|
||||
end
|
||||
end
|
||||
h.reject! {|k,v| v.blank?}
|
||||
h
|
||||
end
|
||||
|
||||
h.reject! {|k,v| v.blank?}
|
||||
h
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue