Files
openfoodnetwork/spec/models/spree/ability_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

892 lines
32 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
require 'cancan/matchers'
require 'support/ability_helpers'
describe Spree::Ability do
let(:user) { create(:user) }
let(:subject) { Spree::Ability.new(user) }
let(:token) { nil }
before do
user.spree_roles.clear
end
TOKEN = 'token123'
after(:each) {
user.spree_roles = []
}
context 'for general resource' do
let(:resource) { Object.new }
context 'with admin user' do
before(:each) { allow(user).to receive(:has_spree_role?).and_return(true) }
it_should_behave_like 'access granted'
it_should_behave_like 'index allowed'
end
context 'with customer' do
it_should_behave_like 'access denied'
it_should_behave_like 'no index allowed'
end
end
context 'for admin protected resources' do
let(:resource) { Object.new }
let(:resource_shipment) { Spree::Shipment.new }
let(:resource_product) { Spree::Product.new }
let(:resource_user) { Spree::User.new }
let(:resource_order) { Spree::Order.new }
let(:fakedispatch_user) { Spree::User.new }
let(:fakedispatch_ability) { Spree::Ability.new(fakedispatch_user) }
context 'with admin user' do
it 'should be able to admin' do
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
expect(subject).to be_able_to :admin, resource
expect(subject).to be_able_to :index, resource_order
expect(subject).to be_able_to :show, resource_product
expect(subject).to be_able_to :create, resource_user
end
end
context 'with customer' do
it 'should not be able to admin' do
expect(subject).to_not be_able_to :admin, resource
expect(subject).to_not be_able_to :admin, resource_order
expect(subject).to_not be_able_to :admin, resource_product
expect(subject).to_not be_able_to :admin, resource_user
end
end
end
context 'as Guest User' do
context 'for Country' do
let(:resource) { Spree::Country.new }
context 'requested by any user' do
it_should_behave_like 'read only'
end
end
context 'for Order' do
let(:resource) { Spree::Order.new }
context 'requested by same user' do
before(:each) { resource.user = user }
it_should_behave_like 'access granted'
it_should_behave_like 'no index allowed'
end
context 'requested by other user' do
before(:each) { resource.user = Spree::User.new }
it_should_behave_like 'create only'
end
context 'requested with proper token' do
let(:token) { 'TOKEN123' }
before(:each) { allow(resource).to receive_messages token: 'TOKEN123' }
it_should_behave_like 'access granted'
it_should_behave_like 'no index allowed'
end
context 'requested with inproper token' do
let(:token) { 'FAIL' }
before(:each) { allow(resource).to receive_messages token: 'TOKEN123' }
it_should_behave_like 'create only'
end
end
context 'for Product' do
let(:resource) { Spree::Product.new }
context 'requested by any user' do
it_should_behave_like 'read only'
end
end
context 'for ProductProperty' do
let(:resource) { Spree::Product.new }
context 'requested by any user' do
it_should_behave_like 'read only'
end
end
context 'for Property' do
let(:resource) { Spree::Product.new }
context 'requested by any user' do
it_should_behave_like 'read only'
end
end
context 'for State' do
let(:resource) { Spree::State.new }
context 'requested by any user' do
it_should_behave_like 'read only'
end
end
context 'for StockItem' do
let(:resource) { Spree::StockItem.new }
context 'requested by any user' do
it_should_behave_like 'read only'
end
end
context 'for StockLocation' do
let(:resource) { Spree::StockLocation.new }
context 'requested by any user' do
it_should_behave_like 'read only'
end
end
context 'for StockMovement' do
let(:resource) { Spree::StockMovement.new }
context 'requested by any user' do
it_should_behave_like 'read only'
end
end
context 'for Taxons' do
let(:resource) { Spree::Taxon.new }
context 'requested by any user' do
it_should_behave_like 'read only'
end
end
context 'for Taxonomy' do
let(:resource) { Spree::Taxonomy.new }
context 'requested by any user' do
it_should_behave_like 'read only'
end
end
context 'for User' do
context 'requested by same user' do
let(:resource) { user }
it_should_behave_like 'access granted'
it_should_behave_like 'no index allowed'
end
context 'requested by other user' do
let(:resource) { Spree::User.new }
it_should_behave_like 'create only'
end
end
context 'for Variant' do
let(:resource) { Spree::Variant.new }
context 'requested by any user' do
it_should_behave_like 'read only'
end
end
context 'for Zone' do
let(:resource) { Spree::Zone.new }
context 'requested by any user' do
it_should_behave_like 'read only'
end
end
end
describe "broad permissions" do
let(:user) { create(:user) }
let(:enterprise_any) { create(:enterprise, sells: 'any') }
let(:enterprise_own) { create(:enterprise, sells: 'own') }
let(:enterprise_none) { create(:enterprise, sells: 'none') }
let(:enterprise_any_producer) { create(:enterprise, sells: 'any', is_primary_producer: true) }
let(:enterprise_own_producer) { create(:enterprise, sells: 'own', is_primary_producer: true) }
let(:enterprise_none_producer) { create(:enterprise, sells: 'none', is_primary_producer: true) }
context "as manager of an enterprise who sells 'any'" do
before do
user.enterprise_roles.create! enterprise: enterprise_any
end
it { expect(subject.can_manage_products?(user)).to be true }
it { expect(subject.can_manage_enterprises?(user)).to be true }
it { expect(subject.can_manage_orders?(user)).to be true }
it { expect(subject.can_manage_order_cycles?(user)).to be true }
end
context "as manager of an enterprise who sell 'own'" do
before do
user.enterprise_roles.create! enterprise: enterprise_own
end
it { expect(subject.can_manage_products?(user)).to be true }
it { expect(subject.can_manage_enterprises?(user)).to be true }
it { expect(subject.can_manage_orders?(user)).to be true }
it { expect(subject.can_manage_order_cycles?(user)).to be true }
end
context "as manager of an enterprise who sells 'none'" do
before do
user.enterprise_roles.create! enterprise: enterprise_none
end
it { expect(subject.can_manage_products?(user)).to be false }
it { expect(subject.can_manage_enterprises?(user)).to be true }
it { expect(subject.can_manage_orders?(user)).to be false }
it { expect(subject.can_manage_order_cycles?(user)).to be false }
end
context "as manager of a producer enterprise who sells 'any'" do
before do
user.enterprise_roles.create! enterprise: enterprise_any_producer
end
it { expect(subject.can_manage_products?(user)).to be true }
it { expect(subject.can_manage_enterprises?(user)).to be true }
it { expect(subject.can_manage_orders?(user)).to be true }
it { expect(subject.can_manage_order_cycles?(user)).to be true }
end
context "as manager of a producer enterprise who sell 'own'" do
before do
user.enterprise_roles.create! enterprise: enterprise_own_producer
end
it { expect(subject.can_manage_products?(user)).to be true }
it { expect(subject.can_manage_enterprises?(user)).to be true }
it { expect(subject.can_manage_orders?(user)).to be true }
it { expect(subject.can_manage_order_cycles?(user)).to be true }
end
context "as manager of a producer enterprise who sells 'none'" do
before do
user.enterprise_roles.create! enterprise: enterprise_none_producer
end
context "as a non profile" do
before do
enterprise_none_producer.is_primary_producer = true
enterprise_none_producer.producer_profile_only = false
enterprise_none_producer.save!
end
it { expect(subject.can_manage_products?(user)).to be true }
it { expect(subject.can_manage_enterprises?(user)).to be true }
it { expect(subject.can_manage_orders?(user)).to be false }
it { expect(subject.can_manage_order_cycles?(user)).to be false }
end
context "as a profile" do
before do
enterprise_none_producer.is_primary_producer = true
enterprise_none_producer.producer_profile_only = true
enterprise_none_producer.save!
end
it { expect(subject.can_manage_products?(user)).to be false }
it { expect(subject.can_manage_enterprises?(user)).to be true }
it { expect(subject.can_manage_orders?(user)).to be false }
it { expect(subject.can_manage_order_cycles?(user)).to be false }
end
end
context "as a new user with no enterprises" do
it { expect(subject.can_manage_products?(user)).to be false }
it { expect(subject.can_manage_enterprises?(user)).to be false }
it { expect(subject.can_manage_orders?(user)).to be false }
it { expect(subject.can_manage_order_cycles?(user)).to be false }
it "can create enterprises straight off the bat" do
expect(subject.is_new_user?(user)).to be true
expect(user).to have_ability :create, for: Enterprise
end
end
end
describe 'Roles' do
# create enterprises
let(:s1) { create(:supplier_enterprise) }
let(:s2) { create(:supplier_enterprise) }
let(:s_related) { create(:supplier_enterprise) }
let(:d1) { create(:distributor_enterprise) }
let(:d2) { create(:distributor_enterprise) }
let(:p1) { create(:product, supplier: s1) }
let(:p2) { create(:product, supplier: s2) }
let(:p_related) { create(:product, supplier: s_related) }
let(:er1) { create(:enterprise_relationship, parent: s1, child: d1) }
let(:er2) { create(:enterprise_relationship, parent: d1, child: s1) }
let(:er3) { create(:enterprise_relationship, parent: s2, child: d2) }
let(:er_ps) {
create(:enterprise_relationship, parent: s_related, child: s1,
permissions_list: [:manage_products])
}
subject { user }
let(:user) { nil }
context "when is a supplier enterprise user" do
# create supplier_enterprise1 user without full admin access
let(:user) do
user = create(:user)
user.spree_roles = []
s1.enterprise_roles.build(user: user).save
user
end
let(:order) { create(:order) }
it "should be able to read/write their enterprises' products and variants" do
is_expected.to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy],
for: p1)
is_expected.to have_ability(
[:admin, :index, :read, :edit, :update, :search, :destroy,
:delete], for: p1.variants.first
)
end
it "should be able to read/write related enterprises' products " \
"and variants with manage_products permission" do
er_ps
is_expected.to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy],
for: p_related)
is_expected.to have_ability(
[:admin, :index, :read, :edit, :update, :search, :destroy,
:delete], for: p_related.variants.first
)
end
it "should not be able to read/write other enterprises' products and variants" do
is_expected.not_to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy],
for: p2)
is_expected.not_to have_ability([:admin, :index, :read, :edit, :update, :search, :destroy],
for: p2.variants.first)
end
it "should not be able to access admin actions on orders" do
is_expected.not_to have_ability([:admin], for: Spree::Order)
end
it "should be able to create a new product" do
is_expected.to have_ability(:create, for: Spree::Product)
end
it "should be able to read/write their enterprises' product variants" do
is_expected.to have_ability([:create], for: Spree::Variant)
is_expected.to have_ability(
[:admin, :index, :read, :create, :edit, :search, :update, :destroy,
:delete], for: p1.variants.first
)
end
it "should not be able to read/write other enterprises' product variants" do
is_expected.not_to have_ability(
[:admin, :index, :read, :create, :edit, :search, :update,
:destroy], for: p2.variants.first
)
end
it "should be able to read/write their enterprises' product properties" do
is_expected.to have_ability(
[:admin, :index, :read, :create, :edit, :update_positions,
:destroy], for: Spree::ProductProperty
)
end
it "should be able to read/write their enterprises' product images" do
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :destroy],
for: Spree::Image)
end
it "should be able to read Taxons (in order to create classifications)" do
is_expected.to have_ability([:admin, :index, :read, :search], for: Spree::Taxon)
end
it "should be able to read/write Classifications on a product" do
is_expected.to have_ability([:admin, :index, :read, :create, :edit],
for: Spree::Classification)
end
it "should be able to read/write their enterprises' producer properties" do
is_expected.to have_ability(
[:admin, :index, :read, :create, :edit, :update_positions,
:destroy], for: ProducerProperty
)
end
it "should be able to read and create enterprise relationships" do
is_expected.to have_ability([:admin, :index, :create], for: EnterpriseRelationship)
end
it "should be able to destroy enterprise relationships for its enterprises" do
is_expected.to have_ability(:destroy, for: er1)
end
it "should be able to destroy enterprise relationships for other child-linked enterprises" do
is_expected.to have_ability(:destroy, for: er2)
end
it "should not be able to destroy enterprise relationships for other enterprises" do
is_expected.not_to have_ability(:destroy, for: er3)
end
it "should be able to read some reports" do
is_expected.to have_ability(
[:admin, :index, :show], for: Admin::ReportsController
)
is_expected.to have_ability(
[:customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory,
:order_cycle_management], for: :report
)
end
include_examples "allows access to Enterprise Fee Summary"
it "should not be able to read other reports" do
is_expected.not_to have_ability(
[:group_buys, :payments, :orders_and_distributors, :users_and_enterprises,
:xero_invoices, :revenues_by_hub], for: :report
)
end
it "should not be able to access customer actions" do
is_expected.not_to have_ability([:admin, :index, :update], for: Customer)
end
describe "order_cycles abilities" do
context "where the enterprise is not in an order_cycle" do
let!(:order_cycle) { create(:simple_order_cycle) }
it "should not be able to access read/update order_cycle actions" do
is_expected.not_to have_ability([:admin, :index, :read, :edit, :update],
for: order_cycle)
end
it "should not be able to access bulk_update, clone order cycle actions" do
is_expected.not_to have_ability([:bulk_update, :clone], for: order_cycle)
end
it "cannot request permitted enterprises for an order cycle" do
is_expected.not_to have_ability([:for_order_cycle], for: Enterprise)
end
it "cannot request permitted enterprise fees for an order cycle" do
is_expected.not_to have_ability([:for_order_cycle], for: EnterpriseFee)
end
end
context "where the enterprise is in an order_cycle" do
let!(:order_cycle) { create(:simple_order_cycle) }
let!(:exchange){
create(:exchange, incoming: true, order_cycle: order_cycle,
receiver: order_cycle.coordinator, sender: s1)
}
it "should be able to access read/update order cycle actions" do
is_expected.to have_ability([:admin, :index, :read, :edit, :update], for: order_cycle)
end
it "should not be able to access bulk/update, clone order cycle actions" do
is_expected.not_to have_ability([:bulk_update, :clone], for: order_cycle)
end
it "can request permitted enterprises for an order cycle" do
is_expected.to have_ability([:for_order_cycle], for: Enterprise)
end
it "can request permitted enterprise fees for an order cycle" do
is_expected.to have_ability([:for_order_cycle], for: EnterpriseFee)
end
end
end
end
context "when is a distributor enterprise user" do
let(:user) do
user = create(:user)
user.spree_roles = []
d1.enterprise_roles.build(user: user).save
user
end
# create order for each enterprise
let(:o1) do
o = create(:order, distributor: d1, bill_address: create(:address))
create(:line_item, order: o, product: p1)
o
end
let(:o2) do
o = create(:order, distributor: d2, bill_address: create(:address))
create(:line_item, order: o, product: p1)
o
end
let(:o3) do
o = create(:order, distributor: nil, bill_address: create(:address))
create(:line_item, order: o, product: p1)
o
end
describe "editing enterprises" do
let!(:d_related) { create(:distributor_enterprise) }
let!(:er_pd) {
create(:enterprise_relationship, parent: d_related, child: d1,
permissions_list: [:edit_profile])
}
it "should be able to edit enterprises it manages" do
is_expected.to have_ability(
[:read, :edit, :update, :remove_logo, :remove_promo_image, :remove_terms_and_conditions,
:bulk_update, :resend_confirmation], for: d1
)
end
it "should be able to edit enterprises it has permission to" do
is_expected.to have_ability(
[:read, :edit, :update, :remove_logo, :remove_promo_image, :remove_terms_and_conditions,
:bulk_update, :resend_confirmation], for: d_related
)
end
it "should be able to manage shipping methods, payment methods and enterprise fees " \
"for enterprises it manages" do
is_expected.to have_ability(
[:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d1
)
end
it "should not be able to manage shipping methods, payment methods and enterprise fees " \
"for enterprises it has edit profile permission to" do
is_expected.not_to have_ability(
[:manage_shipping_methods, :manage_payment_methods,
:manage_enterprise_fees], for: d_related
)
end
end
describe "variant overrides" do
let(:vo1) { create(:variant_override, hub: d1, variant: p1.variants.first) }
let(:vo2) { create(:variant_override, hub: d1, variant: p2.variants.first) }
let(:vo3) { create(:variant_override, hub: d2, variant: p1.variants.first) }
let(:vo4) { create(:variant_override, hub: d2, variant: p2.variants.first) }
let!(:er1) {
create(:enterprise_relationship, parent: s1, child: d1,
permissions_list: [:create_variant_overrides])
}
it "should be able to access variant overrides page" do
is_expected.to have_ability([:admin, :index, :bulk_update, :bulk_reset],
for: VariantOverride)
end
it "should be able to read/write their own variant overrides" do
is_expected.to have_ability([:admin, :index, :read, :update], for: vo1)
end
it "should not be able to read/write variant overrides " \
"when producer of product hasn't granted permission" do
is_expected.not_to have_ability([:admin, :index, :read, :update], for: vo2)
end
it "shouldn't be able to read/write variant overrides when we can't add hub to OC" do
is_expected.not_to have_ability([:admin, :index, :read, :update], for: vo3)
end
it "should not be able to read/write other enterprises' variant overrides" do
is_expected.not_to have_ability([:admin, :index, :read, :update], for: vo4)
end
end
it "should be able to read/write their enterprises' orders" do
is_expected.to have_ability([:admin, :index, :read, :edit], for: o1)
end
it "should not be able to read/write other enterprises' orders" do
is_expected.not_to have_ability([:admin, :index, :read, :edit], for: o2)
end
it "should be able to read/write orders that are in the process of being created" do
is_expected.to have_ability([:admin, :index, :read, :edit], for: o3)
end
it "should be able to create and search on nil (required for creating an order)" do
is_expected.to have_ability([:create, :search], for: nil)
end
it "should be able to create a new order" do
is_expected.to have_ability([:admin, :index, :read, :create, :update], for: Spree::Order)
end
it "should be able to create a new line item" do
is_expected.to have_ability([:admin, :create], for: Spree::LineItem)
end
it "should be able to read/write Payments on a product" do
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire],
for: Spree::Payment)
end
it "should be able to read/write Shipments on a product" do
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire],
for: Spree::Shipment)
end
it "should be able to read/write Adjustments on a product" do
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire],
for: Spree::Adjustment)
end
it "should be able to read/write ReturnAuthorizations on a product" do
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire],
for: Spree::ReturnAuthorization)
end
it "should be able to read/write PaymentMethods" do
is_expected.to have_ability([:admin, :index, :create, :update, :destroy],
for: Spree::PaymentMethod)
end
it "should be able to read/write ShippingMethods" do
is_expected.to have_ability([:admin, :index, :create, :update, :destroy],
for: Spree::ShippingMethod)
end
it "should be able to read and create enterprise relationships" do
is_expected.to have_ability([:admin, :index, :create], for: EnterpriseRelationship)
end
it "should be able to destroy enterprise relationships for its enterprises" do
is_expected.to have_ability(:destroy, for: er2)
end
it "should be able to destroy enterprise relationships for other child-linked enterprises" do
is_expected.to have_ability(:destroy, for: er1)
end
it "should not be able to destroy enterprise relationships for other enterprises" do
is_expected.not_to have_ability(:destroy, for: er3)
end
it "should be able to read some reports" do
is_expected.to have_ability(
[:admin, :index, :show], for: Admin::ReportsController
)
is_expected.to have_ability(
[:customers, :sales_tax, :group_buys, :bulk_coop, :payments,
:orders_and_distributors, :orders_and_fulfillment, :products_and_inventory,
:order_cycle_management, :xero_invoices], for: :report
)
end
include_examples "allows access to Enterprise Fee Summary"
it "should not be able to read other reports" do
is_expected.not_to have_ability([:users_and_enterprises, :revenues_by_hub],
for: :report)
end
it "should be able to access customer actions" do
is_expected.to have_ability([:admin, :index, :update], for: Customer)
end
context "for a given order_cycle" do
let!(:order_cycle) { create(:simple_order_cycle, coordinator: d2) }
let!(:exchange){
create(:exchange, incoming: false, order_cycle: order_cycle, receiver: d1,
sender: order_cycle.coordinator)
}
it "should be able to access read and update order cycle actions" do
is_expected.to have_ability([:admin, :index, :read, :edit, :update], for: order_cycle)
end
it "should not be able to access bulk_update, clone order cycle actions" do
is_expected.not_to have_ability([:bulk_update, :clone], for: order_cycle)
end
end
it "can request permitted enterprises for an order cycle" do
is_expected.to have_ability([:for_order_cycle], for: Enterprise)
end
it "can request permitted enterprise fees for an order cycle" do
is_expected.to have_ability([:for_order_cycle], for: EnterpriseFee)
end
end
context 'Order Cycle co-ordinator, distributor enterprise manager' do
let(:user) do
user = create(:user)
user.spree_roles = []
d1.enterprise_roles.build(user: user).save
user
end
let(:oc1) { create(:simple_order_cycle, coordinator: d1) }
let(:oc2) { create(:simple_order_cycle, coordinator: d2) }
it "should be able to read/write OrderCycles they are the co-ordinator of" do
is_expected.to have_ability(
[:admin, :index, :read, :edit, :update, :bulk_update, :clone, :destroy], for: oc1
)
end
it "should not be able to read/write OrderCycles they are not the co-ordinator of" do
should_not have_ability(
[:admin, :index, :read, :create, :edit, :update, :bulk_update, :clone, :destroy], for: oc2
)
end
it "should be able to create OrderCycles" do
is_expected.to have_ability([:create], for: OrderCycle)
end
it "should be able to read/write EnterpriseFees" do
is_expected.to have_ability(
[:admin, :index, :read, :create, :edit, :bulk_update, :destroy,
:for_order_cycle], for: EnterpriseFee
)
end
it "should be able to add enterprises to order cycles" do
is_expected.to have_ability([:admin, :index, :for_order_cycle, :create], for: Enterprise)
end
end
context 'enterprise manager' do
let(:user) do
user = create(:user)
user.spree_roles = []
s1.enterprise_roles.build(user: user).save
user
end
it 'should have the ability to view the admin account page' do
is_expected.to have_ability([:admin, :show], for: :account)
end
it 'should have the ability to read and edit enterprises that I manage' do
is_expected.to have_ability([:read, :edit, :update, :bulk_update], for: s1)
end
it 'should not have the ability to read and edit enterprises that I do not manage' do
is_expected.not_to have_ability([:read, :edit, :update, :bulk_update], for: s2)
end
it 'should not have the ability to welcome and register enterprises that I do not own' do
is_expected.not_to have_ability([:welcome, :register], for: s1)
end
it 'should have the ability administrate and create enterpises' do
is_expected.to have_ability([:admin, :index, :create], for: Enterprise)
end
it "should have the ability to search for users which share management of its enterprises" do
is_expected.to have_ability([:admin, :known_users, :customers], for: :search)
is_expected.not_to have_ability([:users], for: :search)
end
it "has the ability to manage vouchers" do
is_expected.to have_ability([:admin, :create], for: Voucher)
end
end
context 'enterprise owner' do
let(:user) { s1.owner }
it 'should have the ability to welcome and register enterprises that I own' do
is_expected.to have_ability([:welcome, :register], for: s1)
end
it 'should have the ability to view the admin account page' do
is_expected.to have_ability([:admin, :show], for: :account)
end
end
end
describe "permissions for variant overrides" do
let!(:distributor) { create(:distributor_enterprise) }
let!(:producer) { create(:supplier_enterprise) }
let!(:product) { create(:product, supplier: producer) }
let!(:variant) { create(:variant, product: product) }
let!(:variant_override) { create(:variant_override, hub: distributor, variant: variant) }
subject { user }
let(:manage_actions) { [:admin, :index, :read, :update, :bulk_update, :bulk_reset] }
describe "when admin" do
before { user.spree_roles << Spree::Role.find_or_create_by!(name: 'admin') }
it "should have permission" do
is_expected.to have_ability(manage_actions, for: variant_override)
end
end
describe "when user of the producer" do
let(:user) { producer.owner }
it "should not have permission" do
is_expected.not_to have_ability(manage_actions, for: variant_override)
end
end
describe "when user of the distributor" do
let(:user) { distributor.owner }
it "should not have permission" do
is_expected.not_to have_ability(manage_actions, for: variant_override)
end
end
describe "when user of the distributor which is also the producer" do
let(:user) { distributor.owner }
let!(:distributor) {
create(:distributor_enterprise, is_primary_producer: true, sells: "any")
}
let!(:producer) { distributor }
it "should have permission" do
is_expected.to have_ability(manage_actions, for: variant_override)
end
end
describe "when owner of the distributor with add_to_order_cycle permission to the producer" do
let!(:unauthorized_enterprise) do
create(:enterprise, sells: "any").tap do |record|
create(:enterprise_relationship, parent: producer, child: record,
permissions_list: [:add_to_order_cycle])
end
end
let(:user) { unauthorized_enterprise.owner }
it "should not have permission" do
is_expected.not_to have_ability(manage_actions, for: variant_override)
end
end
describe "when owner of enterprise with create_variant_overrides permission to the producer" do
let!(:authorized_enterprise) do
create(:enterprise, sells: "any").tap do |record|
create(:enterprise_relationship, parent: producer, child: record,
permissions_list: [:create_variant_overrides])
end
end
let(:user) { authorized_enterprise.owner }
it "should not have permission" do
is_expected.not_to have_ability(manage_actions, for: variant_override)
end
describe "when the enterprise is not a distributor" do
let!(:authorized_enterprise) do
create(:enterprise, sells: "none").tap do |record|
create(:enterprise_relationship, parent: producer, child: record,
permissions_list: [:create_variant_overrides])
end
end
it "should not have permission" do
is_expected.not_to have_ability(manage_actions, for: variant_override)
end
end
end
end
end