Fix specs for OrderSyncer

This commit is contained in:
Kristina Lim
2019-02-27 23:50:21 +08:00
parent 0cfee37567
commit 56e2ee5366

View File

@@ -2,17 +2,23 @@ require 'spec_helper'
describe OrderSyncer do
describe "updating the shipping method" do
let(:subscription) { create(:subscription, with_items: true, with_proxy_orders: true) }
let(:order) { subscription.proxy_orders.first.initialise_order! }
let(:shipping_method) { subscription.shipping_method }
let(:new_shipping_method) { create(:shipping_method, distributors: [subscription.shop]) }
let!(:subscription) { create(:subscription, with_items: true, with_proxy_orders: true) }
let!(:order) { subscription.proxy_orders.first.initialise_order! }
let!(:shipping_method) { subscription.shipping_method }
let!(:new_shipping_method) { create(:shipping_method, distributors: [subscription.shop]) }
let(:syncer) { OrderSyncer.new(subscription) }
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
# Create shipping rates for available shipping methods.
order.shipments.each(&:refresh_rates)
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 +31,13 @@ describe OrderSyncer do
context "when the shipping method on a shipment is the same as the new shipping method on the subscription" do
before do
# Create shipping rates for available shipping methods.
order.shipments.each(&:refresh_rates)
# 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
@@ -42,15 +50,18 @@ describe OrderSyncer do
end
context "when the shipping method on a shipment is not the same as the new shipping method on the subscription" do
let(:changed_shipping_method) { create(:shipping_method) }
let!(:changed_shipping_method) { create(:shipping_method) }
before do
# Create shipping rates for available shipping methods.
order.shipments.each(&:refresh_rates)
# 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
@@ -239,6 +250,7 @@ describe OrderSyncer do
context "but the shipping method is being changed to one that requires a ship_address" do
let(:new_shipping_method) { create(:shipping_method, require_ship_address: true) }
before { params.merge!(shipping_method_id: new_shipping_method.id) }
it "updates ship_address attrs" do