Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwil committed Jan 7, 2025
1 parent c5e6c38 commit f3e3143
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions core/spec/models/spree/stock/simple_coordinator_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "Integrating with the simple coordinator" do
Expand Down Expand Up @@ -97,11 +99,9 @@
end

it 'raises exception and includes unfulfillable items' do
begin
expect(shipments).not_to be_empty
rescue Spree::Order::InsufficientStock => e
rescue Spree::Order::InsufficientStock => e
expect(e.items.keys.map(&:id)).to contain_exactly(variant.id)
end
end
end

Expand Down Expand Up @@ -236,28 +236,28 @@

context "when custom coordinator options are passed" do
let!(:order) {
create :order_with_line_items, line_items_attributes: [{variant: create(:product_in_stock).master }]
create :order_with_line_items, line_items_attributes: [{ variant: create(:product_in_stock).master }]
}

subject {
Spree::Stock::SimpleCoordinator.new(order, coordinator_options:)
}

describe "to customize the estimator's behavior" do
let(:coordinator_options) { {arbitrary_shipping_rates: [my_shipping_rate]} }
let(:coordinator_options) { { arbitrary_shipping_rates: [my_shipping_rate] } }
let(:my_shipping_rate) { create(:shipping_method).shipping_rates.new }

around do |example|
MyEstimator = Class.new(Spree::Stock::Estimator) do
def shipping_rates(package, _frontend_only = true)
def shipping_rates(package)
raise ShipmentRequired if package.shipment.nil?
raise OrderRequired if package.shipment.order.nil?

first_shipping_rate = coordinator_options[:arbitrary_shipping_rates]&.first

if first_shipping_rate
first_shipping_rate.selected = true
return [first_shipping_rate]
[first_shipping_rate]
else
raise StandardError, "no shipping rate!"
end
Expand All @@ -277,14 +277,14 @@ def shipping_rates(package, _frontend_only = true)
end

describe "to customize the inventory unit builder's behavior" do
let(:coordinator_options) { {multiplier: 4} }
let(:coordinator_options) { { multiplier: 4 } }

around do |example|
MyInventoryUnitBuilder = Class.new(Spree::Stock::InventoryUnitBuilder) do
def units
units = []
coordinator_options[:multiplier].times do
units = units.concat(super)
units.concat(super)
end
units
end
Expand All @@ -305,7 +305,7 @@ def units
end

describe "to customize the allocator's behavior" do
let(:coordinator_options) { {force_backordered: true} }
let(:coordinator_options) { { force_backordered: true } }

around do |example|
MyAllocator = Class.new(Spree::Stock::Allocator::OnHandFirst) do
Expand Down Expand Up @@ -333,15 +333,17 @@ def allocate_inventory(desired)
end

describe "to customize the stock locator filter behavior" do
let(:coordinator_options) { {force_specific_stock_location: specific_stock_location} }
let(:coordinator_options) { { force_specific_stock_location: specific_stock_location } }
let(:specific_stock_location) { create(:stock_location) }

around do |example|
MyLocatorFilter = Class.new(Spree::Stock::LocationFilter::Active) do
def filter
coordinator_options[:force_specific_stock_location] ?
if coordinator_options[:force_specific_stock_location]
[coordinator_options[:force_specific_stock_location]]
: super
else
super
end
end
end

Expand All @@ -358,7 +360,7 @@ def filter
end

describe "to customize the stock location sorters behavior" do
let(:coordinator_options) { {force_stock_location_order: [stock_location_2, stock_location_1]} }
let(:coordinator_options) { { force_stock_location_order: [stock_location_2, stock_location_1] } }
let!(:stock_location_1) { create(:stock_location, active: true, propagate_all_variants: true) }
let!(:stock_location_2) { create(:stock_location, active: true, propagate_all_variants: true) }

Expand Down

0 comments on commit f3e3143

Please sign in to comment.