From 8ae36c9b481b7ac393f1d5adc32d86cc4d4b6051 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Fri, 30 Jun 2017 17:42:13 +0200 Subject: [PATCH] Destroy all shipments when clearing order Now we only clear the order's shipping_method, and in Spree 2.0 it can have many shipments. --- app/models/spree/order_decorator.rb | 2 +- spec/models/spree/order_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 8519e52ff0..c3b5cb7356 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -83,7 +83,7 @@ Spree::Order.class_eval do def empty_with_clear_shipping_and_payments! empty_without_clear_shipping_and_payments! payments.clear - update_attributes(shipping_method_id: nil) + shipments.destroy_all end alias_method_chain :empty!, :clear_shipping_and_payments diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index e7c46c27cb..a27b9e91a8 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -383,18 +383,18 @@ describe Spree::Order do end describe "emptying the order" do - it "removes shipping method" do - subject.shipping_method = create(:shipping_method) + it "removes shipments" do + subject.shipments << create(:shipment) subject.save! subject.empty! - subject.shipping_method.should == nil + expect(subject.shipments).to be_empty end it "removes payments" do subject.payments << create(:payment) subject.save! subject.empty! - subject.payments.should == [] + expect(subject.payments).to be_empty end end