diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb index 9d1536856e..73880badf4 100644 --- a/app/controllers/admin/enterprise_fees_controller.rb +++ b/app/controllers/admin/enterprise_fees_controller.rb @@ -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, diff --git a/app/helpers/enterprise_fees_helper.rb b/app/helpers/enterprise_fees_helper.rb index cc22f07326..55647b6413 100644 --- a/app/helpers/enterprise_fees_helper.rb +++ b/app/helpers/enterprise_fees_helper.rb @@ -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 diff --git a/app/views/admin/enterprise_fees/_calculator_settings.html.haml b/app/views/admin/enterprise_fees/_calculator_settings.html.haml index 4936ee35b2..be05330d6c 100644 --- a/app/views/admin/enterprise_fees/_calculator_settings.html.haml +++ b/app/views/admin/enterprise_fees/_calculator_settings.html.haml @@ -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? diff --git a/spec/features/admin/enterprise_fees_spec.rb b/spec/features/admin/enterprise_fees_spec.rb index 862a338f15..057840525b 100644 --- a/spec/features/admin/enterprise_fees_spec.rb +++ b/spec/features/admin/enterprise_fees_spec.rb @@ -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