From 7b7e39f89db6708d5c43fbe8f153fe5f6431217f Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Wed, 27 Feb 2019 23:50:21 +0800 Subject: [PATCH] Fix specs for OrderSyncer --- spec/services/order_syncer_spec.rb | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/spec/services/order_syncer_spec.rb b/spec/services/order_syncer_spec.rb index 6d44862ab8e0..0943deb56e4d 100644 --- a/spec/services/order_syncer_spec.rb +++ b/spec/services/order_syncer_spec.rb @@ -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 @@ -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 @@ -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