Skip to content

Commit 7900a2f

Browse files
wip: Ensure coordinator_options are integration tested
This new, passing spec should be moved. Additional coverage could be added. Existing specs in the modified spec file can also be moved to an integration test file. Co-authored-by: Noah Silvera <[email protected]>
1 parent cd5b4be commit 7900a2f

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

core/app/models/spree/stock/estimator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def shipping_rates(package, frontend_only = true)
2929

3030
private
3131

32+
attr_reader :coordinator_options
33+
3234
def choose_default_shipping_rate(shipping_rates)
3335
unless shipping_rates.empty?
3436
default_shipping_rate = Spree::Config.shipping_rate_selector_class.new(shipping_rates).find_default

core/spec/lib/spree/core/stock_configuration_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,42 @@
3737
ensure
3838
Object.send(:remove_const, :MyEstimator)
3939
end
40+
41+
# FIXME:
42+
# Move this to an integration test file after moving existing specs that are
43+
# actually integration specs to that file.
44+
#
45+
it "uses coordinator options passed in to the simple coordinator" do
46+
order = create(:order_with_line_items)
47+
my_shipping_rate = create(:shipping_method).shipping_rates.new
48+
49+
MyEstimator = Class.new(Spree::Stock::Estimator) do
50+
def shipping_rates(package, _frontend_only = true)
51+
raise ShipmentRequired if package.shipment.nil?
52+
raise OrderRequired if package.shipment.order.nil?
53+
54+
if (shipping_rate = coordinator_options[:arbitrary_shipping_rates].first)
55+
shipping_rate.selected = true
56+
return [shipping_rate]
57+
else
58+
raise StandardError, "no shipping rate!"
59+
end
60+
end
61+
end
62+
Spree::Config.stock.estimator_class = MyEstimator.to_s
63+
64+
stock_simple_coordinator = stock_configuration.coordinator_class
65+
shipments = stock_simple_coordinator
66+
.new(
67+
order, coordinator_options: {
68+
arbitrary_shipping_rates: [my_shipping_rate]
69+
}
70+
)
71+
.shipments
72+
73+
74+
expect(shipments.first.selected_shipping_rate).to eq my_shipping_rate
75+
end
4076
end
4177

4278
describe '#location_filter_class' do
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require "rails_helper"
2+
3+
4+
# FIXME:
5+
# - Move over existing simple coordinator specs that are actually integration
6+
# tests.
7+
# - Add test coverage for the usage of `coordinator_options` as passed from the
8+
# simple coordinator to other collaborating classes.
9+
#
10+
RSpec.describe "Integrating with the simple coordinator" do
11+
end

0 commit comments

Comments
 (0)