mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-06 22:36:07 +00:00
Inspecting 1478 files
.......C............................C..............................................................................................................C.......................................................................................................C............................................................................C................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C.................C......................................C...................................................................................................................C...........................................................C........................C...C.....C..C..C..........C..................C...............C.....................C...................................................................................C......................................................C........C..C...........C....................C.CC....C....................................C......C..........................
Offenses:
app/components/confirm_modal_component.rb:4:88: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
def initialize(id:, confirm_actions: nil, reflex: nil, controller: nil, message: nil,
^
app/components/confirm_modal_component.rb:4:101: C: [Corrected] Layout/LineLength: Line is too long. [110/100]
def initialize(id:, confirm_actions: nil, reflex: nil, controller: nil, message: nil, confirm_reflexes: nil)
^^^^^^^^^^
app/components/confirm_modal_component.rb:5:1: C: [Corrected] Layout/ParameterAlignment: Align the parameters of a method definition if they span more than one line.
confirm_reflexes: nil)
^^^^^^^^^^^^^^^^^^^^^
app/controllers/admin/product_import_controller.rb:142:43: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
redirect_to '/admin/product_import',
^
app/controllers/admin/product_import_controller.rb:142:101: C: [Corrected] Layout/LineLength: Line is too long. [104/100]
redirect_to '/admin/product_import', notice: I18n.t(:product_import_no_data_in_spreadsheet_notice)
^^^^
app/controllers/admin/product_import_controller.rb:143:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
notice: I18n.t(:product_import_no_data_in_spreadsheet_notice)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/spree/users_controller.rb:53:101: C: Layout/LineLength: Line is too long. [107/100]
message: t('devise.user_registrations.spree_user.signed_up_but_unconfirmed') })
^^^^^^^
app/models/customer.rb:43:101: C: [Corrected] Layout/LineLength: Line is too long. [113/100]
scope :managed_by, ->(user) { user&.persisted? ? where(user: user).or(of(Enterprise.managed_by(user))) : none }
^^^^^^^^^^^^^
app/models/customer.rb:44:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 1) spaces for indentation.
user&.persisted? ? where(user: user).or(of(Enterprise.managed_by(user))) : none
^
app/models/customer.rb:44:3: C: [Corrected] Layout/IndentationWidth: Use 2 (not -19) spaces for indentation.
user&.persisted? ? where(user: user).or(of(Enterprise.managed_by(user))) : none
^^^^^^^^^^^^^^^^^^^
app/models/customer.rb:44:82: C: [Corrected] Layout/BlockEndNewline: Expression at 44, 82 should be on its own line.
user&.persisted? ? where(user: user).or(of(Enterprise.managed_by(user))) : none }
^
app/models/customer.rb:44:101: C: Layout/LineLength: Line is too long. [102/100]
user&.persisted? ? where(user: user).or(of(Enterprise.managed_by(user))) : none
^^
app/models/customer.rb:45:1: C: [Corrected] Layout/BlockAlignment: } at 45, 0 is not aligned with ->(user) { at 43, 21 or scope :managed_by, ->(user) { at 43, 2.
}
^
app/models/spree/line_item.rb:53:101: C: Layout/LineLength: Line is too long. [110/100]
attr_accessor :skip_stock_check, :target_shipment # Allows manual skipping of Stock::AvailabilityValidator
^^^^^^^^^^
spec/controllers/admin/order_cycles_controller_spec.rb:38:101: C: Layout/LineLength: Line is too long. [108/100]
it "loads order cycles that closed within the past month, and orders without a close_at date" do
^^^^^^^^
spec/controllers/admin/order_cycles_controller_spec.rb:48:101: C: Layout/LineLength: Line is too long. [111/100]
it "loads order cycles that closed after the specified date, and orders without a close_at date" do
^^^^^^^^^^^
spec/controllers/admin/order_cycles_controller_spec.rb:100:101: C: Layout/LineLength: Line is too long. [125/100]
expect(flash[:error]).to eq "You don't have permission to create an order cycle coordinated by that enterprise"
^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/admin/order_cycles_controller_spec.rb:125:101: C: Layout/LineLength: Line is too long. [101/100]
order_cycle.exchanges.create! sender: distributor, receiver: distributor, incoming: true,
^
spec/controllers/admin/order_cycles_controller_spec.rb:127:101: C: Layout/LineLength: Line is too long. [102/100]
order_cycle.exchanges.create! sender: distributor, receiver: distributor, incoming: false,
^^
spec/controllers/admin/order_cycles_controller_spec.rb:284:101: C: Layout/LineLength: Line is too long. [101/100]
merge(order_cycle: { preferred_product_selection_from_coordinator_inventory_only: true })
^
spec/controllers/admin/order_cycles_controller_spec.rb:311:101: C: Layout/LineLength: Line is too long. [104/100]
create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: hub, incoming: false,
^^^^
spec/controllers/admin/order_cycles_controller_spec.rb:374:101: C: Layout/LineLength: Line is too long. [102/100]
expect(json_response['errors']).to eq 'Hm, something went wrong. No order cycle data found.'
^^
spec/controllers/admin/order_cycles_controller_spec.rb:460:101: C: Layout/LineLength: Line is too long. [176/100]
expect(flash[:error]).to eq 'That order cycle has been selected by a customer and cannot be deleted. To prevent customers from accessing it, please close it instead.'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/admin/order_cycles_controller_spec.rb:470:101: C: Layout/LineLength: Line is too long. [147/100]
expect(flash[:error]).to eq 'That order cycle is linked to a schedule and cannot be deleted. Please unlink or delete the schedule first.'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/api/v0/order_cycles_controller_spec.rb:16:101: C: [Corrected] Layout/LineLength: Line is too long. [106/100]
let!(:product1) { create(:product, name: "Kangaroo", primary_taxon: taxon1, properties: [property1]) }
^^^^^^
spec/controllers/api/v0/order_cycles_controller_spec.rb:17:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 1) spaces for indentation.
create(:product, name: "Kangaroo", primary_taxon: taxon1, properties: [property1])
^
spec/controllers/api/v0/order_cycles_controller_spec.rb:17:3: C: [Corrected] Layout/IndentationWidth: Use 2 (not -2) spaces for indentation.
create(:product, name: "Kangaroo", primary_taxon: taxon1, properties: [property1])
^^
spec/controllers/api/v0/order_cycles_controller_spec.rb:17:85: C: [Corrected] Layout/BlockEndNewline: Expression at 17, 85 should be on its own line.
create(:product, name: "Kangaroo", primary_taxon: taxon1, properties: [property1]) }
^
spec/controllers/api/v0/order_cycles_controller_spec.rb:17:101: C: [Corrected] Layout/LineLength: Line is too long. [106/100]
let!(:product2) { create(:product, name: "Parsnips", primary_taxon: taxon2, properties: [property2]) }
^^^^^^
spec/controllers/api/v0/order_cycles_controller_spec.rb:18:1: C: [Corrected] Layout/BlockAlignment: } at 18, 0 is not aligned with let!(:product1) { at 16, 4.
}
^
spec/controllers/api/v0/order_cycles_controller_spec.rb:19:85: C: [Corrected] Layout/BlockEndNewline: Expression at 19, 85 should be on its own line.
create(:product, name: "Parsnips", primary_taxon: taxon2, properties: [property2]) }
^
spec/controllers/api/v0/order_cycles_controller_spec.rb:20:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 1) spaces for indentation.
create(:product, name: "Parsnips", primary_taxon: taxon2, properties: [property2])
^
spec/controllers/api/v0/order_cycles_controller_spec.rb:20:3: C: [Corrected] Layout/IndentationWidth: Use 2 (not -2) spaces for indentation.
create(:product, name: "Parsnips", primary_taxon: taxon2, properties: [property2])
^^
spec/controllers/api/v0/order_cycles_controller_spec.rb:21:1: C: [Corrected] Layout/BlockAlignment: } at 21, 0 is not aligned with let!(:product2) { at 19, 4.
}
^
spec/controllers/spree/admin/orders_controller_spec.rb:232:101: C: [Corrected] Layout/LineLength: Line is too long. [117/100]
let!(:order_cycle){ create(:simple_order_cycle, distributors: [distributor], variants: [line_item.variant]) }
^^^^^^^^^^^^^^^^^
spec/controllers/spree/admin/orders_controller_spec.rb:233:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 1) spaces for indentation.
create(:simple_order_cycle, distributors: [distributor], variants: [line_item.variant])
^
spec/controllers/spree/admin/orders_controller_spec.rb:233:3: C: [Corrected] Layout/IndentationWidth: Use 2 (not -6) spaces for indentation.
create(:simple_order_cycle, distributors: [distributor], variants: [line_item.variant])
^^^^^^
spec/controllers/spree/admin/orders_controller_spec.rb:233:90: C: [Corrected] Layout/BlockEndNewline: Expression at 233, 90 should be on its own line.
create(:simple_order_cycle, distributors: [distributor], variants: [line_item.variant]) }
^
spec/controllers/spree/admin/orders_controller_spec.rb:234:1: C: [Corrected] Layout/BlockAlignment: } at 234, 0 is not aligned with let!(:order_cycle){ at 232, 8.
}
^
spec/controllers/spree/admin/orders_controller_spec.rb:252:101: C: Layout/LineLength: Line is too long. [109/100]
allow_any_instance_of(Spree::Order).to receive(:ensure_available_shipping_rates).and_return(true)
^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:93:88: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:order_with_totals_and_distribution, :completed, distributor: d,
^
spec/lib/reports/customers_report_spec.rb:93:101: C: [Corrected] Layout/LineLength: Line is too long. [125/100]
create(:order_with_totals_and_distribution, :completed, distributor: d, bill_address: a, shipping_method: sm)
^^^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:94:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
bill_address: a, shipping_method: sm)
^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:94:101: C: Layout/LineLength: Line is too long. [109/100]
bill_address: a, shipping_method: sm)
^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:96:101: C: [Corrected] Layout/LineLength: Line is too long. [125/100]
create(:order_with_totals_and_distribution, :completed, distributor: d, bill_address: a, shipping_method: sm)
^^^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:97:88: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:order_with_totals_and_distribution, :completed, distributor: d,
^
spec/lib/reports/customers_report_spec.rb:98:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
bill_address: a, shipping_method: sm)
^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:98:101: C: Layout/LineLength: Line is too long. [109/100]
bill_address: a, shipping_method: sm)
^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:113:101: C: Layout/LineLength: Line is too long. [118/100]
[d.address.address1, d.address.address2, d.address.city].join(" "),
^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:120:101: C: [Corrected] Layout/LineLength: Line is too long. [129/100]
create(:order_with_totals_and_distribution, :completed, distributor: d2, bill_address: a, shipping_method: sm2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:122:91: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:order_with_totals_and_distribution, :completed, distributor: d2,
^
spec/lib/reports/customers_report_spec.rb:123:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
bill_address: a, shipping_method: sm2)
^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:123:101: C: Layout/LineLength: Line is too long. [112/100]
bill_address: a, shipping_method: sm2)
^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:133:101: C: Layout/LineLength: Line is too long. [120/100]
[d.address.address1, d.address.address2, d.address.city].join(" "),
^^^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:139:101: C: Layout/LineLength: Line is too long. [123/100]
[d2.address.address1, d2.address.address2, d2.address.city].join(" "),
^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:145:101: C: [Corrected] Layout/LineLength: Line is too long. [128/100]
create(:order_with_totals_and_distribution, :completed, distributor: d, bill_address: a, shipping_method: sm2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:148:90: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:order_with_totals_and_distribution, :completed, distributor: d,
^
spec/lib/reports/customers_report_spec.rb:149:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
bill_address: a, shipping_method: sm2)
^^^^^^^^^^^^^^^
spec/lib/reports/customers_report_spec.rb:149:101: C: Layout/LineLength: Line is too long. [112/100]
bill_address: a, shipping_method: sm2)
^^^^^^^^^^^^
spec/migrations/migrate_customer_names_spec.rb:16:101: C: Layout/LineLength: Line is too long. [122/100]
value_type: "boolean", key: "/enterprise/show_customer_names_to_suppliers/#{enterprise1.id}")
^^^^^^^^^^^^^^^^^^^^^^
spec/migrations/migrate_customer_names_spec.rb:18:101: C: Layout/LineLength: Line is too long. [122/100]
value_type: "boolean", key: "/enterprise/show_customer_names_to_suppliers/#{enterprise2.id}")
^^^^^^^^^^^^^^^^^^^^^^
spec/migrations/migrate_customer_names_spec.rb:20:101: C: Layout/LineLength: Line is too long. [122/100]
value_type: "boolean", key: "/enterprise/show_customer_names_to_suppliers/#{enterprise4.id}")
^^^^^^^^^^^^^^^^^^^^^^
spec/models/enterprise_spec.rb:521:101: C: [Corrected] Layout/LineLength: Line is too long. [111/100]
expect(Enterprise.supplying_variant_in([p1.variants.first, p2.variants.first])).to match_array [s1, s2]
^^^^^^^^^^^
spec/models/enterprise_spec.rb:522:1: C: [Corrected] Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
p2.variants.first])).to match_array [s1, s2]
^^^^^^^^^^^^^^^^^
spec/models/order_cycle_spec.rb:207:101: C: Layout/LineLength: Line is too long. [118/100]
expect(oc.variants).to match_array [p0.variants.first, p1.variants.first, p2.variants.first, p2_v, p1_v_visible,
^^^^^^^^^^^^^^^^^^
spec/models/order_cycle_spec.rb:220:101: C: Layout/LineLength: Line is too long. [111/100]
expect(oc.distributed_variants).to match_array [p1.variants.first, p2.variants.first, p2_v, p1_v_visible,
^^^^^^^^^^^
spec/models/product_importer_spec.rb:782:101: C: Layout/LineLength: Line is too long. [101/100]
csv << [" Oats ", "\nPorridge Oats\n", "\r#{enterprise2.name}\r", "\t#{enterprise.name}\t",
^
spec/models/spree/ability_spec.rb:340:69: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
[:admin, :index, :read, :edit, :update, :search, :destroy,
^
spec/models/spree/ability_spec.rb:340:101: C: [Corrected] Layout/LineLength: Line is too long. [101/100]
[:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p1.variants.first
^
spec/models/spree/ability_spec.rb:341:1: C: [Corrected] Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
:delete], for: p1.variants.first
^^^^^^^
spec/models/spree/ability_spec.rb:350:101: C: [Corrected] Layout/LineLength: Line is too long. [108/100]
[:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p_related.variants.first
^^^^^^^^
spec/models/spree/ability_spec.rb:351:69: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
[:admin, :index, :read, :edit, :update, :search, :destroy,
^
spec/models/spree/ability_spec.rb:352:1: C: [Corrected] Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
:delete], for: p_related.variants.first
^^^^^^^
spec/models/spree/ability_spec.rb:379:101: C: [Corrected] Layout/LineLength: Line is too long. [101/100]
[:admin, :index, :read, :create, :edit, :search, :update, :destroy], for: p2.variants.first
^
spec/models/spree/ability_spec.rb:381:68: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
[:admin, :index, :read, :create, :edit, :search, :update,
^
spec/models/spree/ability_spec.rb:382:1: C: [Corrected] Layout/ArrayAlignment: Align the elements of an array literal if they span more than one line.
:destroy], for: p2.variants.first
^^^^^^^^
spec/models/spree/adjustment_spec.rb:339:101: C: Layout/LineLength: Line is too long. [106/100]
create(:tax_rate, included_in_price: true, calculator: ::Calculator::DefaultTax.new, zone: zone,
^^^^^^
spec/models/spree/adjustment_spec.rb:367:101: C: Layout/LineLength: Line is too long. [101/100]
calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0))
^
spec/models/spree/adjustment_spec.rb:428:101: C: Layout/LineLength: Line is too long. [105/100]
context "when enterprise fees inherit their tax_category from the product they are applied to" do
^^^^^
spec/models/spree/adjustment_spec.rb:443:101: C: Layout/LineLength: Line is too long. [101/100]
calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0))
^
spec/models/spree/line_item_spec.rb:208:101: C: Layout/LineLength: Line is too long. [107/100]
expect(LineItem.from_order_cycle(oc_order.order_cycle).first.id).to eq oc_order.line_items.first.id
^^^^^^^
spec/models/spree/line_item_spec.rb:342:101: C: Layout/LineLength: Line is too long. [102/100]
Spree::Variant.find(variant.id).on_hand
^^
spec/models/spree/product_spec.rb:409:74: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:simple_order_cycle, suppliers: [s], distributors: [d1],
^
spec/models/spree/product_spec.rb:409:101: C: [Corrected] Layout/LineLength: Line is too long. [104/100]
create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [p1.variants.first])
^^^^
spec/models/spree/product_spec.rb:410:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
variants: [p1.variants.first])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/spree/product_spec.rb:410:101: C: [Corrected] Layout/LineLength: Line is too long. [104/100]
create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.variants.first])
^^^^
spec/models/spree/product_spec.rb:411:74: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:simple_order_cycle, suppliers: [s], distributors: [d2],
^
spec/models/spree/product_spec.rb:412:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
variants: [p2.variants.first])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/spree/product_spec.rb:486:101: C: [Corrected] Layout/LineLength: Line is too long. [104/100]
create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [p1.variants.first])
^^^^
spec/models/spree/product_spec.rb:487:101: C: [Corrected] Layout/LineLength: Line is too long. [104/100]
create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.variants.first])
^^^^
spec/models/spree/product_spec.rb:488:74: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:simple_order_cycle, suppliers: [s], distributors: [d1],
^
spec/models/spree/product_spec.rb:489:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
variants: [p1.variants.first])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/spree/product_spec.rb:490:74: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:simple_order_cycle, suppliers: [s], distributors: [d2],
^
spec/models/spree/product_spec.rb:491:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
variants: [p2.variants.first])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/spree/product_spec.rb:495:101: C: [Corrected] Layout/LineLength: Line is too long. [102/100]
create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.variants.first])
^^
spec/models/spree/product_spec.rb:499:73: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:simple_order_cycle, suppliers: [s], distributors: [d],
^
spec/models/spree/product_spec.rb:500:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
variants: [p.variants.first])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/spree/variant_spec.rb:356:101: C: Layout/LineLength: Line is too long. [108/100]
it "lists any variants that are not listed as visible=false only for the relevant enterprise" do
^^^^^^^^
spec/models/spree/variant_spec.rb:479:101: C: Layout/LineLength: Line is too long. [108/100]
expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:fees_for).with(variant) {
^^^^^^^^
spec/models/spree/variant_spec.rb:494:101: C: Layout/LineLength: Line is too long. [116/100]
expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:fees_by_type_for).with(variant) {
^^^^^^^^^^^^^^^^
spec/models/spree/variant_spec.rb:704:101: C: Layout/LineLength: Line is too long. [115/100]
expect_any_instance_of(VariantUnits::OptionValueNamer).to receive(:name).exactly(1).times.and_call_original
^^^^^^^^^^^^^^^
spec/requests/api/orders_spec.rb:167:88: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:order_with_line_items, line_items_count: 1, bill_address_id: nil,
^
spec/requests/api/orders_spec.rb:167:101: C: [Corrected] Layout/LineLength: Line is too long. [109/100]
create(:order_with_line_items, line_items_count: 1, bill_address_id: nil, ship_address_id: nil)
^^^^^^^^^
spec/requests/api/orders_spec.rb:168:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
ship_address_id: nil)
^^^^^^^^^^^^^^^^^^^^
spec/services/products_renderer_spec.rb:91:101: C: Layout/LineLength: Line is too long. [101/100]
{ q: { with_properties: [property_organic.id] } })
^
spec/services/products_renderer_spec.rb:100:101: C: Layout/LineLength: Line is too long. [101/100]
{ q: { with_properties: [property_organic.id] } })
^
spec/services/products_renderer_spec.rb:118:101: C: Layout/LineLength: Line is too long. [101/100]
{ q: { with_properties: [property_organic.id] } })
^
spec/support/request/web_helper.rb:96:84: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
tomselect_wrapper.find(:css, '.ts-dropdown.multi .ts-dropdown-content .option',
^
spec/support/request/web_helper.rb:96:101: C: [Corrected] Layout/LineLength: Line is too long. [102/100]
tomselect_wrapper.find(:css, '.ts-dropdown.multi .ts-dropdown-content .option', text: value).click
^^
spec/support/request/web_helper.rb:97:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
text: value).click
^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:29:101: C: [Corrected] Layout/LineLength: Line is too long. [197/100]
let!(:tax_rate2) { create(:tax_rate, name: "TVA 20%", amount: 0.2, zone: default_tax_zone, included_in_price: true, tax_category: tax_category_included, calculator: Calculator::DefaultTax.new ) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:30:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 1) spaces for indentation.
create(:tax_rate, name: "TVA 20%", amount: 0.2, zone: default_tax_zone, included_in_price: true,
^
spec/system/admin/adjustments_spec.rb:30:3: C: [Corrected] Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
create(:tax_rate, name: "TVA 20%", amount: 0.2, zone: default_tax_zone, included_in_price: true,
spec/system/admin/adjustments_spec.rb:30:98: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
create(:tax_rate, name: "TVA 20%", amount: 0.2, zone: default_tax_zone, included_in_price: true,
^
spec/system/admin/adjustments_spec.rb:30:101: C: [Corrected] Layout/LineLength: Line is too long. [177/100]
create(:tax_rate, name: "TVA 20%", amount: 0.2, zone: default_tax_zone, included_in_price: true, tax_category: tax_category_included, calculator: Calculator::DefaultTax.new ) }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:30:177: C: [Corrected] Layout/BlockEndNewline: Expression at 30, 177 should be on its own line.
create(:tax_rate, name: "TVA 20%", amount: 0.2, zone: default_tax_zone, included_in_price: true, tax_category: tax_category_included, calculator: Calculator::DefaultTax.new ) }
^
spec/system/admin/adjustments_spec.rb:31:1: C: [Corrected] Layout/HashAlignment: Align the keys of a hash literal if they span more than one line.
tax_category: tax_category_included, calculator: Calculator::DefaultTax.new )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:32:1: C: [Corrected] Layout/BlockAlignment: } at 32, 0 is not aligned with let!(:tax_rate2) { at 29, 2.
}
^
spec/system/admin/adjustments_spec.rb:41:101: C: Layout/LineLength: Line is too long. [134/100]
shared_examples "when the enable_localized_number preference" do |adjustment_label, adjustment_amount, tax_category, tax, tax_total|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:67:101: C: [Corrected] Layout/LineLength: Line is too long. [117/100]
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "TVA 20%", "$0.33", "$-1.67"
^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:68:100: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "TVA 20%",
^
spec/system/admin/adjustments_spec.rb:69:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"$0.33", "$-1.67"
^^^^^^^
spec/system/admin/adjustments_spec.rb:71:101: C: [Corrected] Layout/LineLength: Line is too long. [120/100]
it_behaves_like "when the enable_localized_number preference", "Late fee", "100", "TVA 20%", "$-16.67", "$83.33"
^^^^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:73:90: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Late fee", "100",
^
spec/system/admin/adjustments_spec.rb:74:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"TVA 20%", "$-16.67", "$83.33"
^^^^^^^^^
spec/system/admin/adjustments_spec.rb:77:101: C: [Corrected] Layout/LineLength: Line is too long. [113/100]
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "GST", "$10.00", "$8.00"
^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:80:96: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "GST",
^
spec/system/admin/adjustments_spec.rb:81:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"$10.00", "$8.00"
^^^^^^^^
spec/system/admin/adjustments_spec.rb:81:101: C: [Corrected] Layout/LineLength: Line is too long. [113/100]
it_behaves_like "when the enable_localized_number preference", "Late fee", "110", "GST", "$10.00", "$120"
^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:85:97: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Late fee", "110", "GST",
^
spec/system/admin/adjustments_spec.rb:86:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"$10.00", "$120"
^^^^^^^^
spec/system/admin/adjustments_spec.rb:93:101: C: [Corrected] Layout/LineLength: Line is too long. [117/100]
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "TVA 20%", "$0.33", "$-1.67"
^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:97:101: C: [Corrected] Layout/LineLength: Line is too long. [120/100]
it_behaves_like "when the enable_localized_number preference", "Late fee", "100", "TVA 20%", "$-16.67", "$83.33"
^^^^^^^^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:98:100: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "TVA 20%",
^
spec/system/admin/adjustments_spec.rb:99:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"$0.33", "$-1.67"
^^^^^^^
spec/system/admin/adjustments_spec.rb:103:90: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Late fee", "100",
^
spec/system/admin/adjustments_spec.rb:103:101: C: [Corrected] Layout/LineLength: Line is too long. [113/100]
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "GST", "$10.00", "$8.00"
^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:104:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"TVA 20%", "$-16.67", "$83.33"
^^^^^^^^^
spec/system/admin/adjustments_spec.rb:107:101: C: [Corrected] Layout/LineLength: Line is too long. [113/100]
it_behaves_like "when the enable_localized_number preference", "Late fee", "110", "GST", "$10.00", "$120"
^^^^^^^^^^^^^
spec/system/admin/adjustments_spec.rb:110:96: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Discount", "-2", "GST",
^
spec/system/admin/adjustments_spec.rb:111:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"$10.00", "$8.00"
^^^^^^^^
spec/system/admin/adjustments_spec.rb:115:97: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
it_behaves_like "when the enable_localized_number preference", "Late fee", "110", "GST",
^
spec/system/admin/adjustments_spec.rb:116:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
"$10.00", "$120"
^^^^^^^^
spec/system/admin/bulk_order_management_spec.rb:268:101: C: Layout/LineLength: Line is too long. [105/100]
text: "#{o1.bill_address.last_name}, #{o1.bill_address.first_name}"
^^^^^
spec/system/admin/bulk_order_management_spec.rb:1036:101: C: Layout/LineLength: Line is too long. [147/100]
expect(page).to have_content "This operation will result in one or more empty orders, which will be cancelled. Do you wish to proceed?"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/bulk_order_management_spec.rb:1060:101: C: Layout/LineLength: Line is too long. [138/100]
it "the user can confirm + wants to send email confirmation : line item is then deleted, order is canceled and email is sent" do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/bulk_order_management_spec.rb:1072:101: C: Layout/LineLength: Line is too long. [134/100]
it "the user can confirm + uncheck the restock option: line item is then deleted and order is canceled without retocking" do
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/customers_spec.rb:40:101: C: Layout/LineLength: Line is too long. [126/100]
managed_distributor2.name], without_options: [unmanaged_distributor.name]
^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_cycles/simple_spec.rb:346:101: C: Layout/LineLength: Line is too long. [101/100]
with_options: [schedule_of_other_managed_distributor.name]
^
spec/system/admin/order_cycles/simple_spec.rb:623:101: C: Layout/LineLength: Line is too long. [121/100]
value: Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0).strftime("%F %T %z"), visible: false
^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_cycles/simple_spec.rb:625:101: C: Layout/LineLength: Line is too long. [120/100]
value: Time.zone.local(2040, 10, 24, 17, 0o0, 0o0).strftime("%F %T %z"), visible: false
^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_cycles/simple_spec.rb:733:101: C: Layout/LineLength: Line is too long. [121/100]
value: Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0).strftime("%F %T %z"), visible: false
^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_cycles/simple_spec.rb:735:101: C: Layout/LineLength: Line is too long. [120/100]
value: Time.zone.local(2040, 10, 24, 17, 0o0, 0o0).strftime("%F %T %z"), visible: false
^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_spec.rb:598:101: C: [Corrected] Layout/LineLength: Line is too long. [101/100]
expect(page).to have_link "Resend Confirmation", href: spree.resend_admin_order_path(order)
^
spec/system/admin/order_spec.rb:599:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
href: spree.resend_admin_order_path(order)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_spec.rb:616:101: C: [Corrected] Layout/LineLength: Line is too long. [105/100]
expect(page).to have_link "Cancel Order", href: spree.fire_admin_order_path(order, e: 'cancel')
^^^^^
spec/system/admin/order_spec.rb:618:1: C: [Corrected] Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.
href: spree.fire_admin_order_path(order, e: 'cancel')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/orders_spec.rb:259:101: C: Layout/LineLength: Line is too long. [109/100]
distributor: distributor2, bill_address_id: nil, ship_address_id: nil)
^^^^^^^^^
spec/system/admin/product_import_spec.rb:573:101: C: Layout/LineLength: Line is too long. [106/100]
expect(page).to have_content "line 4: Cabbage - On_hand incorrect value - On_demand incorrect value"
^^^^^^
spec/system/admin/product_import_spec.rb:574:101: C: Layout/LineLength: Line is too long. [108/100]
expect(page).to have_content "line 5: Aubergine - On_hand incorrect value - On_demand incorrect value"
^^^^^^^^
spec/system/admin/product_import_spec.rb:583:101: C: Layout/LineLength: Line is too long. [102/100]
csv << ["name", "producer", "category", "on_hand", "price", "on_demand", "units", "unit_type",
^^
spec/system/admin/product_import_spec.rb:585:101: C: Layout/LineLength: Line is too long. [106/100]
csv << ["Beans", "User Enterprise", "Vegetables", "invalid", "3.50", "1", "0.5", "g", "Small Bag",
^^^^^^
spec/system/admin/product_import_spec.rb:587:101: C: Layout/LineLength: Line is too long. [103/100]
csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6", "invalid", "5", "kg", "Big Bag",
^^^
spec/system/admin/product_import_spec.rb:589:101: C: Layout/LineLength: Line is too long. [106/100]
csv << ["Cabbage", "User Enterprise", "Vegetables", "invalid", "1.5", "invalid", "1", "kg", "Bag",
^^^^^^
spec/system/admin/product_import_spec.rb:591:101: C: Layout/LineLength: Line is too long. [102/100]
csv << ["Aubergine", "User Enterprise", "Vegetables", nil, "1.5", "invalid", "1", "kg", "Bag",
^^
spec/system/admin/product_import_spec.rb:607:101: C: Layout/LineLength: Line is too long. [114/100]
expect(page).to have_content "line 4: Cabbage ( Bag ) - On_hand incorrect value - On_demand incorrect value"
^^^^^^^^^^^^^^
spec/system/admin/product_import_spec.rb:608:101: C: Layout/LineLength: Line is too long. [116/100]
expect(page).to have_content "line 5: Aubergine ( Bag ) - On_hand incorrect value - On_demand incorrect value"
^^^^^^^^^^^^^^^^
spec/system/admin/product_import_spec.rb:617:101: C: Layout/LineLength: Line is too long. [102/100]
csv << ["name", "producer", "category", "on_hand", "price", "on_demand", "units", "unit_type",
^^
spec/system/admin/product_import_spec.rb:619:101: C: Layout/LineLength: Line is too long. [101/100]
csv << ["Beans", "User Enterprise", "Vegetables", "-1", "3.50", "1", "500", "g", "Small Bag",
^
spec/system/admin/product_import_spec.rb:641:101: C: Layout/LineLength: Line is too long. [114/100]
expect(page).to have_content "line 4: Cabbage ( Bag ) - On_hand incorrect value - On_demand incorrect value"
^^^^^^^^^^^^^^
spec/system/admin/product_import_spec.rb:642:101: C: Layout/LineLength: Line is too long. [116/100]
expect(page).to have_content "line 5: Aubergine ( Bag ) - On_hand incorrect value - On_demand incorrect value"
^^^^^^^^^^^^^^^^
spec/system/consumer/shopping/cart_spec.rb:147:101: C: Layout/LineLength: Line is too long. [101/100]
preferred_unit_from_list: "kg"),
^
spec/system/consumer/shopping/products_spec.rb:98:101: C: Layout/LineLength: Line is too long. [113/100]
"<script>alert('Dangerous!');</script>", truncate: false)
^^^^^^^^^^^^^
1478 files inspected, 173 offenses detected, 106 offenses corrected
927 lines
36 KiB
Ruby
927 lines
36 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
describe Enterprise do
|
|
describe "sending emails" do
|
|
describe "on creation" do
|
|
let!(:user) { create(:user) }
|
|
let!(:enterprise) { create(:enterprise, owner: user) }
|
|
|
|
it "sends a welcome email" do
|
|
expect do
|
|
create(:enterprise, owner: user)
|
|
end.to enqueue_job ActionMailer::MailDeliveryJob
|
|
|
|
expect(enqueued_jobs.last.to_s).to match "welcome"
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "associations" do
|
|
it { is_expected.to belong_to(:owner) }
|
|
it { is_expected.to have_many(:supplied_products) }
|
|
it { is_expected.to have_many(:distributed_orders) }
|
|
it { is_expected.to belong_to(:address) }
|
|
it { is_expected.to belong_to(:business_address) }
|
|
it { is_expected.to have_many(:vouchers) }
|
|
|
|
it "destroys enterprise roles upon its own demise" do
|
|
e = create(:enterprise)
|
|
u = create(:user)
|
|
u.enterprise_roles.build(enterprise: e).save!
|
|
|
|
role = e.enterprise_roles.first
|
|
e.destroy
|
|
expect(EnterpriseRole.where(id: role.id)).to be_empty
|
|
end
|
|
|
|
xit "destroys supplied products upon destroy" do
|
|
s = create(:supplier_enterprise)
|
|
p = create(:simple_product, supplier: s)
|
|
|
|
s.destroy
|
|
|
|
expect(Spree::Product.where(id: p.id)).to be_empty
|
|
end
|
|
|
|
it "destroys relationships upon destroy" do
|
|
e = create(:enterprise)
|
|
e_other = create(:enterprise)
|
|
er1 = create(:enterprise_relationship, parent: e, child: e_other)
|
|
er2 = create(:enterprise_relationship, child: e, parent: e_other)
|
|
|
|
e.destroy
|
|
|
|
expect(EnterpriseRelationship.where(id: [er1, er2])).to be_empty
|
|
end
|
|
|
|
describe "relationships to other enterprises" do
|
|
let(:e) { create(:distributor_enterprise) }
|
|
let(:p) { create(:supplier_enterprise) }
|
|
let(:c) { create(:distributor_enterprise) }
|
|
|
|
let!(:er1) { create(:enterprise_relationship, parent_id: p.id, child_id: e.id) }
|
|
let!(:er2) { create(:enterprise_relationship, parent_id: e.id, child_id: c.id) }
|
|
|
|
it "finds relatives" do
|
|
expect(e.relatives).to match_array [p, c]
|
|
end
|
|
|
|
it "finds relatives_including_self" do
|
|
expect(e.relatives_including_self).to include e
|
|
end
|
|
|
|
it "scopes relatives to visible distributors" do
|
|
enterprise = build_stubbed(:distributor_enterprise)
|
|
expect(enterprise).to receive(:relatives_including_self).and_return(relatives = [])
|
|
expect(relatives).to receive(:is_distributor).and_return relatives
|
|
enterprise.distributors
|
|
end
|
|
|
|
it "scopes relatives to visible producers" do
|
|
enterprise = build_stubbed(:distributor_enterprise)
|
|
expect(enterprise).to receive(:relatives_including_self).and_return(relatives = [])
|
|
expect(relatives).to receive(:is_primary_producer).and_return relatives
|
|
enterprise.suppliers
|
|
end
|
|
end
|
|
|
|
describe "ownership" do
|
|
let(:u1) { create(:user) }
|
|
let(:u2) { create(:user) }
|
|
let!(:e) { create(:enterprise, owner: u1 ) }
|
|
|
|
it "adds new owner to list of managers" do
|
|
expect(e.owner).to eq u1
|
|
expect(e.users).to include u1
|
|
expect(e.users).to_not include u2
|
|
e.owner = u2
|
|
e.save!
|
|
e.reload
|
|
expect(e.owner).to eq u2
|
|
expect(e.users).to include u1, u2
|
|
end
|
|
|
|
it "validates ownership limit" do
|
|
expect(u1.enterprise_limit).to be 5
|
|
expect(u1.owned_enterprises.reload).to eq [e]
|
|
4.times { create(:enterprise, owner: u1) }
|
|
e2 = create(:enterprise, owner: u2)
|
|
expect {
|
|
e2.owner = u1
|
|
e2.save!
|
|
}.to raise_error ActiveRecord::RecordInvalid,
|
|
"Validation failed: #{u1.email} is not permitted " \
|
|
"to own any more enterprises (limit is 5)."
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "validations" do
|
|
it { is_expected.to validate_presence_of(:name) }
|
|
it do
|
|
create(:distributor_enterprise)
|
|
is_expected.to validate_uniqueness_of(:permalink)
|
|
end
|
|
|
|
it "requires an owner" do
|
|
enterprise = build_stubbed(:enterprise, owner: nil)
|
|
expect(enterprise).not_to be_valid
|
|
expect(enterprise.errors[:owner].first).to eq "can't be blank"
|
|
end
|
|
|
|
describe "name uniqueness" do
|
|
let(:owner) { create(:user, email: 'owner@example.com') }
|
|
let!(:enterprise) { create(:enterprise, name: 'Enterprise', owner: owner) }
|
|
|
|
it "prevents duplicate names for new records" do
|
|
e = Enterprise.new name: enterprise.name
|
|
expect(e).to_not be_valid
|
|
expect(e.errors[:name].first).to include enterprise_name_error(owner.email)
|
|
end
|
|
|
|
it "prevents duplicate names for existing records" do
|
|
e = create(:enterprise, name: 'foo')
|
|
e.name = enterprise.name
|
|
expect(e).to_not be_valid
|
|
expect(e.errors[:name].first).to include enterprise_name_error(owner.email)
|
|
end
|
|
|
|
it "does not prohibit the saving of an enterprise with no name clash" do
|
|
expect(enterprise).to be_valid
|
|
end
|
|
|
|
it "sets the enterprise contact to the owner by default" do
|
|
expect(enterprise.contact).to eq enterprise.owner
|
|
end
|
|
end
|
|
|
|
describe "prevent a wrong instagram link pattern" do
|
|
it "invalidates the instagram attribute https://facebook.com/user" do
|
|
e = build(:enterprise, instagram: 'https://facebook.com/user')
|
|
expect(e).to_not be_valid
|
|
end
|
|
|
|
it "invalidates the instagram attribute tagram.com/user" do
|
|
e = build(:enterprise, instagram: 'tagram.com/user')
|
|
expect(e).to_not be_valid
|
|
end
|
|
|
|
it "invalidates the instagram attribute https://instagram.com/user/preferences" do
|
|
e = build(:enterprise, instagram: 'https://instagram.com/user/preferences')
|
|
expect(e).to_not be_valid
|
|
end
|
|
|
|
it "invalidates the instagram attribute https://www.instagram.com/p/Cpg4McNPyJA/" do
|
|
e = build(:enterprise, instagram: 'https://www.instagram.com/p/Cpg4McNPyJA/')
|
|
expect(e).to_not be_valid
|
|
end
|
|
|
|
it "invalidates the instagram attribute https://instagram.com/user-user" do
|
|
e = build(:enterprise, instagram: 'https://instagram.com/user-user')
|
|
expect(e).to_not be_valid
|
|
end
|
|
end
|
|
|
|
describe "Verify accepted instagram url pattern" do
|
|
it "validates empty instagram attribute" do
|
|
e = build(:enterprise, instagram: '')
|
|
expect(e).to be_valid
|
|
expect(e.instagram).to eq ""
|
|
end
|
|
|
|
it "validates the instagram attribute @my_user" do
|
|
e = build(:enterprise, instagram: '@my_user')
|
|
expect(e).to be_valid
|
|
expect(e.instagram).to eq "my_user"
|
|
end
|
|
|
|
it "validates the instagram attribute user" do
|
|
e = build(:enterprise, instagram: 'user')
|
|
expect(e).to be_valid
|
|
expect(e.instagram).to eq "user"
|
|
end
|
|
|
|
it "validates the instagram attribute my_www5.example" do
|
|
e = build(:enterprise, instagram: 'my_www5.example')
|
|
expect(e).to be_valid
|
|
expect(e.instagram).to eq "my_www5.example"
|
|
end
|
|
|
|
it "validates the instagram attribute http://instagram.com/user" do
|
|
e = build(:enterprise, instagram: 'http://instagram.com/user')
|
|
expect(e).to be_valid
|
|
expect(e.instagram).to eq "user"
|
|
end
|
|
|
|
it "validates the instagram attribute https://www.instagram.com/user" do
|
|
e = build(:enterprise, instagram: 'https://www.instagram.com/user')
|
|
expect(e).to be_valid
|
|
expect(e.instagram).to eq "user"
|
|
end
|
|
|
|
it "validates the instagram attribute instagram.com/@user" do
|
|
e = build(:enterprise, instagram: 'instagram.com/@user')
|
|
expect(e).to be_valid
|
|
expect(e.instagram).to eq "user"
|
|
end
|
|
|
|
it "validates the instagram attribute Https://www.Instagram.com/@User" do
|
|
e = build(:enterprise, instagram: 'Https://www.Instagram.com/@User')
|
|
expect(e).to be_valid
|
|
expect(e.instagram).to eq "user"
|
|
end
|
|
|
|
it "validates the instagram attribute instagram.com/user" do
|
|
e = build(:enterprise, instagram: 'instagram.com/user')
|
|
expect(e).to be_valid
|
|
expect(e.instagram).to eq "user"
|
|
end
|
|
|
|
it "renders the expected pattern" do
|
|
e = build(:enterprise, instagram: 'instagram.com/user')
|
|
expect(e.instagram).to eq "user"
|
|
end
|
|
end
|
|
|
|
describe "preferred_shopfront_taxon_order" do
|
|
it "empty strings are valid" do
|
|
enterprise = build(:enterprise, preferred_shopfront_taxon_order: "")
|
|
expect(enterprise).to be_valid
|
|
end
|
|
|
|
it "a single integer is valid" do
|
|
enterprise = build(:enterprise, preferred_shopfront_taxon_order: "11")
|
|
expect(enterprise).to be_valid
|
|
end
|
|
|
|
it "comma delimited integers are valid" do
|
|
enterprise = build(:enterprise, preferred_shopfront_taxon_order: "1,2,3")
|
|
expect(enterprise).to be_valid
|
|
enterprise = build(:enterprise, preferred_shopfront_taxon_order: "1,22,333")
|
|
expect(enterprise).to be_valid
|
|
end
|
|
|
|
it "commas at the beginning and end are disallowed" do
|
|
enterprise = build(:enterprise, preferred_shopfront_taxon_order: ",1,2,3")
|
|
expect(enterprise).to be_invalid
|
|
enterprise = build(:enterprise, preferred_shopfront_taxon_order: "1,2,3,")
|
|
expect(enterprise).to be_invalid
|
|
end
|
|
|
|
it "any other characters are invalid" do
|
|
enterprise = build(:enterprise, preferred_shopfront_taxon_order: "a1,2,3")
|
|
expect(enterprise).to be_invalid
|
|
enterprise = build(:enterprise, preferred_shopfront_taxon_order: ".1,2,3")
|
|
expect(enterprise).to be_invalid
|
|
enterprise = build(:enterprise, preferred_shopfront_taxon_order: " 1,2,3")
|
|
expect(enterprise).to be_invalid
|
|
end
|
|
end
|
|
|
|
describe "preferred_shopfront_producer_order" do
|
|
it "empty strings are valid" do
|
|
enterprise = build(:enterprise, preferred_shopfront_producer_order: "")
|
|
expect(enterprise).to be_valid
|
|
end
|
|
|
|
it "a single integer is valid" do
|
|
enterprise = build(:enterprise, preferred_shopfront_producer_order: "11")
|
|
expect(enterprise).to be_valid
|
|
end
|
|
|
|
it "comma delimited integers are valid" do
|
|
enterprise = build(:enterprise, preferred_shopfront_producer_order: "1,2,3")
|
|
expect(enterprise).to be_valid
|
|
enterprise = build(:enterprise, preferred_shopfront_producer_order: "1,22,333")
|
|
expect(enterprise).to be_valid
|
|
end
|
|
|
|
it "commas at the beginning and end are disallowed" do
|
|
enterprise = build(:enterprise, preferred_shopfront_producer_order: ",1,2,3")
|
|
expect(enterprise).to be_invalid
|
|
enterprise = build(:enterprise, preferred_shopfront_producer_order: "1,2,3,")
|
|
expect(enterprise).to be_invalid
|
|
end
|
|
|
|
it "any other characters are invalid" do
|
|
enterprise = build(:enterprise, preferred_shopfront_producer_order: "a1,2,3")
|
|
expect(enterprise).to be_invalid
|
|
enterprise = build(:enterprise, preferred_shopfront_producer_order: ".1,2,3")
|
|
expect(enterprise).to be_invalid
|
|
enterprise = build(:enterprise, preferred_shopfront_producer_order: " 1,2,3")
|
|
expect(enterprise).to be_invalid
|
|
end
|
|
end
|
|
|
|
describe "white label logo link" do
|
|
before do
|
|
# validate white_label_logo_link only if white_label_logo is present
|
|
allow_any_instance_of(Enterprise).to receive(:white_label_logo).and_return(true)
|
|
end
|
|
|
|
it "validates the white_label_logo_link attribute" do
|
|
e = build(:enterprise, white_label_logo_link: 'http://www.example.com')
|
|
expect(e).to be_valid
|
|
expect(e.white_label_logo_link).to eq "http://www.example.com"
|
|
end
|
|
|
|
it "adds http:// to the white_label_logo_link attribute if it is missing" do
|
|
e = build(:enterprise, white_label_logo_link: 'www.example.com')
|
|
expect(e).to be_valid
|
|
expect(e.white_label_logo_link).to eq "http://www.example.com"
|
|
end
|
|
|
|
it "ignores whitespace around the URL form copying and pasting" do
|
|
e = build(:enterprise, white_label_logo_link: ' www.example.com ')
|
|
expect(e).to be_valid
|
|
expect(e.white_label_logo_link).to eq "http://www.example.com"
|
|
end
|
|
|
|
it "does not validate if URL is invalid and can't be infered" do
|
|
e = build(:enterprise, white_label_logo_link: 'with spaces')
|
|
expect(e).to be_invalid
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "callbacks" do
|
|
it "restores permalink to original value when it is changed and invalid" do
|
|
e1 = create(:enterprise, permalink: "taken")
|
|
e2 = create(:enterprise, permalink: "not_taken")
|
|
e2.permalink = "taken"
|
|
e2.save
|
|
expect(e2.reload.permalink).to eq "not_taken"
|
|
end
|
|
end
|
|
|
|
describe "scopes" do
|
|
describe 'visible' do
|
|
it 'find visible enterprises' do
|
|
d1 = create(:distributor_enterprise, visible: false)
|
|
s1 = create(:supplier_enterprise)
|
|
expect(Enterprise.visible).to eq([s1])
|
|
end
|
|
end
|
|
|
|
describe "activated" do
|
|
let!(:unconfirmed_user) { create(:user, confirmed_at: nil, enterprise_limit: 2) }
|
|
let!(:inactive_enterprise) { create(:enterprise, sells: "unspecified") }
|
|
let!(:active_enterprise) { create(:enterprise, sells: "none") }
|
|
|
|
it "finds enterprises that have a sells property other than 'unspecified'" do
|
|
activated_enterprises = Enterprise.activated
|
|
expect(activated_enterprises).to include active_enterprise
|
|
expect(activated_enterprises).to_not include inactive_enterprise
|
|
end
|
|
end
|
|
|
|
describe "ready_for_checkout" do
|
|
let!(:e) { create(:enterprise) }
|
|
|
|
it "does not show enterprises with no payment methods" do
|
|
create(:shipping_method, distributors: [e])
|
|
expect(Enterprise.ready_for_checkout).not_to include e
|
|
end
|
|
|
|
it "does not show enterprises with no shipping methods" do
|
|
create(:payment_method, distributors: [e])
|
|
expect(Enterprise.ready_for_checkout).not_to include e
|
|
end
|
|
|
|
it "does not show enterprises with unavailable payment methods" do
|
|
create(:shipping_method, distributors: [e])
|
|
create(:payment_method, distributors: [e], active: false)
|
|
expect(Enterprise.ready_for_checkout).not_to include e
|
|
end
|
|
|
|
it "does not show enterprises which only have backend shipping methods" do
|
|
create(:shipping_method, distributors: [e],
|
|
display_on: Spree::ShippingMethod::DISPLAY_ON_OPTIONS[:back_end])
|
|
create(:payment_method, distributors: [e])
|
|
expect(Enterprise.ready_for_checkout).not_to include e
|
|
end
|
|
|
|
it "shows enterprises with available payment and shipping methods" do
|
|
create(:shipping_method, distributors: [e])
|
|
create(:payment_method, distributors: [e])
|
|
expect(Enterprise.ready_for_checkout).to include e
|
|
end
|
|
end
|
|
|
|
describe "not_ready_for_checkout" do
|
|
let!(:e) { create(:enterprise) }
|
|
|
|
it "shows enterprises with no payment methods" do
|
|
create(:shipping_method, distributors: [e])
|
|
expect(Enterprise.not_ready_for_checkout).to include e
|
|
end
|
|
|
|
it "shows enterprises with no shipping methods" do
|
|
create(:payment_method, distributors: [e])
|
|
expect(Enterprise.not_ready_for_checkout).to include e
|
|
end
|
|
|
|
it "shows enterprises with unavailable payment methods" do
|
|
create(:shipping_method, distributors: [e])
|
|
create(:payment_method, distributors: [e], active: false)
|
|
expect(Enterprise.not_ready_for_checkout).to include e
|
|
end
|
|
|
|
it "shows enterprises which only have backend shipping methods" do
|
|
create(:shipping_method, distributors: [e],
|
|
display_on: Spree::ShippingMethod::DISPLAY_ON_OPTIONS[:back_end])
|
|
create(:payment_method, distributors: [e])
|
|
expect(Enterprise.not_ready_for_checkout).to include e
|
|
end
|
|
|
|
it "does not show enterprises with available payment and shipping methods" do
|
|
create(:shipping_method, distributors: [e])
|
|
create(:payment_method, distributors: [e])
|
|
expect(Enterprise.not_ready_for_checkout).not_to include e
|
|
end
|
|
end
|
|
|
|
describe "#ready_for_checkout?" do
|
|
let!(:e) { create(:enterprise) }
|
|
|
|
it "returns false for enterprises with no payment methods" do
|
|
create(:shipping_method, distributors: [e])
|
|
expect(e.reload).not_to be_ready_for_checkout
|
|
end
|
|
|
|
it "returns false for enterprises with no shipping methods" do
|
|
create(:payment_method, distributors: [e])
|
|
expect(e.reload).not_to be_ready_for_checkout
|
|
end
|
|
|
|
it "returns false for enterprises with unavailable payment methods" do
|
|
create(:shipping_method, distributors: [e])
|
|
create(:payment_method, distributors: [e], active: false)
|
|
expect(e.reload).not_to be_ready_for_checkout
|
|
end
|
|
|
|
it "returns false for enterprises which only have backend shipping methods" do
|
|
create(:shipping_method, distributors: [e],
|
|
display_on: Spree::ShippingMethod::DISPLAY_ON_OPTIONS[:back_end])
|
|
create(:payment_method, distributors: [e])
|
|
expect(e.reload).not_to be_ready_for_checkout
|
|
end
|
|
|
|
it "returns true for enterprises with available payment and shipping methods" do
|
|
create(:shipping_method, distributors: [e])
|
|
create(:payment_method, distributors: [e])
|
|
expect(e.reload).to be_ready_for_checkout
|
|
end
|
|
|
|
it "returns false for enterprises with payment methods that are available but not configured
|
|
correctly" do
|
|
create(:shipping_method, distributors: [e])
|
|
create(:stripe_sca_payment_method, distributors: [e])
|
|
expect(e.reload).not_to be_ready_for_checkout
|
|
end
|
|
end
|
|
|
|
describe "distributors_with_active_order_cycles" do
|
|
it "finds active distributors by order cycles" do
|
|
s = create(:supplier_enterprise)
|
|
d = create(:distributor_enterprise)
|
|
p = create(:product)
|
|
create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.variants.first])
|
|
expect(Enterprise.distributors_with_active_order_cycles).to eq([d])
|
|
end
|
|
|
|
it "should not find inactive distributors by order cycles" do
|
|
s = create(:supplier_enterprise)
|
|
d = create(:distributor_enterprise)
|
|
p = create(:product)
|
|
create(:simple_order_cycle, orders_open_at: 10.days.from_now,
|
|
orders_close_at: 17.days.from_now, suppliers: [s],
|
|
distributors: [d], variants: [p.variants.first])
|
|
expect(Enterprise.distributors_with_active_order_cycles).not_to include d
|
|
end
|
|
end
|
|
|
|
describe "supplying_variant_in" do
|
|
it "finds producers by supply of variant" do
|
|
s = create(:supplier_enterprise)
|
|
p = create(:simple_product, supplier: s)
|
|
v = create(:variant, product: p)
|
|
|
|
expect(Enterprise.supplying_variant_in([v])).to eq([s])
|
|
end
|
|
|
|
it "returns multiple enterprises when given multiple variants" do
|
|
s1 = create(:supplier_enterprise)
|
|
s2 = create(:supplier_enterprise)
|
|
p1 = create(:simple_product, supplier: s1)
|
|
p2 = create(:simple_product, supplier: s2)
|
|
|
|
expect(Enterprise.supplying_variant_in([p1.variants.first,
|
|
p2.variants.first])).to match_array [s1, s2]
|
|
end
|
|
|
|
it "does not return duplicates" do
|
|
s = create(:supplier_enterprise)
|
|
p1 = create(:simple_product, supplier: s)
|
|
p2 = create(:simple_product, supplier: s)
|
|
|
|
expect(Enterprise.supplying_variant_in([p1.variants.first, p2.variants.first])).to eq([s])
|
|
end
|
|
end
|
|
|
|
describe "distributing_products" do
|
|
let(:distributor) { create(:distributor_enterprise) }
|
|
let(:product) { create(:product) }
|
|
|
|
it "returns enterprises distributing via an order cycle" do
|
|
order_cycle = create(:simple_order_cycle, distributors: [distributor],
|
|
variants: [product.variants.first])
|
|
expect(Enterprise.distributing_products(product.id)).to eq([distributor])
|
|
end
|
|
|
|
it "does not return duplicate enterprises" do
|
|
another_product = create(:product)
|
|
order_cycle = create(:simple_order_cycle, distributors: [distributor],
|
|
variants: [product.variants.first,
|
|
another_product.variants.first])
|
|
expect(Enterprise.distributing_products([product.id,
|
|
another_product.id])).to eq([distributor])
|
|
end
|
|
end
|
|
|
|
describe "managed_by" do
|
|
it "shows only enterprises for given user" do
|
|
user = create(:user)
|
|
user.spree_roles = []
|
|
e1 = create(:enterprise)
|
|
e2 = create(:enterprise)
|
|
e1.enterprise_roles.build(user: user).save
|
|
|
|
enterprises = Enterprise.managed_by user
|
|
expect(enterprises.count).to eq(1)
|
|
expect(enterprises).to include e1
|
|
end
|
|
|
|
it "shows all enterprises for admin user" do
|
|
user = create(:admin_user)
|
|
e1 = create(:enterprise)
|
|
e2 = create(:enterprise)
|
|
|
|
enterprises = Enterprise.managed_by user
|
|
expect(enterprises.count).to eq(2)
|
|
expect(enterprises).to include e1
|
|
expect(enterprises).to include e2
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "callbacks" do
|
|
describe "after creation" do
|
|
let(:owner) { create(:user, enterprise_limit: 10) }
|
|
let(:hub1) { create(:distributor_enterprise, owner: owner) }
|
|
let(:hub2) { create(:distributor_enterprise, owner: owner) }
|
|
let(:hub3) { create(:distributor_enterprise, owner: owner) }
|
|
let(:producer1) { create(:supplier_enterprise, owner: owner) }
|
|
let(:producer2) { create(:supplier_enterprise, owner: owner) }
|
|
|
|
describe "when a producer is created" do
|
|
before do
|
|
hub1
|
|
hub2
|
|
end
|
|
|
|
it "creates links from the new producer to all hubs owned by the same user, " \
|
|
"granting add_to_order_cycle and create_variant_overrides permissions" do
|
|
producer1
|
|
|
|
should_have_enterprise_relationship from: producer1, to: hub1,
|
|
with: [:add_to_order_cycle, :create_variant_overrides]
|
|
should_have_enterprise_relationship from: producer1, to: hub2,
|
|
with: [:add_to_order_cycle, :create_variant_overrides]
|
|
end
|
|
|
|
it "does not create any other links" do
|
|
expect do
|
|
producer1
|
|
end.to change(EnterpriseRelationship, :count).by(2)
|
|
end
|
|
end
|
|
|
|
describe "when a new hub is created" do
|
|
it "it creates links to the hub, from all producers owned by the same user, " \
|
|
"granting add_to_order_cycle and create_variant_overrides permissions" do
|
|
producer1
|
|
producer2
|
|
hub1
|
|
|
|
should_have_enterprise_relationship from: producer1, to: hub1,
|
|
with: [:add_to_order_cycle, :create_variant_overrides]
|
|
should_have_enterprise_relationship from: producer2, to: hub1,
|
|
with: [:add_to_order_cycle, :create_variant_overrides]
|
|
end
|
|
|
|
it "creates links from the new hub to all hubs owned by the same user, " \
|
|
"granting add_to_order_cycle permission" do
|
|
hub1
|
|
hub2
|
|
hub3
|
|
|
|
should_have_enterprise_relationship from: hub2, to: hub1, with: [:add_to_order_cycle]
|
|
should_have_enterprise_relationship from: hub3, to: hub1, with: [:add_to_order_cycle]
|
|
should_have_enterprise_relationship from: hub3, to: hub2, with: [:add_to_order_cycle]
|
|
end
|
|
|
|
it "does not create any other links" do
|
|
producer1
|
|
producer2
|
|
expect { hub1 }.to change(EnterpriseRelationship, :count).by(2) # 2 producer links
|
|
expect {
|
|
hub2
|
|
}.to change(EnterpriseRelationship, :count).by(3) # 2 producer links + 1 hub link
|
|
expect {
|
|
hub3
|
|
}.to change(EnterpriseRelationship, :count).by(4) # 2 producer links + 2 hub links
|
|
end
|
|
end
|
|
|
|
def should_have_enterprise_relationship(opts = {})
|
|
er = EnterpriseRelationship.where(parent_id: opts[:from], child_id: opts[:to]).last
|
|
expect(er).not_to be_nil
|
|
if opts[:with] == :all_permissions
|
|
expect(er.permissions.map(&:name)).to match_array ['add_to_order_cycle',
|
|
'manage_products', 'edit_profile',
|
|
'create_variant_overrides']
|
|
elsif opts.key? :with
|
|
expect(er.permissions.map(&:name)).to match_array opts[:with].map(&:to_s)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "finding variants distributed by the enterprise" do
|
|
it "finds variants distributed by order cycle" do
|
|
distributor = create(:distributor_enterprise)
|
|
product = create(:product)
|
|
variant = product.variants.first
|
|
create(:simple_order_cycle, distributors: [distributor], variants: [variant])
|
|
|
|
expect(distributor.distributed_variants).to match_array [variant]
|
|
end
|
|
end
|
|
|
|
describe "taxons" do
|
|
let(:distributor) { create(:distributor_enterprise) }
|
|
let(:supplier) { create(:supplier_enterprise) }
|
|
let(:taxon1) { create(:taxon) }
|
|
let(:taxon2) { create(:taxon) }
|
|
let(:taxon3) { create(:taxon) }
|
|
let(:product1) { create(:simple_product, primary_taxon: taxon1, taxons: [taxon1]) }
|
|
let(:product2) { create(:simple_product, primary_taxon: taxon1, taxons: [taxon1, taxon2]) }
|
|
let(:product3) { create(:simple_product, primary_taxon: taxon3) }
|
|
let(:oc) { create(:order_cycle) }
|
|
let(:ex) {
|
|
create(:exchange, order_cycle: oc, incoming: false, sender: supplier, receiver: distributor)
|
|
}
|
|
|
|
it "gets all taxons of all distributed products" do
|
|
allow(Spree::Product).to receive(:in_distributor).and_return [product1, product2]
|
|
expect(distributor.distributed_taxons).to match_array [taxon1, taxon2]
|
|
end
|
|
|
|
it "gets all taxons of all distributed products in open order cycles" do
|
|
allow(Spree::Product).to receive(:in_distributor).and_return [product1, product2, product3]
|
|
ex.variants << product1.variants.first
|
|
ex.variants << product3.variants.first
|
|
|
|
expect(distributor.current_distributed_taxons).to match_array [taxon1, taxon3]
|
|
end
|
|
|
|
it "gets all taxons of all supplied products" do
|
|
allow(Spree::Product).to receive(:in_supplier).and_return [product1, product2]
|
|
expect(supplier.supplied_taxons).to match_array [taxon1, taxon2]
|
|
end
|
|
end
|
|
|
|
describe "presentation of attributes" do
|
|
let(:distributor) {
|
|
build_stubbed(:distributor_enterprise,
|
|
website: "http://www.google.com",
|
|
facebook: "www.facebook.com/roger",
|
|
linkedin: "https://linkedin.com",
|
|
instagram: "https://www.instagram.com/@insgram_user",
|
|
twitter: "www.twitter.com/@twitter_user")
|
|
}
|
|
|
|
it "strips http from url fields" do
|
|
expect(distributor.website).to eq("www.google.com")
|
|
expect(distributor.facebook).to eq("www.facebook.com/roger")
|
|
expect(distributor.linkedin).to eq("linkedin.com")
|
|
end
|
|
|
|
it "strips @, http and domain address from url fields" do
|
|
expect(distributor.instagram).to eq("insgram_user")
|
|
expect(distributor.twitter).to eq("twitter_user")
|
|
end
|
|
end
|
|
|
|
describe "producer properties" do
|
|
let(:supplier) { create(:supplier_enterprise) }
|
|
|
|
it "sets producer properties" do
|
|
supplier.set_producer_property 'Organic Certified', 'NASAA 12345'
|
|
|
|
expect(supplier.producer_properties.count).to eq(1)
|
|
expect(supplier.producer_properties.first.value).to eq('NASAA 12345')
|
|
expect(supplier.producer_properties.first.property.presentation).to eq('Organic Certified')
|
|
end
|
|
end
|
|
|
|
describe "provide enterprise category" do
|
|
let(:producer_sell_all) { build_stubbed(:enterprise, is_primary_producer: true, sells: "any") }
|
|
let(:producer_sell_own) { build_stubbed(:enterprise, is_primary_producer: true, sells: "own") }
|
|
let(:producer_sell_none) {
|
|
build_stubbed(:enterprise, is_primary_producer: true, sells: "none")
|
|
}
|
|
let(:non_producer_sell_all) {
|
|
build_stubbed(:enterprise, is_primary_producer: false, sells: "any")
|
|
}
|
|
let(:non_producer_sell_own) {
|
|
build_stubbed(:enterprise, is_primary_producer: false, sells: "own")
|
|
}
|
|
let(:non_producer_sell_none) {
|
|
build_stubbed(:enterprise, is_primary_producer: false, sells: "none")
|
|
}
|
|
|
|
it "should output enterprise categories" do
|
|
expect(producer_sell_all.is_primary_producer).to eq(true)
|
|
expect(producer_sell_all.sells).to eq("any")
|
|
|
|
expect(producer_sell_all.category).to eq(:producer_hub)
|
|
expect(producer_sell_own.category).to eq(:producer_shop)
|
|
expect(producer_sell_none.category).to eq(:producer)
|
|
expect(non_producer_sell_all.category).to eq(:hub)
|
|
expect(non_producer_sell_own.category).to eq(:hub)
|
|
expect(non_producer_sell_none.category).to eq(:hub_profile)
|
|
end
|
|
end
|
|
|
|
describe "finding and automatically assigning a permalink" do
|
|
let(:enterprise) { build_stubbed(:enterprise, name: "Name To Turn Into A Permalink") }
|
|
it "assigns permalink when initialized" do
|
|
allow(Enterprise).to receive(:find_available_permalink).and_return("available_permalink")
|
|
expect(Enterprise).to receive(:find_available_permalink).with("Name To Turn Into A Permalink")
|
|
expect do
|
|
enterprise.send(:initialize_permalink)
|
|
end.to change { enterprise.permalink }.to("available_permalink")
|
|
end
|
|
|
|
describe "finding a permalink" do
|
|
let!(:enterprise1) { create(:enterprise, permalink: "permalink") }
|
|
let!(:enterprise2) { create(:enterprise, permalink: "permalink1") }
|
|
|
|
it "parameterizes the value provided" do
|
|
expect(Enterprise.find_available_permalink("Some Unused Permalink"))
|
|
.to eq "some-unused-permalink"
|
|
end
|
|
|
|
it "sets the permalink to 'my-enterprise' if parametized permalink is blank" do
|
|
expect(Enterprise.find_available_permalink("")).to eq "my-enterprise"
|
|
expect(Enterprise.find_available_permalink("$$%{$**}$%}")).to eq "my-enterprise"
|
|
end
|
|
|
|
it "finds and index value based on existing permalinks" do
|
|
expect(Enterprise.find_available_permalink("permalink")).to eq "permalink2"
|
|
end
|
|
|
|
it "ignores permalinks with characters after the index value" do
|
|
create(:enterprise, permalink: "permalink2xxx")
|
|
expect(Enterprise.find_available_permalink("permalink")).to eq "permalink2"
|
|
end
|
|
|
|
it "finds available permalink similar to existing" do
|
|
create(:enterprise, permalink: "permalink2xxx")
|
|
expect(Enterprise.find_available_permalink("permalink2")).to eq "permalink2"
|
|
end
|
|
|
|
it "finds gaps in the indices of existing permalinks" do
|
|
create(:enterprise, permalink: "permalink3")
|
|
expect(Enterprise.find_available_permalink("permalink")).to eq "permalink2"
|
|
end
|
|
|
|
it "should support permalink generation from names with non-roman characters" do
|
|
enterprise = create(:enterprise, name: "你好")
|
|
|
|
expect(enterprise.valid?).to be true
|
|
expect(enterprise.permalink).to eq "ni-hao"
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "#parents_of_one_union_others" do
|
|
it "should return only parent producers" do
|
|
supplier = create(:supplier_enterprise)
|
|
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
|
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
|
create(:enterprise_relationship, parent: distributor,
|
|
child: supplier, permissions: [permission])
|
|
expect(Enterprise.parents_of_one_union_others(supplier, nil)).to include(distributor)
|
|
end
|
|
|
|
it "should return other enterprise if it is passed as a second argument" do
|
|
another_enterprise = create(:enterprise)
|
|
supplier = create(:supplier_enterprise)
|
|
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
|
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
|
create(:enterprise_relationship, parent: distributor,
|
|
child: supplier, permissions: [permission])
|
|
expect(
|
|
Enterprise.parents_of_one_union_others(supplier, another_enterprise)
|
|
).to include(another_enterprise)
|
|
end
|
|
|
|
it "does not find child in the relationship" do
|
|
supplier = create(:supplier_enterprise)
|
|
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
|
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
|
create(:enterprise_relationship, parent: distributor,
|
|
child: supplier, permissions: [permission])
|
|
expect(Enterprise.parents_of_one_union_others(distributor, nil)).not_to include(supplier)
|
|
end
|
|
end
|
|
|
|
describe "#plus_parents_and_order_cycle_producers" do
|
|
it "does not find non-producers" do
|
|
supplier = create(:supplier_enterprise)
|
|
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
|
product = create(:product)
|
|
order_cycle = create(
|
|
:simple_order_cycle,
|
|
suppliers: [supplier],
|
|
distributors: [distributor],
|
|
variants: [product.variants.first]
|
|
)
|
|
expect(distributor.plus_parents_and_order_cycle_producers(order_cycle)).to eq([supplier])
|
|
end
|
|
|
|
it "finds parent in the relationship" do
|
|
supplier = create(:supplier_enterprise)
|
|
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
|
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
|
product = create(:product)
|
|
order_cycle = create(
|
|
:simple_order_cycle,
|
|
distributors: [distributor],
|
|
suppliers: [supplier],
|
|
variants: [product.variants.first]
|
|
)
|
|
create(:enterprise_relationship, parent: distributor,
|
|
child: supplier, permissions: [permission])
|
|
expect(distributor.plus_parents_and_order_cycle_producers(order_cycle)).to include(supplier)
|
|
end
|
|
|
|
it "does not find child in the relationship" do
|
|
supplier = create(:supplier_enterprise)
|
|
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
|
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
|
create(:enterprise_relationship, parent: distributor,
|
|
child: supplier, permissions: [permission])
|
|
product = create(:product)
|
|
order_cycle = create(
|
|
:simple_order_cycle,
|
|
suppliers: [supplier],
|
|
distributors: [distributor],
|
|
variants: [product.variants.first]
|
|
)
|
|
expected = supplier.plus_parents_and_order_cycle_producers(order_cycle)
|
|
expect(expected).not_to include(distributor)
|
|
end
|
|
|
|
it "it finds sender enterprises for order cycles that are passed" do
|
|
supplier = create(:supplier_enterprise)
|
|
sender = create(:supplier_enterprise)
|
|
distributor = create(:distributor_enterprise, is_primary_producer: false)
|
|
permission = EnterpriseRelationshipPermission.create(name: "add_to_order_cycle")
|
|
create(:enterprise_relationship, parent: distributor, child: supplier,
|
|
permissions: [permission])
|
|
product = create(:product)
|
|
order_cycle = create(
|
|
:simple_order_cycle,
|
|
suppliers: [sender],
|
|
distributors: [distributor],
|
|
variants: [product.variants.first]
|
|
)
|
|
expected = supplier.plus_parents_and_order_cycle_producers(order_cycle)
|
|
expect(expected).to include(sender)
|
|
end
|
|
end
|
|
end
|
|
|
|
def enterprise_name_error(owner_email)
|
|
"has already been taken. \
|
|
If this is your enterprise and you would like to claim ownership, \
|
|
or if you would like to trade with this enterprise please contact \
|
|
the current manager of this profile at %s." % owner_email
|
|
end
|