From a0999f5d58370e1409f48bcd8849d4bb413c73d8 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 1 Mar 2020 18:40:15 +0100 Subject: [PATCH] Check #persisted? before calling #touch Rails 4 now throws a fatal error if calling #touch on an object that hasn't been saved yet: https://github.com/rails/rails/blob/c63cfc8722292ec39def505861fbc20bd9774f4c/activerecord/lib/active_record/persistence.rb#L957 Fixes: 41) Stock::Package#shipping_methods does not return shipping methods not used by the package's order distributor Failure/Error: distributors.each(&:touch) ActiveRecord::ActiveRecordError: can not touch on a new record object # ./app/models/spree/shipping_method_decorator.rb:81:in `touch_distributors' # ./spec/models/stock/package_spec.rb:39:in `block (2 levels) in ' # ./spec/models/stock/package_spec.rb:17:in `block (2 levels) in ' # ./spec/models/stock/package_spec.rb:32:in `block (2 levels) in ' # ./spec/models/stock/package_spec.rb:7:in `block (2 levels) in ' # ./spec/models/stock/package_spec.rb:44:in `block (3 levels) in ' 42) Stock::Package#shipping_categories returns shipping categories that are not shipping categories of the order's products Failure/Error: distributors.each(&:touch) ActiveRecord::ActiveRecordError: can not touch on a new record object # ./app/models/spree/shipping_method_decorator.rb:81:in `touch_distributors' # ./spec/models/stock/package_spec.rb:39:in `block (2 levels) in ' # ./spec/models/stock/package_spec.rb:17:in `block (2 levels) in ' # ./spec/models/stock/package_spec.rb:32:in `block (2 levels) in ' # ./spec/models/stock/package_spec.rb:7:in `block (2 levels) in ' # ./spec/models/stock/package_spec.rb:50:in `block (3 levels) in ' --- app/models/spree/shipping_method_decorator.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/spree/shipping_method_decorator.rb b/app/models/spree/shipping_method_decorator.rb index 837fd45ee6..c44bffe546 100644 --- a/app/models/spree/shipping_method_decorator.rb +++ b/app/models/spree/shipping_method_decorator.rb @@ -78,6 +78,8 @@ Spree::ShippingMethod.class_eval do private def touch_distributors - distributors.each(&:touch) + distributors.each do |distributor| + distributor.touch if distributor.persisted? + end end end