Skip to content

Commit

Permalink
Fix specs for OrderSyncer
Browse files Browse the repository at this point in the history
  • Loading branch information
kristinalim committed Mar 1, 2019
1 parent c2461a5 commit 7b7e39f
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions spec/services/order_syncer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
context "when the shipping method on an order is the same as the subscription" do
let(:params) { { shipping_method_id: new_shipping_method.id } }

before do
# Add a shipping rate for the shipping method. This is not necessary if the shipping method
# already existed before the order was created. This should automatically be done in
# Spree::Order.select_shipping_method, not in the OrderSyncer.
order.shipment.add_shipping_method(new_shipping_method)
end

it "updates the shipping_method on the order and on shipments" do
expect(order.shipments.first.shipping_method_id_was).to eq shipping_method.id
expect(order.shipments.first.shipping_method).to eq shipping_method
subscription.assign_attributes(params)
expect(syncer.sync!).to be true
expect(order.reload.shipping_method).to eq new_shipping_method
Expand All @@ -25,11 +32,15 @@

context "when the shipping method on a shipment is the same as the new shipping method on the subscription" do
before do
# Add a shipping rate for the shipping method. This is not necessary if the shipping
# method already existed before the order was created. This should automatically be done
# in Spree::Order.select_shipping_method, not in the OrderSyncer.
order.shipment.add_shipping_method(new_shipping_method)

# Updating the shipping method on a shipment updates the shipping method on the order,
# and vice-versa via logic in Spree's shipments controller. So updating both here mimics that
# behaviour.
order.shipments.first.update_attributes(shipping_method_id: new_shipping_method.id)
order.update_attributes(shipping_method_id: new_shipping_method.id)
order.select_shipping_method(new_shipping_method.id)
subscription.assign_attributes(params)
expect(syncer.sync!).to be true
end
Expand All @@ -45,12 +56,18 @@
let(:changed_shipping_method) { create(:shipping_method) }

before do
# Add a shipping rate for the shipping method. This is not necessary if the shipping
# method already existed before the order was created. This should automatically be done
# in Spree::Order.select_shipping_method, not in the OrderSyncer.
order.shipment.add_shipping_method(new_shipping_method)
order.shipment.add_shipping_method(changed_shipping_method)

# Updating the shipping method on a shipment updates the shipping method on the order,
# and vice-versa via logic in Spree's shipments controller. So updating both here mimics that
# behaviour.
order.shipments.first.update_attributes(shipping_method_id: changed_shipping_method.id)
order.update_attributes(shipping_method_id: changed_shipping_method.id)
order.select_shipping_method(changed_shipping_method.id)
subscription.assign_attributes(params)

expect(syncer.sync!).to be true
end

Expand Down

0 comments on commit 7b7e39f

Please sign in to comment.