When product unit changed, remove option types from master as well as other variants

This commit is contained in:
Rohan Mitchell
2014-03-12 12:31:35 +11:00
parent 93a661ac08
commit 356099a49a
2 changed files with 11 additions and 1 deletions

View File

@@ -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

View File

@@ -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