mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-29 21:17:17 +00:00
Inspecting 1478 files
.......C............................C..............................................................................................................C.......................................................................................................C............................................................................C................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C.................C......................................C...................................................................................................................C...........................................................C........................C...C.....C..C..C..........C..................C...............C.....................C...................................................................................C......................................................C........C..C...........C....................C.CC....C....................................C......C..........................
Offenses:
app/components/confirm_modal_component.rb:4:88: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
def initialize(id:, confirm_actions: nil, reflex: nil, controller: nil, message: nil,
^
app/components/confirm_modal_component.rb:4:101: C: [Corrected] Layout/LineLength: Line is too long. [110/100]
def initialize(id:, confirm_actions: nil, reflex: nil, controller: nil, message: nil, confirm_reflexes: nil)
^^^^^^^^^^
app/components/confirm_modal_component.rb:5:1: C: [Corrected] Layout/ParameterAlignment: Align the parameters of a method definition if they span more than one line.
confirm_reflexes: nil)
^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/product_import_controller.rb:142:43: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
redirect_to '/admin/product_import',
^
app/controllers/admin/product_import_controller.rb:142:101: C: [Corrected] Layout/LineLength: Line is too long. [104/100]
redirect_to '/admin/product_import', notice: I18n.t(:product_import_no_data_in_spreadsheet_notice)
^^^^
app/controllers/admin/product_import_controller.rb:143:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
notice: I18n.t(:product_import_no_data_in_spreadsheet_notice)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/spree/users_controller.rb:53:101: C: Layout/LineLength: Line is too long. [107/100]
message: t('devise.user_registrations.spree_user.signed_up_but_unconfirmed') })
^^^^^^^
app/models/customer.rb:43:101: C: [Corrected] Layout/LineLength: Line is too long. [113/100]
scope :managed_by, ->(user) { user&.persisted? ? where(user: user).or(of(Enterprise.managed_by(user))) : none }
^^^^^^^^^^^^^
app/models/customer.rb:44:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 1) spaces for indentation.
user&.persisted? ? where(user: user).or(of(Enterprise.managed_by(user))) : none
^
app/models/customer.rb:44:3: C: [Corrected] Layout/IndentationWidth: Use 2 (not -19) spaces for indentation.
user&.persisted? ? where(user: user).or(of(Enterprise.managed_by(user))) : none
^^^^^^^^^^^^^^^^^^^
app/models/customer.rb:44:82: C: [Corrected] Layout/BlockEndNewline: Expression at 44, 82 should be on its own line.
user&.persisted? ? where(user: user).or(of(Enterprise.managed_by(user))) : none }
^
app/models/customer.rb:44:101: C: Layout/LineLength: Line is too long. [102/100]
user&.persisted? ? where(user: user).or(of(Enterprise.managed_by(user))) : none
^^
app/models/customer.rb:45:1: C: [Corrected] Layout/BlockAlignment: } at 45, 0 is not aligned with ->(user) { at 43, 21 or scope :managed_by, ->(user) { at 43, 2.
}
^
app/models/spree/line_item.rb:53:101: C: Layout/LineLength: Line is too long. [110/100]
attr_accessor :skip_stock_check, :target_shipment # Allows manual skipping of Stock::AvailabilityValidator
^^^^^^^^^^
spec/controllers/admin/order_cycles_controller_spec.rb:38:101: C: Layout/LineLength: Line is too long. [108/100]
it "loads order cycles that closed within the past month, and orders without a close_at date" do
^^^^^^^^
spec/controllers/admin/order_cycles_controller_spec.rb:48:101: C: Layout/LineLength: Line is too long. [111/100]
it "loads order cycles that closed after the specified date, and orders without a close_at date" do
^^^^^^^^^^^
spec/controllers/admin/order_cycles_controller_spec.rb:100:101: C: Layout/LineLength: Line is too long. [125/100]
expect(flash[:error]).to eq "You don't have permission to create an order cycle coordinated by that enterprise"
^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/admin/order_cycles_controller_spec.rb:125:101: C: Layout/LineLength: Line is too long. [101/100]
order_cycle.exchanges.create! sender: distributor, receiver: distributor, incoming: true,
^
spec/controllers/admin/order_cycles_controller_spec.rb:127:101: C: Layout/LineLength: Line is too long. [102/100]
order_cycle.exchanges.create! sender: distributor, receiver: distributor, incoming: false,
^^
spec/controllers/admin/order_cycles_controller_spec.rb:284:101: C: Layout/LineLength: Line is too long. [101/100]
merge(order_cycle: { preferred_product_selection_from_coordinator_inventory_only: true })
^
spec/controllers/admin/order_cycles_controller_spec.rb:311:101: C: Layout/LineLength: Line is too long. [104/100]
create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: hub, incoming: false,
^^^^
spec/controllers/admin/order_cycles_controller_spec.rb:374:101: C: Layout/LineLength: Line is too long. [102/100]
expect(json_response['errors']).to eq 'Hm, something went wrong. No order cycle data found.'
^^
spec/controllers/admin/order_cycles_controller_spec.rb:460:101: C: Layout/LineLength: Line is too long. [176/100]
expect(flash[:error]).to eq 'That order cycle has been selected by a customer and cannot be deleted. To prevent customers from accessing it, please close it instead.'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/admin/order_cycles_controller_spec.rb:470:101: C: Layout/LineLength: Line is too long. [147/100]
expect(flash[:error]).to eq 'That order cycle is linked to a schedule and cannot be deleted. Please unlink or delete the schedule first.'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/api/v0/order_cycles_controller_spec.rb:16:101: C: [Corrected] Layout/LineLength: Line is too long. [106/100]
let!(:product1) { create(:product, name: "Kangaroo", primary_taxon: taxon1, properties: [property1]) }
^^^^^^
spec/controllers/api/v0/order_cycles_controller_spec.rb:17:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 1) spaces for indentation.
create(:product, name: "Kangaroo", primary_taxon: taxon1, properties: [property1])
^
spec/controllers/api/v0/order_cycles_controller_spec.rb:17:3: C: [Corrected] Layout/IndentationWidth: Use 2 (not -2) spaces for indentation.
create(:product, name: "Kangaroo", primary_taxon: taxon1, properties: [property1])
^^
spec/controllers/api/v0/order_cycles_controller_spec.rb:17:85: C: [Corrected] Layout/BlockEndNewline: Expression at 17, 85 should be on its own line.
create(:product, name: "Kangaroo", primary_taxon: taxon1, properties: [property1]) }
^
spec/controllers/api/v0/order_cycles_controller_spec.rb:17:101: C: [Corrected] Layout/LineLength: Line is too long. [106/100]
let!(:product2) { create(:product, name: "Parsnips", primary_taxon: taxon2, properties: [property2]) }
^^^^^^
spec/controllers/api/v0/order_cycles_controller_spec.rb:18:1: C: [Corrected] Layout/BlockAlignment: } at 18, 0 is not aligned with let!(:product1) { at 16, 4.
}
^
spec/controllers/api/v0/order_cycles_controller_spec.rb:19:85: C: [Corrected] Layout/BlockEndNewline: Expression at 19, 85 should be on its own line.
create(:product, name: "Parsnips", primary_taxon: taxon2, properties: [property2]) }
^
spec/controllers/api/v0/order_cycles_controller_spec.rb:20:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 1) spaces for indentation.
create(:product, name: "Parsnips", primary_taxon: taxon2, properties: [property2])
^
spec/controllers/api/v0/order_cycles_controller_spec.rb:20:3: C: [Corrected] Layout/IndentationWidth: Use 2 (not -2) spaces for indentation.
create(:product, name: "Parsnips", primary_taxon: taxon2, properties: [property2])
^^
spec/controllers/api/v0/order_cycles_controller_spec.rb:21:1: C: [Corrected] Layout/BlockAlignment: } at 21, 0 is not aligned with let!(:product2) { at 19, 4.
}
^
spec/controllers/spree/admin/orders_controller_spec.rb:232:101: C: [Corrected] Layout/LineLength: Line is too long. [117/100]
let!(:order_cycle){ create(:simple_order_cycle, distributors: [distributor], variants: [line_item.variant]) }
^^^^^^^^^^^^^^^^^
spec/controllers/spree/admin/orders_controller_spec.rb:233:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 1) spaces for indentation.
create(:simple_order_cycle, distributors: [distributor], variants: [line_item.variant])
^
spec/controllers/spree/admin/orders_controller_spec.rb:233:3: C: [Corrected] Layout/IndentationWidth: Use 2 (not -6) spaces for indentation.
create(:simple_order_cycle, distributors: [distributor], variants: [line_item.variant])
^^^^^^
spec/controllers/spree/admin/orders_controller_spec.rb:233:90: C: [Corrected] Layout/BlockEndNewline: Expression at 233, 90 should be on its own line.
create(:simple_order_cycle, distributors: [distributor], variants: [line_item.variant]) }
^
spec/controllers/spree/admin/orders_controller_spec.rb:234:1: C: [Corrected] Layout/BlockAlignment: } at 234, 0 is not aligned with let!(:order_cycle){ at 232, 8.
}
^
spec/controllers/spree/admin/orders_controller_spec.rb:252:101: C: Layout/LineLength: Line is too long. [109/100]
allow_any_instance_of(Spree::Order).to receive(:ensure_available_shipping_rates).and_return(true)
^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:93:88: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:order_with_totals_and_distribution, :completed, distributor: d,
^
spec/lib/reports/customers_report_spec.rb:93:101: C: [Corrected] Layout/LineLength: Line is too long. [125/100]
create(:order_with_totals_and_distribution, :completed, distributor: d, bill_address: a, shipping_method: sm)
^^^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:94:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
bill_address: a, shipping_method: sm)
^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:94:101: C: Layout/LineLength: Line is too long. [109/100]
bill_address: a, shipping_method: sm)
^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:96:101: C: [Corrected] Layout/LineLength: Line is too long. [125/100]
create(:order_with_totals_and_distribution, :completed, distributor: d, bill_address: a, shipping_method: sm)
^^^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:97:88: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:order_with_totals_and_distribution, :completed, distributor: d,
^
spec/lib/reports/customers_report_spec.rb:98:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
bill_address: a, shipping_method: sm)
^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:98:101: C: Layout/LineLength: Line is too long. [109/100]
bill_address: a, shipping_method: sm)
^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:113:101: C: Layout/LineLength: Line is too long. [118/100]
[d.address.address1, d.address.address2, d.address.city].join(" "),
^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:120:101: C: [Corrected] Layout/LineLength: Line is too long. [129/100]
create(:order_with_totals_and_distribution, :completed, distributor: d2, bill_address: a, shipping_method: sm2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:122:91: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:order_with_totals_and_distribution, :completed, distributor: d2,
^
spec/lib/reports/customers_report_spec.rb:123:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
bill_address: a, shipping_method: sm2)
^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:123:101: C: Layout/LineLength: Line is too long. [112/100]
bill_address: a, shipping_method: sm2)
^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:133:101: C: Layout/LineLength: Line is too long. [120/100]
[d.address.address1, d.address.address2, d.address.city].join(" "),
^^^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:139:101: C: Layout/LineLength: Line is too long. [123/100]
[d2.address.address1, d2.address.address2, d2.address.city].join(" "),
^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:145:101: C: [Corrected] Layout/LineLength: Line is too long. [128/100]
create(:order_with_totals_and_distribution, :completed, distributor: d, bill_address: a, shipping_method: sm2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:148:90: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:order_with_totals_and_distribution, :completed, distributor: d,
^
spec/lib/reports/customers_report_spec.rb:149:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
bill_address: a, shipping_method: sm2)
^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:149:101: C: Layout/LineLength: Line is too long. [112/100]
bill_address: a, shipping_method: sm2)
^^^^^^^^^^^^
spec/migrations/migrate_customer_names_spec.rb:16:101: C: Layout/LineLength: Line is too long. [122/100]
value_type: "boolean", key: "/enterprise/show_customer_names_to_suppliers/#{enterprise1.id}")
^^^^^^^^^^^^^^^^^^^^^^
spec/migrations/migrate_customer_names_spec.rb:18:101: C: Layout/LineLength: Line is too long. [122/100]
value_type: "boolean", key: "/enterprise/show_customer_names_to_suppliers/#{enterprise2.id}")
^^^^^^^^^^^^^^^^^^^^^^
spec/migrations/migrate_customer_names_spec.rb:20:101: C: Layout/LineLength: Line is too long. [122/100]
value_type: "boolean", key: "/enterprise/show_customer_names_to_suppliers/#{enterprise4.id}")
^^^^^^^^^^^^^^^^^^^^^^
spec/models/enterprise_spec.rb:521:101: C: [Corrected] Layout/LineLength: Line is too long. [111/100]
expect(Enterprise.supplying_variant_in([p1.variants.first, p2.variants.first])).to match_array [s1, s2]
^^^^^^^^^^^
spec/models/enterprise_spec.rb:522:1: C: [Corrected] Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
p2.variants.first])).to match_array [s1, s2]
^^^^^^^^^^^^^^^^^
spec/models/order_cycle_spec.rb:207:101: C: Layout/LineLength: Line is too long. [118/100]
expect(oc.variants).to match_array [p0.variants.first, p1.variants.first, p2.variants.first, p2_v, p1_v_visible,
^^^^^^^^^^^^^^^^^^
spec/models/order_cycle_spec.rb:220:101: C: Layout/LineLength: Line is too long. [111/100]
expect(oc.distributed_variants).to match_array [p1.variants.first, p2.variants.first, p2_v, p1_v_visible,
^^^^^^^^^^^
spec/models/product_importer_spec.rb:782:101: C: Layout/LineLength: Line is too long. [101/100]
csv << [" Oats ", "\nPorridge Oats\n", "\r#{enterprise2.name}\r", "\t#{enterprise.name}\t",
^
spec/models/spree/ability_spec.rb:340:69: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
[:admin, :index, :read, :edit, :update, :search, :destroy,
^
spec/models/spree/ability_spec.rb:340:101: C: [Corrected] Layout/LineLength: Line is too long. [101/100]
[:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p1.variants.first
^
spec/models/spree/ability_spec.rb:341:1: C: [Corrected] Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
:delete], for: p1.variants.first
^^^^^^^
spec/models/spree/ability_spec.rb:350:101: C: [Corrected] Layout/LineLength: Line is too long. [108/100]
[:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p_related.variants.first
^^^^^^^^
spec/models/spree/ability_spec.rb:351:69: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
[:admin, :index, :read, :edit, :update, :search, :destroy,
^
spec/models/spree/ability_spec.rb:352:1: C: [Corrected] Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
:delete], for: p_related.variants.first
^^^^^^^
spec/models/spree/ability_spec.rb:379:101: C: [Corrected] Layout/LineLength: Line is too long. [101/100]
[:admin, :index, :read, :create, :edit, :search, :update, :destroy], for: p2.variants.first
^
spec/models/spree/ability_spec.rb:381:68: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
[:admin, :index, :read, :create, :edit, :search, :update,
^
spec/models/spree/ability_spec.rb:382:1: C: [Corrected] Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
:destroy], for: p2.variants.first
^^^^^^^^
spec/models/spree/adjustment_spec.rb:339:101: C: Layout/LineLength: Line is too long. [106/100]
create(:tax_rate, included_in_price: true, calculator: ::Calculator::DefaultTax.new, zone: zone,
^^^^^^
spec/models/spree/adjustment_spec.rb:367:101: C: Layout/LineLength: Line is too long. [101/100]
calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0))
^
spec/models/spree/adjustment_spec.rb:428:101: C: Layout/LineLength: Line is too long. [105/100]
context "when enterprise fees inherit their tax_category from the product they are applied to" do
^^^^^
spec/models/spree/adjustment_spec.rb:443:101: C: Layout/LineLength: Line is too long. [101/100]
calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0))
^
spec/models/spree/line_item_spec.rb:208:101: C: Layout/LineLength: Line is too long. [107/100]
expect(LineItem.from_order_cycle(oc_order.order_cycle).first.id).to eq oc_order.line_items.first.id
^^^^^^^
spec/models/spree/line_item_spec.rb:342:101: C: Layout/LineLength: Line is too long. [102/100]
Spree::Variant.find(variant.id).on_hand
^^
spec/models/spree/product_spec.rb:409:74: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:simple_order_cycle, suppliers: [s], distributors: [d1],
^
spec/models/spree/product_spec.rb:409:101: C: [Corrected] Layout/LineLength: Line is too long. [104/100]
create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [p1.variants.first])
^^^^
spec/models/spree/product_spec.rb:410:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
variants: [p1.variants.first])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/spree/product_spec.rb:410:101: C: [Corrected] Layout/LineLength: Line is too long. [104/100]
create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.variants.first])
^^^^
spec/models/spree/product_spec.rb:411:74: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:simple_order_cycle, suppliers: [s], distributors: [d2],
^
spec/models/spree/product_spec.rb:412:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
variants: [p2.variants.first])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/spree/product_spec.rb:486:101: C: [Corrected] Layout/LineLength: Line is too long. [104/100]
create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [p1.variants.first])
^^^^
spec/models/spree/product_spec.rb:487:101: C: [Corrected] Layout/LineLength: Line is too long. [104/100]
create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.variants.first])
^^^^
spec/models/spree/product_spec.rb:488:74: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:simple_order_cycle, suppliers: [s], distributors: [d1],
^
spec/models/spree/product_spec.rb:489:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
variants: [p1.variants.first])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/spree/product_spec.rb:490:74: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:simple_order_cycle, suppliers: [s], distributors: [d2],
^
spec/models/spree/product_spec.rb:491:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
variants: [p2.variants.first])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/spree/product_spec.rb:495:101: C: [Corrected] Layout/LineLength: Line is too long. [102/100]
create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.variants.first])
^^
spec/models/spree/product_spec.rb:499:73: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:simple_order_cycle, suppliers: [s], distributors: [d],
^
spec/models/spree/product_spec.rb:500:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
variants: [p.variants.first])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/spree/variant_spec.rb:356:101: C: Layout/LineLength: Line is too long. [108/100]
it "lists any variants that are not listed as visible=false only for the relevant enterprise" do
^^^^^^^^
spec/models/spree/variant_spec.rb:479:101: C: Layout/LineLength: Line is too long. [108/100]
expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:fees_for).with(variant) {
^^^^^^^^
spec/models/spree/variant_spec.rb:494:101: C: Layout/LineLength: Line is too long. [116/100]
expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:fees_by_type_for).with(variant) {
^^^^^^^^^^^^^^^^
spec/models/spree/variant_spec.rb:704:101: C: Layout/LineLength: Line is too long. [115/100]
expect_any_instance_of(VariantUnits::OptionValueNamer).to receive(:name).exactly(1).times.and_call_original
^^^^^^^^^^^^^^^
spec/requests/api/orders_spec.rb:167:88: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:order_with_line_items, line_items_count: 1, bill_address_id: nil,
^
spec/requests/api/orders_spec.rb:167:101: C: [Corrected] Layout/LineLength: Line is too long. [109/100]
create(:order_with_line_items, line_items_count: 1, bill_address_id: nil, ship_address_id: nil)
^^^^^^^^^
spec/requests/api/orders_spec.rb:168:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
ship_address_id: nil)
^^^^^^^^^^^^^^^^^^^^
spec/services/products_renderer_spec.rb:91:101: C: Layout/LineLength: Line is too long. [101/100]
{ q: { with_properties: [property_organic.id] } })
^
spec/services/products_renderer_spec.rb:100:101: C: Layout/LineLength: Line is too long. [101/100]
{ q: { with_properties: [property_organic.id] } })
^
spec/services/products_renderer_spec.rb:118:101: C: Layout/LineLength: Line is too long. [101/100]
{ q: { with_properties: [property_organic.id] } })
^
spec/support/request/web_helper.rb:96:84: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
tomselect_wrapper.find(:css, '.ts-dropdown.multi .ts-dropdown-content .option',
^
spec/support/request/web_helper.rb:96:101: C: [Corrected] Layout/LineLength: Line is too long. [102/100]
tomselect_wrapper.find(:css, '.ts-dropdown.multi .ts-dropdown-content .option', text: value).click
^^
spec/support/request/web_helper.rb:97:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
text: value).click
^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:29:101: C: [Corrected] Layout/LineLength: Line is too long. [197/100]
let!(:tax_rate2) { create(:tax_rate, name: "TVA 20%", amount: 0.2, zone: default_tax_zone, included_in_price: true, tax_category: tax_category_included, calculator: Calculator::DefaultTax.new ) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:30:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 1) spaces for indentation.
create(:tax_rate, name: "TVA 20%", amount: 0.2, zone: default_tax_zone, included_in_price: true,
^
spec/system/admin/adjustments_spec.rb:30:3: C: [Corrected] Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
create(:tax_rate, name: "TVA 20%", amount: 0.2, zone: default_tax_zone, included_in_price: true,
spec/system/admin/adjustments_spec.rb:30:98: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:tax_rate, name: "TVA 20%", amount: 0.2, zone: default_tax_zone, included_in_price: true,
^
spec/system/admin/adjustments_spec.rb:30:101: C: [Corrected] Layout/LineLength: Line is too long. [177/100]
create(:tax_rate, name: "TVA 20%", amount: 0.2, zone: default_tax_zone, included_in_price: true, tax_category: tax_category_included, calculator: Calculator::DefaultTax.new ) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:30:177: C: [Corrected] Layout/BlockEndNewline: Expression at 30, 177 should be on its own line.
create(:tax_rate, name: "TVA 20%", amount: 0.2, zone: default_tax_zone, included_in_price: true, tax_category: tax_category_included, calculator: Calculator::DefaultTax.new ) }
^
spec/system/admin/adjustments_spec.rb:31:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
tax_category: tax_category_included, calculator: Calculator::DefaultTax.new )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:32:1: C: [Corrected] Layout/BlockAlignment: } at 32, 0 is not aligned with let!(:tax_rate2) { at 29, 2.
}
^
spec/system/admin/adjustments_spec.rb:41:101: C: Layout/LineLength: Line is too long. [134/100]
shared_examples "when the enable_localized_number preference" do |adjustment_label, adjustment_amount, tax_category, tax, tax_total|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:67:101: C: [Corrected] Layout/LineLength: Line is too long. [117/100]
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "TVA 20%", "$0.33", "$-1.67"
^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:68:100: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "TVA 20%",
^
spec/system/admin/adjustments_spec.rb:69:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"$0.33", "$-1.67"
^^^^^^^
spec/system/admin/adjustments_spec.rb:71:101: C: [Corrected] Layout/LineLength: Line is too long. [120/100]
it_behaves_like "when the enable_localized_number preference", "Late fee", "100", "TVA 20%", "$-16.67", "$83.33"
^^^^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:73:90: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Late fee", "100",
^
spec/system/admin/adjustments_spec.rb:74:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"TVA 20%", "$-16.67", "$83.33"
^^^^^^^^^
spec/system/admin/adjustments_spec.rb:77:101: C: [Corrected] Layout/LineLength: Line is too long. [113/100]
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "GST", "$10.00", "$8.00"
^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:80:96: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "GST",
^
spec/system/admin/adjustments_spec.rb:81:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"$10.00", "$8.00"
^^^^^^^^
spec/system/admin/adjustments_spec.rb:81:101: C: [Corrected] Layout/LineLength: Line is too long. [113/100]
it_behaves_like "when the enable_localized_number preference", "Late fee", "110", "GST", "$10.00", "$120"
^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:85:97: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Late fee", "110", "GST",
^
spec/system/admin/adjustments_spec.rb:86:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"$10.00", "$120"
^^^^^^^^
spec/system/admin/adjustments_spec.rb:93:101: C: [Corrected] Layout/LineLength: Line is too long. [117/100]
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "TVA 20%", "$0.33", "$-1.67"
^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:97:101: C: [Corrected] Layout/LineLength: Line is too long. [120/100]
it_behaves_like "when the enable_localized_number preference", "Late fee", "100", "TVA 20%", "$-16.67", "$83.33"
^^^^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:98:100: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "TVA 20%",
^
spec/system/admin/adjustments_spec.rb:99:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"$0.33", "$-1.67"
^^^^^^^
spec/system/admin/adjustments_spec.rb:103:90: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Late fee", "100",
^
spec/system/admin/adjustments_spec.rb:103:101: C: [Corrected] Layout/LineLength: Line is too long. [113/100]
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "GST", "$10.00", "$8.00"
^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:104:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"TVA 20%", "$-16.67", "$83.33"
^^^^^^^^^
spec/system/admin/adjustments_spec.rb:107:101: C: [Corrected] Layout/LineLength: Line is too long. [113/100]
it_behaves_like "when the enable_localized_number preference", "Late fee", "110", "GST", "$10.00", "$120"
^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:110:96: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "GST",
^
spec/system/admin/adjustments_spec.rb:111:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"$10.00", "$8.00"
^^^^^^^^
spec/system/admin/adjustments_spec.rb:115:97: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Late fee", "110", "GST",
^
spec/system/admin/adjustments_spec.rb:116:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"$10.00", "$120"
^^^^^^^^
spec/system/admin/bulk_order_management_spec.rb:268:101: C: Layout/LineLength: Line is too long. [105/100]
text: "#{o1.bill_address.last_name}, #{o1.bill_address.first_name}"
^^^^^
spec/system/admin/bulk_order_management_spec.rb:1036:101: C: Layout/LineLength: Line is too long. [147/100]
expect(page).to have_content "This operation will result in one or more empty orders, which will be cancelled. Do you wish to proceed?"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/bulk_order_management_spec.rb:1060:101: C: Layout/LineLength: Line is too long. [138/100]
it "the user can confirm + wants to send email confirmation : line item is then deleted, order is canceled and email is sent" do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/bulk_order_management_spec.rb:1072:101: C: Layout/LineLength: Line is too long. [134/100]
it "the user can confirm + uncheck the restock option: line item is then deleted and order is canceled without retocking" do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/customers_spec.rb:40:101: C: Layout/LineLength: Line is too long. [126/100]
managed_distributor2.name], without_options: [unmanaged_distributor.name]
^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_cycles/simple_spec.rb:346:101: C: Layout/LineLength: Line is too long. [101/100]
with_options: [schedule_of_other_managed_distributor.name]
^
spec/system/admin/order_cycles/simple_spec.rb:623:101: C: Layout/LineLength: Line is too long. [121/100]
value: Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0).strftime("%F %T %z"), visible: false
^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_cycles/simple_spec.rb:625:101: C: Layout/LineLength: Line is too long. [120/100]
value: Time.zone.local(2040, 10, 24, 17, 0o0, 0o0).strftime("%F %T %z"), visible: false
^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_cycles/simple_spec.rb:733:101: C: Layout/LineLength: Line is too long. [121/100]
value: Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0).strftime("%F %T %z"), visible: false
^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_cycles/simple_spec.rb:735:101: C: Layout/LineLength: Line is too long. [120/100]
value: Time.zone.local(2040, 10, 24, 17, 0o0, 0o0).strftime("%F %T %z"), visible: false
^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_spec.rb:598:101: C: [Corrected] Layout/LineLength: Line is too long. [101/100]
expect(page).to have_link "Resend Confirmation", href: spree.resend_admin_order_path(order)
^
spec/system/admin/order_spec.rb:599:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
href: spree.resend_admin_order_path(order)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_spec.rb:616:101: C: [Corrected] Layout/LineLength: Line is too long. [105/100]
expect(page).to have_link "Cancel Order", href: spree.fire_admin_order_path(order, e: 'cancel')
^^^^^
spec/system/admin/order_spec.rb:618:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
href: spree.fire_admin_order_path(order, e: 'cancel')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/orders_spec.rb:259:101: C: Layout/LineLength: Line is too long. [109/100]
distributor: distributor2, bill_address_id: nil, ship_address_id: nil)
^^^^^^^^^
spec/system/admin/product_import_spec.rb:573:101: C: Layout/LineLength: Line is too long. [106/100]
expect(page).to have_content "line 4: Cabbage - On_hand incorrect value - On_demand incorrect value"
^^^^^^
spec/system/admin/product_import_spec.rb:574:101: C: Layout/LineLength: Line is too long. [108/100]
expect(page).to have_content "line 5: Aubergine - On_hand incorrect value - On_demand incorrect value"
^^^^^^^^
spec/system/admin/product_import_spec.rb:583:101: C: Layout/LineLength: Line is too long. [102/100]
csv << ["name", "producer", "category", "on_hand", "price", "on_demand", "units", "unit_type",
^^
spec/system/admin/product_import_spec.rb:585:101: C: Layout/LineLength: Line is too long. [106/100]
csv << ["Beans", "User Enterprise", "Vegetables", "invalid", "3.50", "1", "0.5", "g", "Small Bag",
^^^^^^
spec/system/admin/product_import_spec.rb:587:101: C: Layout/LineLength: Line is too long. [103/100]
csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6", "invalid", "5", "kg", "Big Bag",
^^^
spec/system/admin/product_import_spec.rb:589:101: C: Layout/LineLength: Line is too long. [106/100]
csv << ["Cabbage", "User Enterprise", "Vegetables", "invalid", "1.5", "invalid", "1", "kg", "Bag",
^^^^^^
spec/system/admin/product_import_spec.rb:591:101: C: Layout/LineLength: Line is too long. [102/100]
csv << ["Aubergine", "User Enterprise", "Vegetables", nil, "1.5", "invalid", "1", "kg", "Bag",
^^
spec/system/admin/product_import_spec.rb:607:101: C: Layout/LineLength: Line is too long. [114/100]
expect(page).to have_content "line 4: Cabbage ( Bag ) - On_hand incorrect value - On_demand incorrect value"
^^^^^^^^^^^^^^
spec/system/admin/product_import_spec.rb:608:101: C: Layout/LineLength: Line is too long. [116/100]
expect(page).to have_content "line 5: Aubergine ( Bag ) - On_hand incorrect value - On_demand incorrect value"
^^^^^^^^^^^^^^^^
spec/system/admin/product_import_spec.rb:617:101: C: Layout/LineLength: Line is too long. [102/100]
csv << ["name", "producer", "category", "on_hand", "price", "on_demand", "units", "unit_type",
^^
spec/system/admin/product_import_spec.rb:619:101: C: Layout/LineLength: Line is too long. [101/100]
csv << ["Beans", "User Enterprise", "Vegetables", "-1", "3.50", "1", "500", "g", "Small Bag",
^
spec/system/admin/product_import_spec.rb:641:101: C: Layout/LineLength: Line is too long. [114/100]
expect(page).to have_content "line 4: Cabbage ( Bag ) - On_hand incorrect value - On_demand incorrect value"
^^^^^^^^^^^^^^
spec/system/admin/product_import_spec.rb:642:101: C: Layout/LineLength: Line is too long. [116/100]
expect(page).to have_content "line 5: Aubergine ( Bag ) - On_hand incorrect value - On_demand incorrect value"
^^^^^^^^^^^^^^^^
spec/system/consumer/shopping/cart_spec.rb:147:101: C: Layout/LineLength: Line is too long. [101/100]
preferred_unit_from_list: "kg"),
^
spec/system/consumer/shopping/products_spec.rb:98:101: C: Layout/LineLength: Line is too long. [113/100]
"<script>alert('Dangerous!');</script>", truncate: false)
^^^^^^^^^^^^^
1478 files inspected, 173 offenses detected, 106 offenses corrected
1009 lines
36 KiB
Ruby
1009 lines
36 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "system_helper"
|
|
|
|
describe '
|
|
As an administrator
|
|
I want to create and edit orders
|
|
' do
|
|
include WebHelper
|
|
include AuthenticationHelper
|
|
|
|
let(:user) { create(:user) }
|
|
let(:product) { create(:simple_product) }
|
|
let(:distributor) { create(:distributor_enterprise, owner: user, charges_sales_tax: true) }
|
|
let(:order_cycle) do
|
|
create(:simple_order_cycle, name: 'One', distributors: [distributor],
|
|
variants: [product.variants.first])
|
|
end
|
|
|
|
let(:order) do
|
|
create(:order_with_totals_and_distribution, user: user, distributor: distributor,
|
|
order_cycle: order_cycle, state: 'complete',
|
|
payment_state: 'balance_due')
|
|
end
|
|
let(:customer) { order.customer }
|
|
|
|
before do
|
|
# ensure order has a payment to capture
|
|
order.finalize!
|
|
|
|
create :check_payment, order: order, amount: order.total
|
|
end
|
|
|
|
def new_order_with_distribution(distributor, order_cycle)
|
|
visit spree.new_admin_order_path
|
|
expect(page).to have_selector('#s2id_order_distributor_id')
|
|
select2_select distributor.name, from: 'order_distributor_id'
|
|
select2_select order_cycle.name, from: 'order_order_cycle_id'
|
|
click_button 'Next'
|
|
end
|
|
|
|
it "creating an order with distributor and order cycle" do
|
|
distributor_disabled = create(:distributor_enterprise)
|
|
create(:simple_order_cycle, name: 'Two')
|
|
|
|
login_as_admin
|
|
visit spree.admin_orders_path
|
|
click_link 'New Order'
|
|
|
|
# Distributors without an order cycle should be shown as disabled
|
|
open_select2('#s2id_order_distributor_id')
|
|
expect(page).to have_selector "ul.select2-results li.select2-result.select2-disabled",
|
|
text: distributor_disabled.name
|
|
close_select2
|
|
|
|
# Order cycle selector should be disabled
|
|
expect(page).to have_selector "#s2id_order_order_cycle_id.select2-container-disabled"
|
|
|
|
# The distributor selector should limit the order cycle selection to those for that distributor
|
|
select2_select distributor.name, from: 'order_distributor_id'
|
|
expect(page).to have_select2 'order_order_cycle_id', options: ['One (open)']
|
|
select2_select order_cycle.name, from: 'order_order_cycle_id'
|
|
click_button 'Next'
|
|
|
|
expect(page).not_to have_selector '.flash.error'
|
|
expect(page).not_to have_content "Line items can't be blank"
|
|
|
|
expect(page).to have_selector 'h1', text: 'Customer Details'
|
|
|
|
order = Spree::Order.last
|
|
expect(order.distributor).to eq(distributor)
|
|
expect(order.order_cycle).to eq(order_cycle)
|
|
expect(order.line_items.count).to be_zero
|
|
|
|
click_link "Order Details"
|
|
expect(page).to have_content 'ADD PRODUCT'
|
|
select2_select product.name, from: 'add_variant_id', search: true
|
|
find('button.add_variant').click
|
|
# Wait for JS
|
|
page.has_selector?("table.index tbody tr")
|
|
expect(page).to have_selector 'td', text: product.name
|
|
|
|
expect(order.reload.line_items.count).to be_positive
|
|
end
|
|
|
|
context "can't create an order without selecting a distributor nor an order cycle" do
|
|
before do
|
|
login_as_admin
|
|
visit spree.admin_orders_path
|
|
click_link 'New Order'
|
|
end
|
|
|
|
it 'shows error when distributor is not selected' do
|
|
click_button 'Next'
|
|
|
|
expect(page).to have_content "Order cycle can't be blank"
|
|
expect(page).to have_content "Distributor can't be blank"
|
|
end
|
|
|
|
it 'shows error when order cycle is not selected' do
|
|
select2_select distributor.name, from: 'order_distributor_id'
|
|
click_button 'Next'
|
|
|
|
expect(page).to have_content "Order cycle can't be blank"
|
|
end
|
|
|
|
it "doesn't show links to other steps" do
|
|
expect(page).not_to have_content "CUSTOMER DETAILS"
|
|
expect(page).not_to have_content "ORDER DETAILS"
|
|
expect(page).not_to have_content "PAYMENTS"
|
|
expect(page).not_to have_content "ADJUSTMENTS"
|
|
end
|
|
end
|
|
|
|
context "when creating an order with a customer-only" do
|
|
let!(:order) { create(:order, distributor: distributor, order_cycle: order_cycle) }
|
|
let(:customer2) { create(:customer, enterprise: distributor) }
|
|
let(:customer3) { create(:customer, enterprise: distributor) }
|
|
|
|
before do
|
|
login_as_admin
|
|
visit spree.admin_order_customer_path(order)
|
|
end
|
|
|
|
it "sets the customer on the order" do
|
|
expect(order.customer_id).to be_nil
|
|
|
|
tomselect_search_and_select customer2.email, from: 'customer_search_override'
|
|
check 'order_use_billing'
|
|
click_button 'Update'
|
|
expect(page).to have_content 'Customer Details updated'
|
|
|
|
expect(order.reload.customer).to eq customer2
|
|
end
|
|
|
|
context "when changing the attached customer" do
|
|
before do
|
|
order.update(
|
|
customer: customer2,
|
|
email: customer2.email,
|
|
ship_address: customer2.ship_address,
|
|
bill_address: customer2.bill_address
|
|
)
|
|
visit spree.admin_order_customer_path(order)
|
|
end
|
|
|
|
it "should update the order customer (not only its details)" do
|
|
expect(page).to have_field 'order_email', with: customer2.email
|
|
tomselect_search_and_select customer3.email, from: 'customer_search_override'
|
|
check 'order_use_billing'
|
|
|
|
expect(page).to have_field 'order_email', with: customer3.email
|
|
|
|
expect do
|
|
click_button 'Update'
|
|
expect(page).to have_content 'Customer Details updated'
|
|
end.to change { order.reload.customer }.from(customer2).to(customer3)
|
|
end
|
|
end
|
|
end
|
|
|
|
it "can add a product to an existing order" do
|
|
login_as_admin
|
|
visit spree.edit_admin_order_path(order)
|
|
|
|
select2_select product.name, from: 'add_variant_id', search: true
|
|
find('button.add_variant').click
|
|
# Wait for JS
|
|
sleep(1)
|
|
page.has_selector?("table.index tbody tr td")
|
|
expect(page).to have_selector 'td', text: product.name
|
|
expect(order.line_items.reload.map(&:product)).to include product
|
|
end
|
|
|
|
shared_examples_for "Cancelling the order" do
|
|
it "shows a modal about order cancellation" do
|
|
expect(page).to have_content "This will cancel the current order."
|
|
expect(page).to have_checked_field "Send a cancellation email to the customer"
|
|
expect(page).to have_checked_field "Restock Items: return all items to stock"
|
|
end
|
|
|
|
it "that the user can close and then nothing changes" do
|
|
within(".modal") do
|
|
expect do
|
|
click_on("Cancel")
|
|
end.not_to change { order.reload.state }
|
|
end
|
|
end
|
|
|
|
context "that the user can confirm" do
|
|
let(:shipment) { order.shipments.first }
|
|
|
|
it "and by default an Email is sent and the items are restocked" do
|
|
expect_any_instance_of(Spree::StockLocation).to receive(:restock).at_least(1).times
|
|
expect do
|
|
within(".modal") do
|
|
click_on("OK")
|
|
end
|
|
expect(page).to have_content "Cannot add item to canceled order"
|
|
expect(order.reload.state).to eq("canceled")
|
|
end.to have_enqueued_mail(Spree::OrderMailer, :cancel_email)
|
|
end
|
|
|
|
it "and then the order is cancelled and email is not sent when unchecked" do
|
|
expect_any_instance_of(Spree::StockLocation).to receive(:restock).at_least(1).times
|
|
expect do
|
|
within(".modal") do
|
|
uncheck("send_cancellation_email")
|
|
click_on("OK")
|
|
end
|
|
expect(page).to have_content "Cannot add item to canceled order"
|
|
expect(order.reload.state).to eq("canceled")
|
|
end.to_not have_enqueued_mail(Spree::OrderMailer, :cancel_email)
|
|
end
|
|
|
|
it "and the items are not restocked when the user uncheck the checkbox to restock items" do
|
|
expect_any_instance_of(Spree::StockLocation).not_to receive(:restock)
|
|
expect do
|
|
within(".modal") do
|
|
uncheck("restock_items")
|
|
click_on("OK")
|
|
end
|
|
expect(page).to have_content "Cannot add item to canceled order"
|
|
expect(order.reload.state).to eq("canceled")
|
|
end.to have_enqueued_mail(Spree::OrderMailer, :cancel_email)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "cancelling an order" do
|
|
let(:line_item) { create(:line_item) }
|
|
|
|
before do
|
|
order.line_items << line_item
|
|
login_as_admin
|
|
visit spree.edit_admin_order_path(order)
|
|
end
|
|
|
|
context "when using the cancel button" do
|
|
before do
|
|
find("#cancel_order_form").click
|
|
end
|
|
|
|
it_should_behave_like "Cancelling the order"
|
|
end
|
|
|
|
context "when using the cancel option in the dropdown" do
|
|
before do
|
|
find("#links-dropdown .ofn-drop-down").click
|
|
find('a[href$="cancel"]').click
|
|
end
|
|
|
|
it_should_behave_like "Cancelling the order"
|
|
end
|
|
end
|
|
|
|
it "displays error when incorrect distribution for products is chosen" do
|
|
d = create(:distributor_enterprise)
|
|
oc = create(:simple_order_cycle, distributors: [d])
|
|
|
|
# Move the order back to the cart state
|
|
order.state = 'cart'
|
|
order.completed_at = nil
|
|
# A nil user keeps the order in the cart state
|
|
# Even if the edit page tries to automatically progress the order workflow
|
|
order.user = nil
|
|
order.save
|
|
|
|
login_as_admin
|
|
visit spree.edit_admin_order_path(order)
|
|
|
|
expect(page).to have_select2 "order_distributor_id", with_options: [d.name]
|
|
select2_select d.name, from: 'order_distributor_id'
|
|
select2_select oc.name, from: 'order_order_cycle_id'
|
|
|
|
click_button 'Update And Recalculate Fees'
|
|
expect(page).to have_content "Distributor or order cycle " \
|
|
"cannot supply the products in your cart"
|
|
end
|
|
|
|
it "can't add products to an order outside the order's hub and order cycle" do
|
|
product = create(:simple_product)
|
|
|
|
login_as_admin
|
|
visit spree.edit_admin_order_path(order)
|
|
|
|
expect(page).not_to have_select2 "add_variant_id", with_options: [product.name]
|
|
end
|
|
|
|
context "deleting item of an order" do
|
|
context "when there a more than one items in the order" do
|
|
let(:line_item) { create(:line_item) }
|
|
|
|
before do
|
|
order.line_items << line_item
|
|
login_as_admin
|
|
visit spree.edit_admin_order_path(order)
|
|
find("a.delete-item").click
|
|
expect(page).to have_content "Are you sure?"
|
|
end
|
|
|
|
it "show a modal 'Are you sure?' that the user can close and then nothing change" do
|
|
within(".modal") do
|
|
expect do
|
|
click_on("Cancel")
|
|
expect(page).not_to have_content "Are you sure?"
|
|
end.not_to change { order.line_items.length }
|
|
end
|
|
end
|
|
|
|
it "show a modal 'Are you sure?' that the user confirm and then the item is deleted" do
|
|
expect(order.line_items.length).to eq(2)
|
|
within(".modal") do
|
|
expect do
|
|
click_on("OK")
|
|
end.to change { order.reload.line_items.length }.by(-1)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when it is the last item of an order" do
|
|
before do
|
|
# specify that order has only one line item
|
|
order.line_items = [order.line_items.first]
|
|
login_as_admin
|
|
visit spree.edit_admin_order_path(order)
|
|
find("a.delete-item").click
|
|
end
|
|
|
|
it_should_behave_like "Cancelling the order"
|
|
end
|
|
end
|
|
|
|
it "can't add more items than are available" do
|
|
# Move the order back to the cart state
|
|
order.state = 'cart'
|
|
order.completed_at = nil
|
|
|
|
login_as_admin
|
|
visit spree.edit_admin_order_path(order)
|
|
|
|
quantity = order.line_items.first.quantity
|
|
max_quantity = 0
|
|
total = order.display_total
|
|
|
|
within("tr.stock-item", text: order.products.first.name) do
|
|
find("a.edit-item").click
|
|
expect(page).to have_input(:quantity)
|
|
max_quantity = find("input[name='quantity']")["max"].to_i
|
|
fill_in(:quantity, with: max_quantity + 1)
|
|
find("a.save-item").click
|
|
end
|
|
click_button("OK")
|
|
|
|
expect(page).to_not have_content "Loading..."
|
|
within("tr.stock-item", text: order.products.first.name) do
|
|
expect(page).to have_text(max_quantity.to_s)
|
|
end
|
|
expect(order.reload.line_items.first.quantity).to eq(max_quantity)
|
|
end
|
|
|
|
it "there are infinite items available (variant is on demand)" do
|
|
# Move the order back to the cart state
|
|
order.state = 'cart'
|
|
order.completed_at = nil
|
|
order.line_items.first.variant.update_attribute(:on_demand, true)
|
|
|
|
login_as_admin
|
|
visit spree.edit_admin_order_path(order)
|
|
|
|
within("tr.stock-item", text: order.products.first.name) do
|
|
find("a.edit-item").click
|
|
expect(page).to have_input(:quantity)
|
|
fill_in(:quantity, with: 1000)
|
|
find("a.save-item").click
|
|
end
|
|
|
|
within("tr.stock-item", text: order.products.first.name) do
|
|
expect(page).to have_text("1000")
|
|
end
|
|
expect(order.reload.line_items.first.quantity).to eq(1000)
|
|
end
|
|
|
|
# Regression test for #7337
|
|
context "creating a new order with a variant override" do
|
|
let!(:override) {
|
|
create(:variant_override, hub: distributor, variant: product.variants.first,
|
|
count_on_hand: 100)
|
|
}
|
|
|
|
before do
|
|
product.variants.first.update(on_demand: false, on_hand: 0)
|
|
|
|
login_as user
|
|
new_order_with_distribution(distributor, order_cycle)
|
|
expect(page).to have_selector 'h1', text: "Customer Details"
|
|
end
|
|
|
|
it "creates order and shipment successfully and allows proceeding to payment" do
|
|
fill_in "order_email", with: "test@test.com"
|
|
|
|
expect(page).to have_selector('#order_ship_address_attributes_firstname')
|
|
check "order_use_billing"
|
|
expect(page).not_to have_selector('#order_ship_address_attributes_firstname')
|
|
|
|
fill_in "order_bill_address_attributes_firstname", with: "Clark"
|
|
fill_in "order_bill_address_attributes_lastname", with: "Kent"
|
|
fill_in "order_bill_address_attributes_address1", with: "Smallville"
|
|
fill_in "order_bill_address_attributes_city", with: "Kansas"
|
|
fill_in "order_bill_address_attributes_zipcode", with: "SP1 M11"
|
|
|
|
select "Australia", from: "order_bill_address_attributes_country_id"
|
|
select "Victoria", from: "order_bill_address_attributes_state_id"
|
|
fill_in "order_bill_address_attributes_phone", with: "111 1111 1111"
|
|
|
|
click_button "Update"
|
|
|
|
expect(page).to have_content "Customer Details updated"
|
|
click_link "Order Details"
|
|
|
|
expect(page).to have_content 'Add Product'.upcase
|
|
select2_select product.name, from: 'add_variant_id', search: true
|
|
|
|
within("table.stock-levels") do
|
|
expect(page).to have_selector("#stock_item_quantity")
|
|
fill_in "stock_item_quantity", with: 50
|
|
find("button.add_variant").click
|
|
end
|
|
|
|
expect(page).to_not have_selector("table.stock-levels")
|
|
expect(page).to have_selector("table.stock-contents")
|
|
|
|
within("tr.stock-item") do
|
|
expect(page).to have_text("50")
|
|
end
|
|
|
|
order = Spree::Order.last
|
|
expect(order.line_items.first.quantity).to eq(50)
|
|
expect(order.shipments.count).to eq(1)
|
|
|
|
new_customer = Customer.last
|
|
expect(new_customer.full_name).to eq('Clark Kent')
|
|
expect(new_customer.bill_address.address1).to eq('Smallville')
|
|
expect(new_customer.bill_address.city).to eq('Kansas')
|
|
expect(new_customer.bill_address.zipcode).to eq('SP1 M11')
|
|
expect(new_customer.bill_address.phone).to eq('111 1111 1111')
|
|
expect(new_customer.bill_address).to eq(new_customer.ship_address)
|
|
|
|
click_button "Update And Recalculate Fees"
|
|
|
|
click_link "Payments"
|
|
|
|
expect(page).to have_content "New Payment"
|
|
end
|
|
end
|
|
|
|
it "can't change distributor or order cycle once order has been finalized" do
|
|
login_as_admin
|
|
visit spree.edit_admin_order_path(order)
|
|
|
|
expect(page).not_to have_select2 'order_distributor_id'
|
|
expect(page).not_to have_select2 'order_order_cycle_id'
|
|
|
|
expect(page).to have_selector 'p', text: "Distributor: #{order.distributor.name}"
|
|
expect(page).to have_selector 'p', text: "Order cycle: #{order.order_cycle.name}"
|
|
end
|
|
|
|
it "filling customer details" do
|
|
# Given a customer with an order, which includes their shipping and billing address
|
|
|
|
# We change the 1st order's address details, this way
|
|
# we validate that the original details (stored in customer) are picked up in the 2nd order
|
|
order.ship_address = create(:address, lastname: 'Ship')
|
|
order.bill_address = create(:address, lastname: 'Bill')
|
|
order.save!
|
|
|
|
# We set the existing ship method to delivery, this ship method will be used in the 2nd order
|
|
# Otherwise order_updater.shipping_address_from_distributor will set
|
|
# the 2nd order address to the distributor address
|
|
order.shipping_method.update_attribute :require_ship_address, true
|
|
|
|
# When I create a new order
|
|
login_as user
|
|
new_order_with_distribution(distributor, order_cycle)
|
|
|
|
# The customer selection partial should be visible
|
|
expect(page).to have_selector '#select-customer'
|
|
|
|
# And I select that customer's email address and save the order
|
|
tomselect_search_and_select customer.email, from: 'customer_search_override'
|
|
expect(page).to have_field "order_email", with: customer.email
|
|
click_button 'Update'
|
|
|
|
# Then their addresses should be associated with the order
|
|
order = Spree::Order.last
|
|
expect(order.ship_address.lastname).to eq customer.ship_address.lastname
|
|
expect(order.bill_address.lastname).to eq customer.bill_address.lastname
|
|
expect(order.ship_address.zipcode).to eq customer.ship_address.zipcode
|
|
expect(order.bill_address.zipcode).to eq customer.bill_address.zipcode
|
|
expect(order.ship_address.city).to eq customer.ship_address.city
|
|
expect(order.bill_address.city).to eq customer.bill_address.city
|
|
|
|
click_link "Order Details"
|
|
|
|
select2_select product.name, from: 'add_variant_id', search: true
|
|
find('button.add_variant').click
|
|
page.has_selector? "table.index tbody tr" # Wait for JS
|
|
end
|
|
|
|
context "as an enterprise manager" do
|
|
let(:coordinator1) { create(:distributor_enterprise) }
|
|
let(:coordinator2) { create(:distributor_enterprise) }
|
|
let!(:order_cycle1) { create(:order_cycle, coordinator: coordinator1) }
|
|
let!(:order_cycle2) { create(:simple_order_cycle, coordinator: coordinator2) }
|
|
let!(:supplier1) { order_cycle1.suppliers.first }
|
|
let!(:supplier2) { order_cycle1.suppliers.last }
|
|
let!(:distributor1) { order_cycle1.distributors.first }
|
|
let!(:distributor2) do
|
|
order_cycle1.distributors.reject{ |d| d == distributor1 }.last # ensure d1 != d2
|
|
end
|
|
let(:product) { order_cycle1.products.first }
|
|
|
|
before(:each) do
|
|
@enterprise_user = create(:user)
|
|
@enterprise_user.enterprise_roles.build(enterprise: supplier1).save
|
|
@enterprise_user.enterprise_roles.build(enterprise: coordinator1).save
|
|
@enterprise_user.enterprise_roles.build(enterprise: distributor1).save
|
|
|
|
login_as @enterprise_user
|
|
end
|
|
|
|
describe "viewing the edit page" do
|
|
let!(:shipping_method_for_distributor1) do
|
|
create(:shipping_method_with, :flat_rate, name: "Normal", amount: 12,
|
|
distributors: [distributor1])
|
|
end
|
|
let!(:order) do
|
|
create(:order_with_taxes, distributor: distributor1, ship_address: create(:address),
|
|
product_price: 110, tax_rate_amount: 0.1, included_in_price: true,
|
|
tax_rate_name: "Tax 1").tap do |order|
|
|
order.create_tax_charge!
|
|
order.update_shipping_fees!
|
|
end
|
|
end
|
|
|
|
before do
|
|
distributor1.update_attribute(:abn, '12345678')
|
|
|
|
visit spree.edit_admin_order_path(order)
|
|
end
|
|
|
|
it "verifying page contents" do
|
|
# shows a list of line_items
|
|
within('table.index tbody', match: :first) do
|
|
order.line_items.each do |item|
|
|
expect(page).to have_selector "td", match: :first, text: item.full_name
|
|
expect(page).to have_selector "td.item-price", text: item.single_display_amount
|
|
expect(page).to have_selector "input#quantity[value='#{item.quantity}']", visible: false
|
|
expect(page).to have_selector "td.item-total", text: item.display_amount
|
|
end
|
|
end
|
|
|
|
# shows the order items total
|
|
within('fieldset#order-total') do
|
|
expect(page).to have_selector "span.order-total", text: order.display_item_total
|
|
end
|
|
|
|
# shows the order non-tax adjustments
|
|
order.adjustments.eligible.each do |adjustment|
|
|
expect(page).to have_selector "td", match: :first, text: adjustment.label
|
|
expect(page).to have_selector "td.total", text: adjustment.display_amount
|
|
end
|
|
|
|
# shows the order total
|
|
expect(page).to have_selector "fieldset#order-total", text: order.display_total
|
|
|
|
# shows the order tax adjustments
|
|
within('fieldset', text: 'Line Item Adjustments'.upcase) do
|
|
expect(page).to have_selector "td", match: :first, text: "Tax 1"
|
|
expect(page).to have_selector "td.total", text: Spree::Money.new(10)
|
|
end
|
|
|
|
# shows the dropdown menu" do
|
|
find("#links-dropdown .ofn-drop-down").click
|
|
within "#links-dropdown" do
|
|
expect(page).to have_link "Resend Confirmation",
|
|
href: spree.resend_admin_order_path(order)
|
|
end
|
|
end
|
|
|
|
context "Resending confirmation email" do
|
|
before do
|
|
visit spree.edit_admin_order_path(order)
|
|
find("#links-dropdown .ofn-drop-down").click
|
|
end
|
|
|
|
it "shows the link" do
|
|
expect(page).to have_link "Resend Confirmation",
|
|
href: spree.resend_admin_order_path(order)
|
|
end
|
|
|
|
it "resends the confirmation email" do
|
|
accept_alert "Are you sure you want to resend the order confirmation email?" do
|
|
click_link "Resend Confirmation"
|
|
end
|
|
expect(page).to have_content "Order email has been resent"
|
|
end
|
|
end
|
|
|
|
context "Canceling an order" do
|
|
before do
|
|
visit spree.edit_admin_order_path(order)
|
|
find("#links-dropdown .ofn-drop-down").click
|
|
end
|
|
|
|
it "shows the link" do
|
|
expect(page).to have_link "Cancel Order",
|
|
href: spree.fire_admin_order_path(order, e: 'cancel')
|
|
end
|
|
|
|
it "cancels the order" do
|
|
within ".ofn-drop-down .menu" do
|
|
expect(page).to have_selector("span", text: "Cancel Order")
|
|
page.find("span", text: "Cancel Order").click
|
|
end
|
|
within '.modal-content' do
|
|
expect {
|
|
find_button("OK").click
|
|
}.to change { order.reload.state }.from('complete').to('canceled')
|
|
end
|
|
end
|
|
end
|
|
|
|
context "Check send/print invoice links" do
|
|
|
|
shared_examples_for 'can send/print invoices' do
|
|
before do
|
|
visit spree.edit_admin_order_path(order)
|
|
find("#links-dropdown .ofn-drop-down").click
|
|
end
|
|
|
|
it 'shows the right links' do
|
|
expect(page).to have_link "Send Invoice", href: spree.invoice_admin_order_path(order)
|
|
expect(page).to have_link "Print Invoice", href: spree.print_admin_order_path(order)
|
|
end
|
|
|
|
it 'can send invoices' do
|
|
accept_alert "An invoice for this order will be sent to the customer. " \
|
|
"Are you sure you want to continue?" do
|
|
click_link "Send Invoice"
|
|
end
|
|
expect(page).to have_content "Invoice email has been sent"
|
|
end
|
|
end
|
|
|
|
context "when abn number is not mandatory to send/print invoices" do
|
|
before do
|
|
Spree::Config[:enterprise_number_required_on_invoices?] = false
|
|
distributor1.update_attribute(:abn, "")
|
|
end
|
|
|
|
it_should_behave_like 'can send/print invoices'
|
|
end
|
|
|
|
context "when abn number is mandatory to send/print invoices" do
|
|
before do
|
|
Spree::Config[:enterprise_number_required_on_invoices?] = true
|
|
end
|
|
|
|
context "and a abn numer is set on the distributor" do
|
|
before do
|
|
distributor1.update_attribute(:abn, '12345678')
|
|
end
|
|
|
|
it_should_behave_like 'can send/print invoices'
|
|
end
|
|
|
|
context "and a abn number is not set on the distributor" do
|
|
before do
|
|
distributor1.update_attribute(:abn, "")
|
|
end
|
|
|
|
it "should not display links but a js alert" do
|
|
visit spree.edit_admin_order_path(order)
|
|
|
|
find("#links-dropdown .ofn-drop-down").click
|
|
expect(page).to have_link "Send Invoice", href: "#"
|
|
expect(page).to have_link "Print Invoice", href: "#"
|
|
|
|
message = accept_prompt do
|
|
click_link "Print Invoice"
|
|
end
|
|
expect(message)
|
|
.to eq "#{distributor1.name} must have a valid ABN before invoices can be sent."
|
|
|
|
find("#links-dropdown .ofn-drop-down").click
|
|
message = accept_prompt do
|
|
click_link "Send Invoice"
|
|
end
|
|
expect(message)
|
|
.to eq "#{distributor1.name} must have a valid ABN before invoices can be sent."
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
context "with different shipping methods" do
|
|
let!(:different_shipping_method_for_distributor1) do
|
|
create(:shipping_method_with, :flat_rate, name: "Different", amount: 15,
|
|
distributors: [distributor1])
|
|
end
|
|
let!(:shipping_method_for_distributor2) do
|
|
create(:shipping_method, name: "Other", distributors: [distributor2])
|
|
end
|
|
|
|
it "can edit shipping method" do
|
|
visit spree.edit_admin_order_path(order)
|
|
|
|
expect(page).to_not have_content different_shipping_method_for_distributor1.name
|
|
|
|
find('.edit-method').click
|
|
expect(page).to have_select2('selected_shipping_rate_id',
|
|
with_options: [
|
|
shipping_method_for_distributor1.name,
|
|
different_shipping_method_for_distributor1.name
|
|
], without_options: [shipping_method_for_distributor2.name])
|
|
select2_select(different_shipping_method_for_distributor1.name,
|
|
from: 'selected_shipping_rate_id')
|
|
find('.save-method').click
|
|
|
|
expect(page).to have_content(
|
|
"Shipping: #{different_shipping_method_for_distributor1.name}"
|
|
)
|
|
|
|
within "#order-total" do
|
|
expect(page).to have_content "$175.00"
|
|
end
|
|
end
|
|
|
|
context "when the distributor unsupport a shipping method that's selected " \
|
|
"in an existing order " do
|
|
before do
|
|
distributor1.shipping_methods = [shipping_method_for_distributor1,
|
|
different_shipping_method_for_distributor1]
|
|
order.shipments.each(&:refresh_rates)
|
|
order.shipment.adjustments.first.open
|
|
order.select_shipping_method(different_shipping_method_for_distributor1)
|
|
order.shipment.adjustments.first.close
|
|
distributor1.shipping_methods = [shipping_method_for_distributor1]
|
|
end
|
|
context "shipment is shipped" do
|
|
before do
|
|
order.shipments.first.update_attribute(:state, 'shipped')
|
|
end
|
|
|
|
it "should not change the shipping method" do
|
|
visit spree.edit_admin_order_path(order)
|
|
expect(page).to have_content(
|
|
"Shipping: #{different_shipping_method_for_distributor1.name} $15.00"
|
|
)
|
|
|
|
within "#order-total" do
|
|
expect(page).to have_content "$160.00"
|
|
end
|
|
end
|
|
|
|
context "when shipping rate is updated" do
|
|
before do
|
|
different_shipping_method_for_distributor1.shipping_rates.first.update!(cost: 16)
|
|
end
|
|
|
|
it "should not update the shipping cost" do
|
|
visit spree.edit_admin_order_path(order)
|
|
expect(page).to have_content(
|
|
"Shipping: #{different_shipping_method_for_distributor1.name} $15.00"
|
|
)
|
|
|
|
within "#order-total" do
|
|
expect(page).to have_content "$160.00"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
context "shipment is pending" do
|
|
before do
|
|
order.shipments.first.ensure_correct_adjustment
|
|
expect(order.shipments.first.state).to eq('pending')
|
|
end
|
|
|
|
it "should not replace the selected shipment method" do
|
|
visit spree.edit_admin_order_path(order)
|
|
expect(page).to have_content(
|
|
"Shipping: #{different_shipping_method_for_distributor1.name} $15.00"
|
|
)
|
|
|
|
within "#order-total" do
|
|
expect(page).to have_content "$160.00"
|
|
end
|
|
end
|
|
|
|
context "when shipping rate is updated" do
|
|
before do
|
|
different_shipping_method_for_distributor1.shipping_rates.first.update!(cost: 16)
|
|
end
|
|
|
|
it "should not update the shipping cost" do
|
|
# Since the order is completed, the price is not supposed to be updated
|
|
visit spree.edit_admin_order_path(order)
|
|
expect(page).to have_content(
|
|
"Shipping: #{different_shipping_method_for_distributor1.name} $15.00"
|
|
)
|
|
|
|
within "#order-total" do
|
|
expect(page).to have_content "$160.00"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
it "can edit and delete tracking number" do
|
|
test_tracking_number = "ABCCBA"
|
|
expect(page).to_not have_content test_tracking_number
|
|
|
|
find('.edit-tracking').click
|
|
fill_in "tracking", with: test_tracking_number
|
|
find('.save-tracking').click
|
|
|
|
expect(page).to have_content test_tracking_number
|
|
|
|
find('.delete-tracking.icon-trash').click
|
|
# Cancel Deletion
|
|
# Check if the alert box shows and after clicking cancel
|
|
# the alert box vanishes and tracking num is still present
|
|
expect(page).to have_content 'Are you sure?'
|
|
find('.cancel').click
|
|
expect(page).to_not have_content 'Are you sure?'
|
|
expect(page).to have_content test_tracking_number
|
|
|
|
find('.delete-tracking.icon-trash').click
|
|
expect(page).to have_content 'Are you sure?'
|
|
find('.confirm').click
|
|
expect(page).to_not have_content test_tracking_number
|
|
end
|
|
|
|
it "can edit and delete note" do
|
|
test_note = "this is a note"
|
|
expect(page).to_not have_content test_note
|
|
|
|
find('.edit-note.icon-edit').click
|
|
fill_in "note", with: test_note
|
|
find('.save-note').click
|
|
|
|
expect(page).to have_content test_note
|
|
|
|
find('.delete-note.icon-trash').click
|
|
# Cancel Deletion
|
|
# Check if the alert box shows and after clicking cancel
|
|
# the alert box vanishes and note is still present
|
|
expect(page).to have_content 'Are you sure?'
|
|
find('.cancel').click
|
|
expect(page).to_not have_content 'Are you sure?'
|
|
expect(page).to have_content test_note
|
|
|
|
find('.delete-note.icon-trash').click
|
|
expect(page).to have_content 'Are you sure?'
|
|
find('.confirm').click
|
|
expect(page).to_not have_content test_note
|
|
end
|
|
|
|
it "viewing shipping fees" do
|
|
shipping_fee = order.shipment_adjustments.first
|
|
|
|
click_link "Adjustments"
|
|
|
|
expect(page).to have_selector "tr#spree_adjustment_#{shipping_fee.id}"
|
|
expect(page).to have_selector 'td.amount', text: shipping_fee.amount.to_s
|
|
expect(page).to have_selector 'td.tax', text: shipping_fee.included_tax_total.to_s
|
|
end
|
|
|
|
context "when an included variant has been deleted" do
|
|
let!(:deleted_variant) do
|
|
order.line_items.first.variant.tap(&:delete)
|
|
end
|
|
|
|
it "still lists the variant in the order page" do
|
|
within ".stock-contents" do
|
|
expect(page).to have_content deleted_variant.product_and_full_name
|
|
end
|
|
end
|
|
end
|
|
|
|
context "and the order has been canceled" do
|
|
it "does not allow modifying line items" do
|
|
order.cancel!
|
|
visit spree.edit_admin_order_path(order)
|
|
within("tr.stock-item", text: order.products.first.name) do
|
|
expect(page).to_not have_selector("a.edit-item")
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when an incomplete order has some line items with insufficient stock" do
|
|
let(:incomplete_order) do
|
|
create(:order_with_line_items, user: user, distributor: distributor,
|
|
order_cycle: order_cycle)
|
|
end
|
|
|
|
it "displays the out of stock line items and they can be deleted from the order" do
|
|
incomplete_order.line_items.first.variant.update!(on_demand: false, on_hand: 0)
|
|
|
|
visit spree.edit_admin_order_path(incomplete_order)
|
|
|
|
expect(page).to have_content "Out of Stock".upcase
|
|
|
|
within ".insufficient-stock-items" do
|
|
expect(page).to have_content incomplete_order.products.first.name
|
|
accept_alert 'Are you sure?' do
|
|
find("a.delete-resource").click
|
|
end
|
|
expect(page).to_not have_content incomplete_order.products.first.name
|
|
end
|
|
|
|
# updates the order and verifies the warning disappears
|
|
click_button 'Update And Recalculate Fees'
|
|
expect(page).to_not have_content "Out of Stock".upcase
|
|
end
|
|
end
|
|
end
|
|
|
|
it "creating an order with distributor and order cycle" do
|
|
new_order_with_distribution(distributor1, order_cycle1)
|
|
expect(page).to have_selector 'h1', text: 'Customer Details'
|
|
click_link "Order Details"
|
|
|
|
expect(page).to have_content 'ADD PRODUCT'
|
|
select2_select product.name, from: 'add_variant_id', search: true
|
|
|
|
find('button.add_variant').click
|
|
page.has_selector? "table.index tbody tr"
|
|
expect(page).to have_selector 'td', text: product.name
|
|
|
|
expect(page).to have_select2 'order_distributor_id', with_options: [distributor1.name]
|
|
expect(page).to_not have_select2 'order_distributor_id', with_options: [distributor2.name]
|
|
|
|
expect(page).to have_select2 'order_order_cycle_id',
|
|
with_options: ["#{order_cycle1.name} (open)"]
|
|
expect(page).to_not have_select2 'order_order_cycle_id',
|
|
with_options: ["#{order_cycle2.name} (open)"]
|
|
|
|
click_button 'Update'
|
|
|
|
o = Spree::Order.last
|
|
expect(o.distributor).to eq distributor1
|
|
expect(o.order_cycle).to eq order_cycle1
|
|
end
|
|
end
|
|
|
|
describe "searching customers" do
|
|
def serching_for_customers
|
|
# opens the customer dropdown
|
|
find(".items-placeholder").click
|
|
|
|
# sets the query name
|
|
find(".dropdown-input").set("John")
|
|
within(".customer-details") do
|
|
expect(page).to have_content("John Doe")
|
|
expect(page).to have_content(customer.email.to_s)
|
|
end
|
|
|
|
# sets the query email
|
|
find(".dropdown-input").set("maura@smith.biz")
|
|
within(".customer-details") do
|
|
expect(page).to have_content("John Doe")
|
|
expect(page).to have_content(customer.email.to_s)
|
|
end
|
|
end
|
|
|
|
context "as the enterprise owner" do
|
|
before do
|
|
product.variants.first.update(on_demand: false, on_hand: 0)
|
|
|
|
login_as user
|
|
new_order_with_distribution(distributor, order_cycle)
|
|
expect(page).to have_selector 'h1', text: "Customer Details"
|
|
end
|
|
|
|
it "finds a customer by name" do
|
|
serching_for_customers
|
|
end
|
|
end
|
|
|
|
context "as superadmin" do
|
|
before do
|
|
product.variants.first.update(on_demand: false, on_hand: 0)
|
|
|
|
login_as_admin
|
|
new_order_with_distribution(distributor, order_cycle)
|
|
expect(page).to have_selector 'h1', text: "Customer Details"
|
|
end
|
|
|
|
it "finds a customer by name" do
|
|
serching_for_customers
|
|
end
|
|
end
|
|
end
|
|
end
|