Adapt enterprise fees code and specs to new namespace of Sets::EnterpriseFeeSet

This commit is contained in:
Luis Ramos
2020-11-01 12:01:03 +00:00
parent 96a351ad0e
commit 5d6d7f7ad0
4 changed files with 34 additions and 34 deletions

View File

@@ -80,7 +80,7 @@ module Admin
end
def enterprise_fee_bulk_params
params.require(:enterprise_fee_set).permit(
params.require(:sets_enterprise_fee_set).permit(
collection_attributes: [
:id, :enterprise_id, :fee_type, :name, :tax_category_id,
:inherits_tax_category, :calculator_type,

View File

@@ -1,10 +1,10 @@
module EnterpriseFeesHelper
def angular_name(method)
"enterprise_fee_set[collection_attributes][{{ $index }}][#{method}]"
"sets_enterprise_fee_set[collection_attributes][{{ $index }}][#{method}]"
end
def angular_id(method)
"enterprise_fee_set_collection_attributes_{{ $index }}_#{method}"
"sets_enterprise_fee_set_collection_attributes_{{ $index }}_#{method}"
end
def enterprise_fee_type_options

View File

@@ -1,7 +1,7 @@
-# Render only the calculator settings and not the surrounding form
- enterprise_fee_set = Sets::ModelSet.new(EnterpriseFee, EnterpriseFee.where(:id => enterprise_fee.id))
- calculator_form_string = nil
- form_for enterprise_fee_set, :as => :enterprise_fee_set, :url => '' do |form|
- form_for enterprise_fee_set, :as => :sets_enterprise_fee_set, :url => '' do |form|
- form.fields_for :collection do |f|
- calculator_form_string = capture do
- if !enterprise_fee.new_record?

View File

@@ -18,11 +18,11 @@ feature '
login_as_admin_and_visit spree.edit_admin_general_settings_path
click_link 'Enterprise Fees'
expect(page).to have_select "enterprise_fee_set_collection_attributes_0_enterprise_id"
expect(page).to have_select "enterprise_fee_set_collection_attributes_0_fee_type", selected: 'Packing fee'
expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_enterprise_id"
expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_fee_type", selected: 'Packing fee'
expect(page).to have_selector "input[value='$0.50 / kg']"
expect(page).to have_select "enterprise_fee_set_collection_attributes_0_tax_category_id", selected: 'GST'
expect(page).to have_select "enterprise_fee_set_collection_attributes_0_calculator_type", selected: 'Flat Rate (per item)'
expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_tax_category_id", selected: 'GST'
expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_calculator_type", selected: 'Flat Rate (per item)'
expect(page).to have_selector "input[value='#{amount}']"
end
@@ -34,11 +34,11 @@ feature '
login_as_admin_and_visit admin_enterprise_fees_path
# And I fill in the fields for a new enterprise fee and click update
select 'Feedme', from: 'enterprise_fee_set_collection_attributes_0_enterprise_id'
select 'Admin', from: 'enterprise_fee_set_collection_attributes_0_fee_type'
fill_in 'enterprise_fee_set_collection_attributes_0_name', with: 'Hello!'
select 'GST', from: 'enterprise_fee_set_collection_attributes_0_tax_category_id'
select 'Flat Percent', from: 'enterprise_fee_set_collection_attributes_0_calculator_type'
select 'Feedme', from: 'sets_enterprise_fee_set_collection_attributes_0_enterprise_id'
select 'Admin', from: 'sets_enterprise_fee_set_collection_attributes_0_fee_type'
fill_in 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'Hello!'
select 'GST', from: 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id'
select 'Flat Percent', from: 'sets_enterprise_fee_set_collection_attributes_0_calculator_type'
click_button 'Update'
# Then I should see my fee and fields for the calculator
@@ -46,11 +46,11 @@ feature '
expect(page).to have_selector "input[value='Hello!']"
# When I fill in the calculator fields and click update
fill_in 'enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent', with: '12.34'
fill_in 'sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent', with: '12.34'
click_button 'Update'
# Then I should see the correct values in my calculator fields
expect(page).to have_selector "#enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent[value='12.34']"
expect(page).to have_selector "#sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent[value='12.34']"
end
scenario "editing an enterprise fee" do
@@ -62,18 +62,18 @@ feature '
login_as_admin_and_visit admin_enterprise_fees_path
# And I update the fields for the enterprise fee and click update
select 'Foo', from: 'enterprise_fee_set_collection_attributes_0_enterprise_id'
select 'Admin', from: 'enterprise_fee_set_collection_attributes_0_fee_type'
fill_in 'enterprise_fee_set_collection_attributes_0_name', with: 'Greetings!'
select 'Inherit From Product', from: 'enterprise_fee_set_collection_attributes_0_tax_category_id'
select 'Flat Percent', from: 'enterprise_fee_set_collection_attributes_0_calculator_type'
select 'Foo', from: 'sets_enterprise_fee_set_collection_attributes_0_enterprise_id'
select 'Admin', from: 'sets_enterprise_fee_set_collection_attributes_0_fee_type'
fill_in 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'Greetings!'
select 'Inherit From Product', from: 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id'
select 'Flat Percent', from: 'sets_enterprise_fee_set_collection_attributes_0_calculator_type'
click_button 'Update'
# Then I should see the updated fields for my fee
expect(page).to have_select "enterprise_fee_set_collection_attributes_0_enterprise_id", selected: 'Foo'
expect(page).to have_select "enterprise_fee_set_collection_attributes_0_fee_type", selected: 'Admin fee'
expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_enterprise_id", selected: 'Foo'
expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_fee_type", selected: 'Admin fee'
expect(page).to have_selector "input[value='Greetings!']"
expect(page).to have_select 'enterprise_fee_set_collection_attributes_0_tax_category_id', selected: 'Inherit From Product'
expect(page).to have_select 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id', selected: 'Inherit From Product'
expect(page).to have_selector "option[selected]", text: 'Flat Percent (per item)'
fee.reload
@@ -123,17 +123,17 @@ feature '
within(".side_menu") { click_link 'Enterprise Fees' }
click_link "Create One Now"
select distributor1.name, from: 'enterprise_fee_set_collection_attributes_0_enterprise_id'
select 'Packing', from: 'enterprise_fee_set_collection_attributes_0_fee_type'
fill_in 'enterprise_fee_set_collection_attributes_0_name', with: 'foo'
select 'GST', from: 'enterprise_fee_set_collection_attributes_0_tax_category_id'
select 'Flat Percent', from: 'enterprise_fee_set_collection_attributes_0_calculator_type'
select distributor1.name, from: 'sets_enterprise_fee_set_collection_attributes_0_enterprise_id'
select 'Packing', from: 'sets_enterprise_fee_set_collection_attributes_0_fee_type'
fill_in 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'foo'
select 'GST', from: 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id'
select 'Flat Percent', from: 'sets_enterprise_fee_set_collection_attributes_0_calculator_type'
click_button 'Update'
expect(flash_message).to eq('Your enterprise fees have been updated.')
# After saving, we should be redirected to the fees for our chosen enterprise
expect(page).not_to have_select 'enterprise_fee_set_collection_attributes_1_enterprise_id', selected: 'Second Distributor'
expect(page).not_to have_select 'sets_enterprise_fee_set_collection_attributes_1_enterprise_id', selected: 'Second Distributor'
enterprise_fee = EnterpriseFee.find_by name: 'foo'
expect(enterprise_fee.enterprise).to eq(distributor1)
@@ -146,14 +146,14 @@ feature '
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") { click_link 'Enterprise Fees' }
click_link "Manage Enterprise Fees"
expect(page).to have_field 'enterprise_fee_set_collection_attributes_0_name', with: 'One'
expect(page).not_to have_field 'enterprise_fee_set_collection_attributes_1_name', with: 'Two'
expect(page).to have_field 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'One'
expect(page).not_to have_field 'sets_enterprise_fee_set_collection_attributes_1_name', with: 'Two'
visit edit_admin_enterprise_path(distributor2)
within(".side_menu") { click_link 'Enterprise Fees' }
click_link "Manage Enterprise Fees"
expect(page).not_to have_field 'enterprise_fee_set_collection_attributes_0_name', with: 'One'
expect(page).to have_field 'enterprise_fee_set_collection_attributes_0_name', with: 'Two'
expect(page).not_to have_field 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'One'
expect(page).to have_field 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'Two'
end
it "only allows me to select enterprises I have access to" do
@@ -164,7 +164,7 @@ feature '
visit edit_admin_enterprise_path(distributor2)
within(".side_menu") { click_link 'Enterprise Fees' }
click_link "Manage Enterprise Fees"
expect(page).to have_select('enterprise_fee_set_collection_attributes_0_enterprise_id',
expect(page).to have_select('sets_enterprise_fee_set_collection_attributes_0_enterprise_id',
selected: 'Second Distributor',
options: ['', 'First Distributor', 'Second Distributor'])
end