Files
openfoodnetwork/spec/models/spree/product_spec.rb
Neal Chambers bede52bdae Safely autocorrect Layout/LineLength
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
2023-07-24 09:14:13 +09:00

835 lines
30 KiB
Ruby

# frozen_string_literal: false
require 'spec_helper'
require 'spree/core/product_duplicator'
module Spree
describe Product do
context 'product instance' do
let(:product) { create(:product) }
context '#duplicate' do
before do
allow(product).to receive_messages taxons: [create(:taxon)]
end
it 'duplicates product' do
clone = product.duplicate
expect(clone.name).to eq 'COPY OF ' + product.name
expect(clone.sku).to eq ""
expect(clone.image).to eq product.image
end
end
context "product has variants" do
before do
product.reload.variants << create(:variant, product: product)
end
context "#destroy" do
it "should set deleted_at value" do
product.destroy
expect(product.deleted_at).to_not be_nil
expect(product.variants.all? { |v| !v.deleted_at.nil? }).to be_truthy
end
end
end
describe 'Variants sorting' do
context 'without master variant' do
it 'sorts variants by position' do
expect(product.variants.to_sql).to match(/ORDER BY spree_variants.position ASC/)
end
end
end
end
context "properties" do
let(:product) { create(:product) }
it "should properly assign properties" do
product.set_property('the_prop', 'value1')
expect(product.property('the_prop')).to eq 'value1'
product.set_property('the_prop', 'value2')
expect(product.property('the_prop')).to eq 'value2'
end
it "should not create duplicate properties when set_property is called" do
expect {
product.set_property('the_prop', 'value2')
product.save
product.reload
}.not_to change(product.properties, :length)
expect {
product.set_property('the_prop_new', 'value')
product.save
product.reload
expect(product.property('the_prop_new')).to eq 'value'
}.to change { product.properties.length }.by(1)
end
# Regression test for #2455
it "should not overwrite properties' presentation names" do
Spree::Property.where(name: 'foo').first_or_create!(presentation: "Foo's Presentation Name")
product.set_property('foo', 'value1')
product.set_property('bar', 'value2')
expect(Spree::Property.where(name: 'foo').first.presentation)
.to eq "Foo's Presentation Name"
expect(Spree::Property.where(name: 'bar').first.presentation).to eq "bar"
end
end
describe "supplier properties" do
subject { create(:product) }
it "has no supplier properties to start with" do
expect(subject.supplier_properties).to eq []
end
it "doesn't include product properties" do
subject.set_property("certified", "organic")
expect(subject.supplier_properties).to eq []
end
it "includes the supplier's properties" do
subject.supplier.set_producer_property("certified", "yes")
expect(subject.supplier_properties.map(&:presentation)).to eq ["certified"]
end
end
describe ".with_properties scope" do
let!(:product_without_wanted_property_on_supplier) {
create(:product, supplier: supplier_without_wanted_property)
}
let!(:product_with_wanted_property_on_supplier) {
create(:product, supplier: supplier_with_wanted_property)
}
let!(:product_with_wanted_property) { create(:product, properties: [wanted_property]) }
let!(:product_without_wanted_property_property) {
create(:product, properties: [unwanted_property])
}
let!(:product_with_wanted_property_and_on_supplier) {
create(:product, properties: [wanted_property], supplier: supplier_with_wanted_property)
}
let!(:product_ignoring_property) {
create(:product, supplier: supplier_with_wanted_property, inherits_properties: false)
}
let(:supplier_with_wanted_property) {
create(:supplier_enterprise, properties: [wanted_property])
}
let(:supplier_without_wanted_property) {
create(:supplier_enterprise, properties: [unwanted_property])
}
let(:wanted_property) { create(:property, presentation: 'Certified Organic') }
let(:unwanted_property) { create(:property, presentation: 'Latest Hype') }
it "returns no products without a property id" do
expect(Spree::Product.with_properties([])).to eq []
end
it "returns only products with the wanted property set both on supplier & product itself" do
expect(
Spree::Product.with_properties([wanted_property.id])
).to match_array [
product_with_wanted_property_on_supplier,
product_with_wanted_property,
product_with_wanted_property_and_on_supplier
]
end
end
# Regression tests for Spree #2352
context "classifications and taxons" do
it "is joined through classifications" do
reflection = Spree::Product.reflect_on_association(:taxons)
reflection.options[:through] = :classifications
end
it "will delete all classifications" do
reflection = Spree::Product.reflect_on_association(:classifications)
reflection.options[:dependent] = :delete_all
end
end
describe '#total_on_hand' do
it 'returns sum of stock items count_on_hand' do
product = build(:product)
allow(product).to receive_messages stock_items: [double(Spree::StockItem, count_on_hand: 5)]
expect(product.total_on_hand).to eql(5)
end
end
context "has stock movements" do
let(:product) { create(:product) }
let(:variant) { product.variants.first }
let(:stock_item) { variant.stock_items.first }
it "doesnt raise ReadOnlyRecord error" do
Spree::StockMovement.create!(stock_item: stock_item, quantity: 1)
expect { product.destroy }.not_to raise_error
end
end
describe "associations" do
it { is_expected.to belong_to(:supplier) }
it { is_expected.to belong_to(:primary_taxon) }
end
describe "validations and defaults" do
it "is valid when built from factory" do
expect(build(:product)).to be_valid
end
it "requires a primary taxon" do
expect(build(:simple_product, taxons: [], primary_taxon: nil)).not_to be_valid
end
it "requires a unit value" do
expect(build(:simple_product, unit_value: nil)).not_to be_valid
end
it "requires a supplier" do
expect(build(:simple_product, supplier: nil)).not_to be_valid
end
describe "tax category" do
context "when a tax category is required" do
it "is invalid when a tax category is not provided" do
with_products_require_tax_category(true) do
expect(build(:product, tax_category_id: nil)).not_to be_valid
end
end
end
context "when a tax category is not required" do
it "is valid when a tax category is not provided" do
with_products_require_tax_category(false) do
expect(build(:product, tax_category_id: nil)).to be_valid
end
end
end
end
context "when the product has variants" do
let(:product) do
product = create(:simple_product)
create(:variant, product: product)
product.reload
end
it "requires a unit" do
product.variant_unit = nil
expect(product).not_to be_valid
end
%w(weight volume).each do |unit|
context "when unit is #{unit}" do
it "is valid when unit scale is set and unit name is not" do
product.variant_unit = unit
product.variant_unit_scale = 1
product.variant_unit_name = nil
expect(product).to be_valid
end
it "is invalid when unit scale is not set" do
product.variant_unit = unit
product.variant_unit_scale = nil
product.variant_unit_name = nil
expect(product).not_to be_valid
end
end
end
context "saving a new product" do
let!(:product){ Spree::Product.new }
before do
create(:stock_location)
product.primary_taxon = create(:taxon)
product.supplier = create(:supplier_enterprise)
product.name = "Product1"
product.variant_unit = "weight"
product.variant_unit_scale = 1000
product.unit_value = 1
product.price = 4.27
product.shipping_category = create(:shipping_category)
product.save!
end
it "copies properties to the first standard variant" do
expect(product.variants.reload.length).to eq 1
standard_variant = product.variants.reload.first
expect(standard_variant.price).to eq 4.27
end
end
context "when the unit is items" do
it "is valid when unit name is set and unit scale is not" do
product.variant_unit = 'items'
product.variant_unit_name = 'loaf'
product.variant_unit_scale = nil
expect(product).to be_valid
end
it "is invalid when unit name is not set" do
product.variant_unit = 'items'
product.variant_unit_name = nil
product.variant_unit_scale = nil
expect(product).not_to be_valid
end
end
end
context "a basic product" do
let(:product) { build_stubbed(:simple_product) }
it "requires variant unit fields" do
product.variant_unit = nil
product.variant_unit_name = nil
product.variant_unit_scale = nil
expect(product).to be_invalid
end
it "requires a unit scale when variant unit is weight" do
product.variant_unit = 'weight'
product.variant_unit_scale = nil
product.variant_unit_name = nil
expect(product).not_to be_valid
end
end
describe "#validate_image" do
let(:product) { create(:product_with_image) }
context "when the image is invalid" do
before { expect(product.image).to receive(:valid?).and_return(false) }
it "adds an error message to the base object" do
expect(product).not_to be_valid
expect(product.errors[:base]).to include('Image attachment is not a valid image.')
end
end
context "when master variant is valid" do
it "returns true" do
expect(product).to be_valid
end
end
end
end
describe "callbacks" do
let(:product) { create(:simple_product) }
describe "touching affected enterprises when the product is deleted" do
let(:product) { create(:simple_product) }
let(:supplier) { product.supplier }
let(:distributor) { create(:distributor_enterprise) }
let!(:oc) {
create(:simple_order_cycle, distributors: [distributor],
variants: [product.variants.first])
}
it "touches the supplier" do
expect { product.destroy }.to change { supplier.reload.updated_at }
end
it "touches all distributors" do
expect { product.destroy }.to change { distributor.reload.updated_at }
end
it "removes variants from order cycles" do
expect { product.destroy }.to change { ExchangeVariant.count }
end
end
it "adds the primary taxon to the product's taxon list" do
taxon = create(:taxon)
product = create(:product, primary_taxon: taxon)
expect(product.taxons).to include(taxon)
end
it "removes the previous primary taxon from the taxon list" do
original_taxon = create(:taxon)
product = create(:product, primary_taxon: original_taxon)
product.primary_taxon = create(:taxon)
product.save!
expect(product.taxons).not_to include(original_taxon)
end
it "updates units when saved change to variant unit" do
product.variant_unit = 'items'
product.variant_unit_scale = nil
product.variant_unit_name = 'loaf'
product.save!
expect(product.variant_unit_name).to eq 'loaf'
product.update(variant_unit_name: 'bag')
expect(product.variant_unit_name).to eq 'bag'
product.variant_unit = 'weight'
product.variant_unit_scale = 1
product.variant_unit_name = 'g'
product.save!
expect(product.variant_unit).to eq 'weight'
product.update(variant_unit: 'volume')
expect(product.variant_unit).to eq 'volume'
end
end
describe "scopes" do
describe "in_supplier" do
it "shows products in supplier" do
s1 = create(:supplier_enterprise)
s2 = create(:supplier_enterprise)
p1 = create(:product, supplier: s1)
p2 = create(:product, supplier: s2)
expect(Product.in_supplier(s1)).to eq([p1])
end
end
describe "in_distributor" do
it "shows products in order cycle distribution" do
s = create(:supplier_enterprise)
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
create(:simple_order_cycle, suppliers: [s], distributors: [d1],
variants: [p1.variants.first])
create(:simple_order_cycle, suppliers: [s], distributors: [d2],
variants: [p2.variants.first])
expect(Product.in_distributor(d1)).to eq([p1])
end
it "shows products in order cycle distribution by variant" do
s = create(:supplier_enterprise)
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p1 = create(:product)
v1 = create(:variant, product: p1)
p2 = create(:product)
v2 = create(:variant, product: p2)
create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [v1])
create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [v2])
expect(Product.in_distributor(d1)).to eq([p1])
end
it "doesn't show products listed in the incoming exchange only" do
s = create(:supplier_enterprise)
c = create(:distributor_enterprise)
d = create(:distributor_enterprise)
p = create(:product)
oc = create(:simple_order_cycle, coordinator: c, suppliers: [s], distributors: [d])
ex = oc.exchanges.incoming.first
ex.variants << p.variants.first
expect(Product.in_distributor(d)).to be_empty
end
end
describe "in_distributors" do
let!(:distributor1) { create(:distributor_enterprise) }
let!(:distributor2) { create(:distributor_enterprise) }
let!(:product1) { create(:product) }
let!(:product2) { create(:product) }
let!(:product3) { create(:product) }
let!(:product4) { create(:product) }
let!(:order_cycle1) {
create(:order_cycle, distributors: [distributor1],
variants: [product1.variants.first, product2.variants.first])
}
let!(:order_cycle2) {
create(:order_cycle, distributors: [distributor2],
variants: [product3.variants.first])
}
it "returns distributed products for a given Enterprise AR relation" do
distributors = Enterprise.where(id: [distributor1.id, distributor2.id]).to_a
expect(Product.in_distributors(distributors)).to include product1, product2, product3
expect(Product.in_distributors(distributors)).to_not include product4
end
it "returns distributed products for a given array of enterprise ids" do
distributors_ids = [distributor1.id, distributor2.id]
expect(Product.in_distributors(distributors_ids)).to include product1, product2, product3
expect(Product.in_distributors(distributors_ids)).to_not include product4
end
end
describe "in_supplier_or_distributor" do
it "shows products in supplier" do
s1 = create(:supplier_enterprise)
s2 = create(:supplier_enterprise)
p1 = create(:product, supplier: s1)
p2 = create(:product, supplier: s2)
expect(Product.in_supplier_or_distributor(s1)).to eq([p1])
end
it "shows products in order cycle distribution" do
s = create(:supplier_enterprise)
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
create(:simple_order_cycle, suppliers: [s], distributors: [d1],
variants: [p1.variants.first])
create(:simple_order_cycle, suppliers: [s], distributors: [d2],
variants: [p2.variants.first])
expect(Product.in_supplier_or_distributor(d1)).to eq([p1])
end
it "shows products in all three without duplicates" do
s = create(:supplier_enterprise)
d = create(:distributor_enterprise)
p = create(:product, supplier: s)
create(:simple_order_cycle, suppliers: [s], distributors: [d],
variants: [p.variants.first])
[s, d].each { |e| expect(Product.in_supplier_or_distributor(e)).to eq([p]) }
end
end
describe "in_order_cycle" do
it "shows products in order cycle distribution" do
s = create(:supplier_enterprise)
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
oc1 = create(:simple_order_cycle, suppliers: [s], distributors: [d1],
variants: [p1.variants.first])
oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2],
variants: [p2.variants.first])
expect(Product.in_order_cycle(oc1)).to eq([p1])
end
end
describe "in_an_active_order_cycle" do
it "shows products in order cycle distribution" do
s = create(:supplier_enterprise)
d2 = create(:distributor_enterprise)
d3 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
p3 = create(:product)
oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2],
variants: [p2.variants.first],
orders_open_at: 8.days.ago, orders_close_at: 1.day.ago)
oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d3],
variants: [p3.variants.first],
orders_close_at: Date.tomorrow)
expect(Product.in_an_active_order_cycle).to eq([p3])
end
end
describe "access roles" do
before(:each) do
@e1 = create(:enterprise)
@e2 = create(:enterprise)
@p1 = create(:product, supplier: @e1)
@p2 = create(:product, supplier: @e2)
end
it "shows only products for given user" do
user = create(:user)
user.spree_roles = []
@e1.enterprise_roles.build(user: user).save
product = Product.managed_by user
expect(product.count).to eq(1)
expect(product).to include @p1
end
it "shows all products for admin user" do
user = create(:admin_user)
product = Product.managed_by user
expect(product.count).to eq(2)
expect(product).to include @p1
expect(product).to include @p2
end
end
describe "visible_for" do
let(:enterprise) { create(:distributor_enterprise) }
let!(:new_variant) { create(:variant) }
let!(:hidden_variant) { create(:variant) }
let!(:product) { create(:product) }
let!(:visible_variant1) { create(:variant, product: product) }
let!(:visible_variant2) { create(:variant, product: product) }
let!(:hidden_inventory_item) {
create(:inventory_item, enterprise: enterprise, variant: hidden_variant, visible: false )
}
let!(:visible_inventory_item1) {
create(:inventory_item, enterprise: enterprise, variant: visible_variant1, visible: true )
}
let!(:visible_inventory_item2) {
create(:inventory_item, enterprise: enterprise, variant: visible_variant2, visible: true )
}
let!(:products) { Spree::Product.visible_for(enterprise) }
it "lists any products with variants that are listed as visible=true" do
expect(products.length).to eq(1)
expect(products).to include product
expect(products).to_not include new_variant.product, hidden_variant.product
end
end
describe 'stockable_by' do
let(:shop) { create(:distributor_enterprise) }
let(:add_to_oc_producer) { create(:supplier_enterprise) }
let(:other_producer) { create(:supplier_enterprise) }
let!(:p1) { create(:simple_product, supplier: shop ) }
let!(:p2) { create(:simple_product, supplier: add_to_oc_producer ) }
let!(:p3) { create(:simple_product, supplier: other_producer ) }
before do
create(:enterprise_relationship, parent: add_to_oc_producer, child: shop,
permissions_list: [:add_to_order_cycle])
create(:enterprise_relationship, parent: other_producer, child: shop,
permissions_list: [:manage_products])
end
it 'shows products produced by the enterprise and any producers granting P-OC' do
stockable_products = Spree::Product.stockable_by(shop)
expect(stockable_products).to include p1, p2
expect(stockable_products).to_not include p3
end
end
describe "imported_on" do
let!(:v1) { create(:variant, import_date: 1.day.ago) }
let!(:v2) { create(:variant, import_date: 2.days.ago) }
let!(:v3) { create(:variant, import_date: 1.day.ago) }
it "returns products imported on given day" do
imported_products = Spree::Product.imported_on(1.day.ago.to_date)
expect(imported_products).to include v1.product, v3.product
end
end
end
describe "properties" do
it "returns product properties as a hash" do
product = create(:simple_product)
product.set_property 'Organic Certified', 'NASAA 12345'
property = product.properties.last
expect(product.properties_including_inherited)
.to eq([{ id: property.id, name: "Organic Certified",
value: 'NASAA 12345' }])
end
it "returns producer properties as a hash" do
supplier = create(:supplier_enterprise)
product = create(:simple_product, supplier: supplier)
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
property = supplier.properties.last
expect(product.properties_including_inherited)
.to eq([{ id: property.id, name: "Organic Certified",
value: 'NASAA 54321' }])
end
it "overrides producer properties with product properties" do
supplier = create(:supplier_enterprise)
product = create(:simple_product, supplier: supplier)
product.set_property 'Organic Certified', 'NASAA 12345'
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
property = product.properties.last
expect(product.properties_including_inherited)
.to eq([{ id: property.id, name: "Organic Certified",
value: 'NASAA 12345' }])
end
context "when product has an inherit_properties value set to true" do
let(:supplier) { create(:supplier_enterprise) }
let(:product) { create(:simple_product, supplier: supplier, inherits_properties: true) }
it "inherits producer properties" do
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
property = supplier.properties.last
expect(product.properties_including_inherited)
.to eq([{ id: property.id, name: "Organic Certified",
value: 'NASAA 54321' }])
end
end
context "when product has an inherit_properties value set to false" do
let(:supplier) { create(:supplier_enterprise) }
let(:product) { create(:simple_product, supplier: supplier, inherits_properties: false) }
it "does not inherit producer properties" do
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
expect(product.properties_including_inherited).to eq([])
end
end
it "sorts by position" do
supplier = create(:supplier_enterprise)
product = create(:simple_product, supplier: supplier)
pa = Spree::Property.create! name: 'A', presentation: 'A'
pb = Spree::Property.create! name: 'B', presentation: 'B'
pc = Spree::Property.create! name: 'C', presentation: 'C'
product.product_properties.create!({ property_id: pa.id, value: '1', position: 1 })
product.product_properties.create!({ property_id: pc.id, value: '3', position: 3 })
supplier.producer_properties.create!({ property_id: pb.id, value: '2', position: 2 })
expect(product.properties_including_inherited).to eq(
[{ id: pa.id, name: "A", value: '1' },
{ id: pb.id, name: "B", value: '2' },
{ id: pc.id, name: "C", value: '3' }]
)
end
end
describe "membership" do
it "queries its membership of a particular order cycle distribution" do
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
oc1 = create(:simple_order_cycle, distributors: [d1], variants: [p1.variants.first])
oc2 = create(:simple_order_cycle, distributors: [d2], variants: [p2.variants.first])
expect(p1).to be_in_distributor d1
expect(p1).not_to be_in_distributor d2
end
it "queries its membership of a particular order cycle" do
d1 = create(:distributor_enterprise)
d2 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
oc1 = create(:simple_order_cycle, distributors: [d1], variants: [p1.variants.first])
oc2 = create(:simple_order_cycle, distributors: [d2], variants: [p2.variants.first])
expect(p1).to be_in_order_cycle oc1
expect(p1).not_to be_in_order_cycle oc2
end
end
describe "variant units" do
context "when the product already has a variant unit set" do
let!(:p) {
create(:simple_product,
variant_unit: 'weight',
variant_unit_scale: 1,
variant_unit_name: nil)
}
it "updates its variants unit values" do
v = create(:variant, unit_value: 1, product: p)
p.reload
expect(v.unit_presentation).to eq "1g"
p.update!(variant_unit: 'volume', variant_unit_scale: 0.001)
expect(v.reload.unit_presentation).to eq "1L"
end
end
end
describe "taxons" do
let(:taxon1) { create(:taxon) }
let(:taxon2) { create(:taxon) }
let(:product) { create(:simple_product) }
it "returns the first taxon as the primary taxon" do
expect(product.taxons).to eq([product.primary_taxon])
end
end
describe "deletion" do
let(:p) { create(:simple_product) }
let(:v) { create(:variant, product: p) }
let(:oc) { create(:simple_order_cycle) }
let(:s) { create(:supplier_enterprise) }
let(:e) {
create(:exchange, order_cycle: oc, incoming: true, sender: s, receiver: oc.coordinator)
}
it "removes all variants from order cycles" do
e.variants << v
p.destroy
expect(e.variants.reload).to be_empty
end
end
end
describe "product import" do
describe "finding the most recent import date of the variants" do
let!(:product) { create(:product) }
let(:reference_time) { Time.zone.now.beginning_of_day }
before do
product.reload
end
context "when the variants do not have an import date" do
let!(:variant_a) { create(:variant, product: product, import_date: nil) }
let!(:variant_b) { create(:variant, product: product, import_date: nil) }
it "returns nil" do
expect(product.import_date).to be_nil
end
end
context "when some variants have import date and some do not" do
let!(:variant_a) { create(:variant, product: product, import_date: nil) }
let!(:variant_b) {
create(:variant, product: product, import_date: reference_time - 1.hour)
}
let!(:variant_c) {
create(:variant, product: product, import_date: reference_time - 2.hours)
}
it "returns the most recent import date" do
expect(product.import_date).to eq(variant_b.import_date)
end
end
context "when all variants have import date" do
let!(:variant_a) {
create(:variant, product: product, import_date: reference_time - 2.hours)
}
let!(:variant_b) {
create(:variant, product: product, import_date: reference_time - 1.hour)
}
let!(:variant_c) {
create(:variant, product: product, import_date: reference_time - 3.hours)
}
it "returns the most recent import date" do
expect(product.import_date).to eq(variant_b.import_date)
end
end
end
end
end