mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #8621 from apricot12/Unit-value-shop-front
Update units when variant unit name is edited
This commit is contained in:
@@ -431,7 +431,7 @@ module Spree
|
||||
end
|
||||
|
||||
def update_units
|
||||
return unless saved_change_to_variant_unit?
|
||||
return unless saved_change_to_variant_unit? || saved_change_to_variant_unit_name?
|
||||
|
||||
option_types.delete self.class.all_variant_unit_option_types
|
||||
option_types << variant_unit_option_type if variant_unit.present?
|
||||
|
||||
@@ -443,6 +443,30 @@ module Spree
|
||||
|
||||
expect(product.taxons).not_to include(original_taxon)
|
||||
end
|
||||
|
||||
it "updates units when saved change to variant unit" do
|
||||
product.variant_unit = 'items'
|
||||
product.variant_unit_scale = nil
|
||||
product.variant_unit_name = 'loaf'
|
||||
product.save!
|
||||
|
||||
expect(product.variant_unit_name).to eq 'loaf'
|
||||
|
||||
product.update(variant_unit_name: 'bag')
|
||||
|
||||
expect(product.variant_unit_name).to eq 'bag'
|
||||
|
||||
product.variant_unit = 'weight'
|
||||
product.variant_unit_scale = 1
|
||||
product.variant_unit_name = 'g'
|
||||
product.save!
|
||||
|
||||
expect(product.variant_unit).to eq 'weight'
|
||||
|
||||
product.update(variant_unit: 'volume')
|
||||
|
||||
expect(product.variant_unit).to eq 'volume'
|
||||
end
|
||||
end
|
||||
|
||||
describe "scopes" do
|
||||
|
||||
Reference in New Issue
Block a user