mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Fix easy rubocop issues
This commit is contained in:
@@ -13,11 +13,15 @@ module OrderManagement
|
||||
context "#shipping rates" do
|
||||
before(:each) do
|
||||
shipping_method.zones.first.members.create(zoneable: order.ship_address.country)
|
||||
allow_any_instance_of(Spree::ShippingMethod).to receive_message_chain(:calculator, :available?).and_return(true)
|
||||
allow_any_instance_of(Spree::ShippingMethod).to receive_message_chain(:calculator, :compute).and_return(4.00)
|
||||
allow_any_instance_of(Spree::ShippingMethod).
|
||||
to receive_message_chain(:calculator, :preferences).and_return({ currency: order.currency })
|
||||
allow_any_instance_of(Spree::ShippingMethod).to receive_message_chain(:calculator, :marked_for_destruction?)
|
||||
to receive_message_chain(:calculator, :available?).and_return(true)
|
||||
allow_any_instance_of(Spree::ShippingMethod).
|
||||
to receive_message_chain(:calculator, :compute).and_return(4.00)
|
||||
allow_any_instance_of(Spree::ShippingMethod).
|
||||
to receive_message_chain(:calculator, :preferences).
|
||||
and_return({ currency: order.currency })
|
||||
allow_any_instance_of(Spree::ShippingMethod).
|
||||
to receive_message_chain(:calculator, :marked_for_destruction?)
|
||||
|
||||
allow(package).to receive_messages(shipping_methods: [shipping_method])
|
||||
end
|
||||
@@ -39,7 +43,8 @@ module OrderManagement
|
||||
|
||||
context "the calculator is not available for that order" do
|
||||
it "does not return shipping rates from a shipping method" do
|
||||
allow_any_instance_of(Spree::ShippingMethod).to receive_message_chain(:calculator, :available?).and_return(false)
|
||||
allow_any_instance_of(Spree::ShippingMethod).
|
||||
to receive_message_chain(:calculator, :available?).and_return(false)
|
||||
shipping_rates = subject.shipping_rates(package)
|
||||
expect(shipping_rates).to eq []
|
||||
end
|
||||
@@ -62,9 +67,12 @@ module OrderManagement
|
||||
|
||||
it "sorts shipping rates by cost" do
|
||||
shipping_methods = 3.times.map { create(:shipping_method) }
|
||||
allow(shipping_methods[0]).to receive_message_chain(:calculator, :compute).and_return(5.00)
|
||||
allow(shipping_methods[1]).to receive_message_chain(:calculator, :compute).and_return(3.00)
|
||||
allow(shipping_methods[2]).to receive_message_chain(:calculator, :compute).and_return(4.00)
|
||||
allow(shipping_methods[0]).
|
||||
to receive_message_chain(:calculator, :compute).and_return(5.00)
|
||||
allow(shipping_methods[1]).
|
||||
to receive_message_chain(:calculator, :compute).and_return(3.00)
|
||||
allow(shipping_methods[2]).
|
||||
to receive_message_chain(:calculator, :compute).and_return(4.00)
|
||||
|
||||
allow(subject).to receive(:shipping_methods).and_return(shipping_methods)
|
||||
|
||||
@@ -76,8 +84,10 @@ module OrderManagement
|
||||
let(:shipping_methods) { 2.times.map { create(:shipping_method) } }
|
||||
|
||||
it "selects the most affordable shipping rate" do
|
||||
allow(shipping_methods[0]).to receive_message_chain(:calculator, :compute).and_return(5.00)
|
||||
allow(shipping_methods[1]).to receive_message_chain(:calculator, :compute).and_return(3.00)
|
||||
allow(shipping_methods[0]).
|
||||
to receive_message_chain(:calculator, :compute).and_return(5.00)
|
||||
allow(shipping_methods[1]).
|
||||
to receive_message_chain(:calculator, :compute).and_return(3.00)
|
||||
|
||||
allow(subject).to receive(:shipping_methods).and_return(shipping_methods)
|
||||
|
||||
@@ -86,8 +96,10 @@ module OrderManagement
|
||||
end
|
||||
|
||||
it "selects the cheapest shipping rate and doesn't raise exception over nil cost" do
|
||||
allow(shipping_methods[0]).to receive_message_chain(:calculator, :compute).and_return(1.00)
|
||||
allow(shipping_methods[1]).to receive_message_chain(:calculator, :compute).and_return(nil)
|
||||
allow(shipping_methods[0]).
|
||||
to receive_message_chain(:calculator, :compute).and_return(1.00)
|
||||
allow(shipping_methods[1]).
|
||||
to receive_message_chain(:calculator, :compute).and_return(nil)
|
||||
|
||||
allow(subject).to receive(:shipping_methods).and_return(shipping_methods)
|
||||
|
||||
@@ -104,7 +116,8 @@ module OrderManagement
|
||||
allow(backend_method).to receive_message_chain(:calculator, :compute).and_return(0.00)
|
||||
allow(generic_method).to receive_message_chain(:calculator, :compute).and_return(5.00)
|
||||
|
||||
allow(subject).to receive(:shipping_methods).and_return([backend_method, generic_method])
|
||||
allow(subject).
|
||||
to receive(:shipping_methods).and_return([backend_method, generic_method])
|
||||
|
||||
expect(subject.shipping_rates(package).map(&:selected)).to eq [false, true]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user