From 1ea2f37c18efa845974d41f8fae9473aa78be3a2 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 18 Mar 2019 17:29:58 +1100 Subject: [PATCH] Support international decimals in weight calculator A previous pull request added support for flexible decimal characters when editing money amounts. https://github.com/openfoodfoundation/openfoodnetwork/pull/1831 This pull request applies the same principle to the weight calculator which was missed in the previous pull request. --- app/models/calculator/weight.rb | 4 ++++ spec/models/calculator/weight_spec.rb | 2 ++ 2 files changed, 6 insertions(+) diff --git a/app/models/calculator/weight.rb b/app/models/calculator/weight.rb index 410a53b2f8..a10245bc55 100644 --- a/app/models/calculator/weight.rb +++ b/app/models/calculator/weight.rb @@ -1,7 +1,11 @@ +require 'spree/localized_number' + module Calculator class Weight < Spree::Calculator + extend Spree::LocalizedNumber preference :per_kg, :decimal, default: 0.0 attr_accessible :preferred_per_kg + localize_number :preferred_per_kg def self.description I18n.t('spree.weight') diff --git a/spec/models/calculator/weight_spec.rb b/spec/models/calculator/weight_spec.rb index c45da8850a..028e82d829 100644 --- a/spec/models/calculator/weight_spec.rb +++ b/spec/models/calculator/weight_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Calculator::Weight do + it_behaves_like "a model using the LocalizedNumber module", [:preferred_per_kg] + it "computes shipping cost for an order by total weight" do variant1 = build(:variant, weight: 10) variant2 = build(:variant, weight: 20)