From 356099a49aee03419162e0148076d8bf85d0c60f Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 12 Mar 2014 12:31:35 +1100 Subject: [PATCH] When product unit changed, remove option types from master as well as other variants --- app/models/spree/product_decorator.rb | 2 +- spec/models/spree/product_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 7682720708..7f84913d68 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -151,7 +151,7 @@ Spree::Product.class_eval do if variant_unit_changed? option_types.delete self.class.all_variant_unit_option_types option_types << variant_unit_option_type if variant_unit.present? - variants.each { |v| v.delete_unit_option_values } + variants_including_master.each { |v| v.delete_unit_option_values } end end diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index d42f811422..813a57558f 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -429,6 +429,16 @@ module Spree p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001) }.to change(v.option_values(true), :count).by(-1) end + + it "removes the related option values from its master variant" do + ot = Spree::OptionType.find_by_name 'unit_weight' + p.master.update_attributes!(unit_value: 1) + p.reload + + expect { + p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001) + }.to change(p.master.option_values(true), :count).by(-1) + end end describe "returning the variant unit option type" do