Files
openfoodnetwork/spec/system/admin/enterprise_fees_spec.rb
Neal Chambers e923defd55 Safely autocorrect Layout/TrailingWhitespace
Inspecting 1479 files
...................................................................................................................................................C..C.......................................................................................................C.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C.....C..................C.............................................................................................C...................................................................C.......................................................................................................................................................................C....................................................C.............C...........CC.........C......C.CC.C....................C........................................................

Offenses:

app/controllers/spree/users_controller.rb:36:37: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
            partial("layouts/alert",
                                    ^
app/controllers/spree/users_controller.rb:51:35: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          partial("layouts/alert",
                                  ^
app/controllers/user_confirmations_controller.rb:27:33: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        partial("layouts/alert",
                                ^
app/models/enterprise.rb:117:24: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
  validates :instagram,
                       ^
spec/controllers/spree/credit_cards_controller_spec.rb:250:64: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                  create(:stored_credit_card, user_id: user.id,
                                                               ^
spec/controllers/user_confirmations_controller_spec.rb:45:44: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        session[:confirmation_return_url] =
                                           ^
spec/factories/order_factory.rb:40:67: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
            order.payments << build(:payment, amount: order.total,
                                                                  ^
spec/lib/reports/packing/packing_report_spec.rb:59:40: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        build(:line_item_with_shipment,
                                       ^
spec/lib/reports/packing/packing_report_spec.rb:63:40: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        build(:line_item_with_shipment,
                                       ^
spec/models/enterprise_spec.rb:521:67: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        expect(Enterprise.supplying_variant_in([p1.variants.first,
                                                                  ^
spec/models/enterprise_spec.rb:906:77: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      create(:enterprise_relationship, parent: distributor, child: supplier,
                                                                            ^
spec/services/products_renderer_spec.rb:22:73: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      create(:product, name: "banana bread", primary_taxon_id: cakes.id,
                                                                        ^
spec/services/products_renderer_spec.rb:88:88: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          product_apples.product_properties.create!({ property_id: property_organic.id,
                                                                                       ^
spec/services/products_renderer_spec.rb:90:87: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          products_renderer = ProductsRenderer.new(distributor, order_cycle, customer,
                                                                                      ^
spec/services/products_renderer_spec.rb:97:90: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          fruits_supplier.producer_properties.create!({ property_id: property_organic.id,
                                                                                         ^
spec/services/products_renderer_spec.rb:99:87: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          products_renderer = ProductsRenderer.new(distributor, order_cycle, customer,
                                                                                      ^
spec/services/products_renderer_spec.rb:109:93: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          product_apples.product_properties.create!({ property_id: property_conventional.id,
                                                                                            ^
spec/services/products_renderer_spec.rb:111:94: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          product_banana_bread.product_properties.create!({ property_id: property_organic.id,
                                                                                             ^
spec/services/products_renderer_spec.rb:113:90: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          product_cherries.product_properties.create!({ property_id: property_organic.id,
                                                                                         ^
spec/services/products_renderer_spec.rb:115:91: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          product_doughnuts.product_properties.create!({ property_id: property_organic.id,
                                                                                          ^
spec/services/products_renderer_spec.rb:117:87: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          products_renderer = ProductsRenderer.new(distributor, order_cycle, customer,
                                                                                      ^
spec/support/request/stripe_stubs.rb:17:81: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
  def stub_payment_intent_get_request(response: {}, stripe_account_header: true,
                                                                                ^
spec/support/request/stripe_stubs.rb:172:6: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
    {
     ^
spec/support/request/stripe_stubs.rb:175:24: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        object: "list",
                       ^
spec/support/request/stripe_stubs.rb:176:25: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        has_more: false,
                        ^
spec/system/admin/bulk_order_management_spec.rb:792:99: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      it "displays only line items whose orders meet the date restriction criteria, when changed",
                                                                                                  ^
spec/system/admin/bulk_order_management_spec.rb:1071:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/bulk_order_management_spec.rb:1121:82: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      shared_examples "display only group by information for selected variant" do
                                                                                 ^^^^^^^^^^
spec/system/admin/bulk_order_management_spec.rb:1143:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/bulk_order_management_spec.rb:1166:12: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        end
           ^
spec/system/admin/customers_spec.rb:18:98: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        create(:customer, first_name: 'John', last_name: 'Doe', enterprise: managed_distributor1,
                                                                                                 ^
spec/system/admin/enterprise_fees_spec.rb:102:37: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      select 'Inherit From Product',
                                    ^
spec/system/admin/enterprise_fees_spec.rb:128:38: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      select 'Weight (per kg or lb)',
                                     ^
spec/system/admin/enterprise_fees_spec.rb:132:37: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      select 'Flat Rate (per item)',
                                    ^
spec/system/admin/enterprise_fees_spec.rb:153:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.
spec/system/admin/enterprise_fees_spec.rb:153:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/enterprise_fees_spec.rb:157:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/enterprise_fees_spec.rb:159:38: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      select 'Flat Rate (per order)',
                                     ^
spec/system/admin/enterprise_fees_spec.rb:222:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/flatpickr_spec.rb:22:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/flatpickr_spec.rb:27:32: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      find("#admin-menu").click
                               ^^^^^^^
spec/system/admin/flatpickr_spec.rb:32:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/flatpickr_spec.rb:34:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/flatpickr_spec.rb:41:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_cycles/complex_editing_spec.rb:74:33: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
    expect(page).to have_select(
                                ^
spec/system/admin/order_cycles/complex_editing_spec.rb:110:33: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
    expect(page).to have_select(
                                ^
spec/system/admin/order_cycles/list_spec.rb:147:46: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          expect(find('input.datetimepicker',
                                             ^
spec/system/admin/order_cycles/list_spec.rb:160:46: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          expect(find('input.datetimepicker',
                                             ^
spec/system/admin/order_cycles/list_spec.rb:188:46: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          expect(find('input.datetimepicker',
                                             ^
spec/system/admin/order_cycles/simple_spec.rb:447:43: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        expect(page).not_to have_selector(
                                          ^
spec/system/admin/order_spec.rb:92:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:207:30: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          within(".modal") do
                             ^
spec/system/admin/order_spec.rb:235:21: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      login_as_admin
                    ^^
spec/system/admin/order_spec.rb:240:16: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      before do
               ^
spec/system/admin/order_spec.rb:247:62: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
    context "when using the cancel option in the dropdown" do
                                                             ^^
spec/system/admin/order_spec.rb:248:16: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      before do
               ^
spec/system/admin/order_spec.rb:299:53: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        expect(page).to have_content "Are you sure?"
                                                    ^^^^^^^^
spec/system/admin/order_spec.rb:327:36: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
        find("a.delete-item").click
                                   ^
spec/system/admin/order_spec.rb:401:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:405:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:598:59: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          expect(page).to have_link "Resend Confirmation",
                                                          ^
spec/system/admin/order_spec.rb:617:52: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          expect(page).to have_link "Cancel Order",
                                                   ^
spec/system/admin/order_spec.rb:633:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:635:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.
spec/system/admin/order_spec.rb:635:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:674:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:735:35: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
          within "#order-total" do
                                  ^
spec/system/admin/order_spec.rb:762:39: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
              within "#order-total" do
                                      ^
spec/system/admin/order_spec.rb:778:41: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                within "#order-total" do
                                        ^
spec/system/admin/order_spec.rb:780:20: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                end
                   ^^
spec/system/admin/order_spec.rb:796:39: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
              within "#order-total" do
                                      ^
spec/system/admin/order_spec.rb:807:88: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                # Since the order is completed, the price is not supposed to be updated
                                                                                       ^
spec/system/admin/order_spec.rb:813:41: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                within "#order-total" do
                                        ^
spec/system/admin/order_spec.rb:815:20: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
                end
                   ^^
spec/system/admin/order_spec.rb:924:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:959:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/order_spec.rb:981:16: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
      before do
               ^^
spec/system/admin/order_spec.rb:992:8: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
    end
       ^^
spec/system/admin/order_spec.rb:1002:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/shipping_methods_spec.rb:50:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
spec/system/admin/shipping_methods_spec.rb:92:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.

1479 files inspected, 81 offenses detected, 81 offenses corrected
2023-07-27 09:58:33 +10:00

344 lines
13 KiB
Ruby

# frozen_string_literal: true
require 'system_helper'
describe '
As an administrator
I want to manage enterprise fees
' do
include WebHelper
include AuthenticationHelper
let!(:tax_category_gst) { create(:tax_category, name: 'GST') }
it "listing enterprise fees" do
fee = create(:enterprise_fee, name: '$0.50 / kg', fee_type: 'packing',
tax_category: tax_category_gst)
amount = fee.calculator.preferred_amount
login_as_admin
visit spree.edit_admin_general_settings_path
click_link 'Enterprise Fees'
expect(page).to have_select "#{prefix}_enterprise_id"
expect(page).to have_select "#{prefix}_fee_type", selected: 'Packing fee'
expect(page).to have_selector "input[value='$0.50 / kg']"
expect(page).to have_select "#{prefix}_tax_category_id", selected: 'GST'
expect(page).to have_select "#{prefix}_calculator_type", selected: 'Flat Rate (per item)'
expect(page).to have_selector "input[value='#{amount}']"
end
it "creating an enterprise fee" do
# Given an enterprise
e = create(:supplier_enterprise, name: 'Feedme')
# When I go to the enterprise fees page
login_as_admin
visit admin_enterprise_fees_path
# And I fill in the fields for a new enterprise fee and click update
select 'Feedme', from: "#{prefix}_enterprise_id"
select 'Admin', from: "#{prefix}_fee_type"
fill_in "#{prefix}_name", with: 'Hello!'
select 'GST', from: "#{prefix}_tax_category_id"
select 'Flat Percent', from: "#{prefix}_calculator_type"
click_button 'Update'
# Then I should see my fee and fields for the calculator
expect(page).to have_content "Your enterprise fees have been updated."
expect(page).to have_selector "input[value='Hello!']"
# When I fill in the calculator fields and click update
fill_in "#{prefix}_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("##{prefix}_calculator" \
"_attributes_preferred_flat_percent[value='12.34']")
end
it "creating an enterprise fee with invalid amount shows error flash message" do
# Given an enterprise
e = create(:supplier_enterprise, name: 'Feedme')
# When I go to the enterprise fees page
login_as_admin
visit admin_enterprise_fees_path
# And I fill in the fields for a new enterprise fee and click update
select 'Feedme', from: "#{prefix}_enterprise_id"
select 'Admin', from: "#{prefix}_fee_type"
fill_in "#{prefix}_name", with: 'Hello!'
select 'GST', from: "#{prefix}_tax_category_id"
select 'Flat Percent', from: "#{prefix}_calculator_type"
click_button 'Update'
# Then I should see my fee and fields for the calculator
expect(page).to have_content "Your enterprise fees have been updated."
expect(page).to have_selector "input[value='Hello!']"
# When I fill in the calculator fields and click update
fill_in("#{prefix}_calculator_attributes_preferred_flat_percent", with: "\'20.0'")
click_button 'Update'
# Then I should see the flash error message
expect(flash_message).to eq('Invalid input. Please use only numbers. For example: 10, 5.5, -20')
end
context "editing an enterprise fee" do
# Given an enterprise fee
let!(:fee) { create(:enterprise_fee) }
let!(:enterprise) { create(:enterprise, name: 'Foo') }
before do
# When I go to the enterprise fees page
login_as_admin
visit admin_enterprise_fees_path
# And I update the fields for the enterprise fee and click update
select 'Foo', from: "#{prefix}_enterprise_id"
select 'Admin', from: "#{prefix}_fee_type"
fill_in "#{prefix}_name", with: 'Greetings!'
select 'Inherit From Product', from: "#{prefix}_tax_category_id"
select 'Flat Percent', from: "#{prefix}_calculator_type"
click_button 'Update'
end
it "handle the default cases" do
# Then I should see the updated fields for my fee
expect(page).to have_select "#{prefix}_enterprise_id", selected: 'Foo'
expect(page).to have_select "#{prefix}_fee_type", selected: 'Admin fee'
expect(page).to have_selector "input[value='Greetings!']"
expect(page).to have_select "#{prefix}_tax_category_id", selected: 'Inherit From Product'
expect(page).to have_selector "option[selected]", text: 'Flat Percent (per item)'
fee.reload
expect(fee.enterprise).to eq(enterprise)
expect(fee.name).to eq('Greetings!')
expect(fee.fee_type).to eq('admin')
expect(fee.calculator_type).to eq("Calculator::FlatPercentPerItem")
# Sets tax_category and inherits_tax_category
expect(fee.tax_category).to eq(nil)
expect(fee.inherits_tax_category).to eq(true)
end
it "handle when updating calculator type for Weight to Flat Rate" do
select 'Weight (per kg or lb)', from: "#{prefix}_calculator_type"
click_button 'Update'
select 'Flat Rate (per item)', from: "#{prefix}_calculator_type"
click_button 'Update'
expect(fee.reload.calculator_type).to eq("Calculator::PerItem")
end
it 'shows error flash when updating fee amount with invalid values' do
# When I fill in the calculator fields and click update
fill_in(
"#{prefix}_calculator_attributes_" \
'preferred_flat_percent', with: "\'20.0'"
)
click_button 'Update'
# Then I should see the flash error message
expect(flash_message)
.to eq('Invalid input. Please use only numbers. For example: 10, 5.5, -20')
end
it "does not allow editing to an invalid combination" do
# starting with a valid tax category / calculator combination
expect(page).to have_select "#{prefix}_tax_category_id", selected: 'Inherit From Product'
expect(page).to have_selector "option[selected]", text: 'Flat Percent (per item)'
# editing to an invalid combination
select 'Flat Rate (per order)', from: "#{prefix}_calculator_type"
expect{ click_button 'Update' }.to_not change { fee.reload.calculator_type }
expect(page).to have_content "Inheriting the tax categeory requires a per-item calculator."
end
context "editing two enterprise fees" do
let!(:fee1) { create(:enterprise_fee, fee_type: "sales", enterprise_id: enterprise.id) }
before do
# edits the existing fee
select 'Fundraising', from: "#{prefix}_fee_type"
fill_in "#{prefix}_name", with: 'Hello!'
# edits the another fee
select 'Sales', from: "#{prefix1}_fee_type"
fill_in "#{prefix1}_name", with: 'World!'
select 'GST', from: "#{prefix1}_tax_category_id"
select 'Flat Rate', from: "#{prefix1}_calculator_type"
click_button 'Update'
# edits the mounts on the calculators
fill_in "#{prefix}_calculator_attributes_preferred_flat_percent", with: 12.5
fill_in "#{prefix1}_calculator_attributes_preferred_amount", with: 1.5
click_button 'Update'
end
it "handles updating two enterprise fees" do
# Then I should see the updated fields for my fees
expect(page).to have_select "#{prefix}_fee_type", selected: 'Fundraising fee'
expect(page).to have_selector "input[value='Hello!']"
expect(page).to have_select "#{prefix}_tax_category_id", selected: 'Inherit From Product'
expect(page).to have_selector "option[selected]", text: 'Flat Percent (per item)'
expect(page).to have_field "Flat Percent:", with: '12.5'
expect(page).to have_select "#{prefix1}_enterprise_id", selected: 'Foo'
expect(page).to have_select "#{prefix1}_fee_type", selected: 'Sales fee'
expect(page).to have_selector "input[value='World!']"
expect(page).to have_select "#{prefix1}_tax_category_id", selected: 'GST'
expect(page).to have_selector "option[selected]", text: 'Flat Rate (per order)'
expect(page).to have_field "Amount:", with: '1.5'
fee.reload
expect(fee.enterprise).to eq(enterprise)
expect(fee.name).to eq('Hello!')
expect(fee.fee_type).to eq('fundraising')
expect(fee.calculator_type).to eq("Calculator::FlatPercentPerItem")
fee1.reload
expect(fee1.enterprise).to eq(enterprise)
expect(fee1.name).to eq('World!')
expect(fee1.fee_type).to eq('sales')
expect(fee1.calculator_type).to eq("Calculator::FlatRate")
# Sets tax_category and inherits_tax_category
expect(fee.tax_category).to eq(nil)
expect(fee.inherits_tax_category).to eq(true)
# Sets tax_category and inherits_tax_category
expect(fee1.tax_category).to eq(tax_category_gst)
expect(fee1.inherits_tax_category).to eq(false)
end
end
end
it "deleting an enterprise fee" do
# Given an enterprise fee
fee = create(:enterprise_fee)
# When I go to the enterprise fees page
login_as_admin
visit admin_enterprise_fees_path
# And I click delete
accept_alert do
find("a.delete-resource").click
end
# Then my enterprise fee should have been deleted
visit admin_enterprise_fees_path
expect(page).to have_no_selector "input[value='#{fee.name}']"
end
context "as an enterprise manager" do
let(:enterprise_user) { create(:user) }
let(:distributor1) { create(:distributor_enterprise, name: 'First Distributor') }
let(:distributor2) { create(:distributor_enterprise, name: 'Second Distributor') }
let(:distributor3) { create(:distributor_enterprise, name: 'Third Distributor') }
let(:ef1) { create(:enterprise_fee, name: 'One', enterprise: distributor1) }
let(:ef2) { create(:enterprise_fee, name: 'Two', enterprise: distributor2) }
before(:each) do
enterprise_user.enterprise_roles.build(enterprise: distributor1).save
enterprise_user.enterprise_roles.build(enterprise: distributor2).save
login_as enterprise_user
end
context "creating an enterprise fee" do
before do
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") { click_link 'Enterprise Fees' }
click_link "Create One Now"
end
shared_examples "setting it up" do |tax_category, calculator, flash_message, fee_count|
context "as #{tax_category}, with a #{calculator} calculator" do
it "triggers the expected message" do
select distributor1.name, from: "#{prefix}_enterprise_id"
select 'Packing', from: "#{prefix}_fee_type"
fill_in "#{prefix}_name", with: 'foo'
select tax_category, from: "#{prefix}_tax_category_id"
select calculator, from: "#{prefix}_calculator_type"
click_button 'Update'
# The correct flash message should be displayed
expect(page).to have_content(flash_message)
# After saving, we should be redirected to the fees for our chosen enterprise
expect(page).
not_to have_select 'sets_enterprise_fee_set_collection_attributes_1_enterprise_id',
selected: 'Second Distributor'
# A new enterprise fee is created
expect(EnterpriseFee.count).to eq(fee_count)
end
end
end
context "an error message is displayed" do
message = 'Inheriting the tax categeory requires a per-item calculator.'
it_behaves_like "setting it up", 'Inherit From Product',
'Flat Rate (per order)', message, 0
end
context "an success message is displayed" do
message = 'Your enterprise fees have been updated.'
it_behaves_like "setting it up", 'Inherit From Product', 'Flat Rate (per item)', message, 1
end
context "an success message is displayed" do
message = 'Your enterprise fees have been updated.'
it_behaves_like "setting it up", 'GST', 'Flat Rate (per order)', message, 1
end
context "an success message is displayed" do
message = 'Your enterprise fees have been updated.'
it_behaves_like "setting it up", 'GST', 'Flat Rate (per item)', message, 1
end
end
it "shows me only enterprise fees for the enterprise I select" do
ef1
ef2
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") { click_link 'Enterprise Fees' }
click_link "Manage Enterprise Fees"
expect(page).to have_field "#{prefix}_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 "#{prefix}_name", with: 'One'
expect(page).to have_field "#{prefix}_name", with: 'Two'
end
it "only allows me to select enterprises I have access to" do
ef1
ef2
distributor3
visit edit_admin_enterprise_path(distributor2)
within(".side_menu") { click_link 'Enterprise Fees' }
click_link "Manage Enterprise Fees"
expect(page).to have_select("#{prefix}_enterprise_id",
selected: 'Second Distributor',
options: ['First Distributor', 'Second Distributor'])
end
end
end
def prefix
'sets_enterprise_fee_set_collection_attributes_0'
end
def prefix1
'sets_enterprise_fee_set_collection_attributes_1'
end