Remove localized number logic from calculators

The browser is now responsible for dealing with the decimal separator, for all numeric preferences (as input[type=number]; see Spree::Admin::BaseHelper::preference_field_tag). Calculators are the only place that numeric preferences are used.

It will enforce that only one comma or dot (depending on user's locale) is entered, thus avoiding any ambiguity, and mis-interpretation (eg 100,001 could be interpreted as more than 100 thousand or 100 with a decimal place).
This commit is contained in:
David Cook
2023-04-28 11:59:47 +10:00
parent 43e51cb592
commit a46eef291c
12 changed files with 6 additions and 89 deletions

View File

@@ -17,12 +17,6 @@ describe Calculator::FlatPercentItemTotal do
expect(calculator.compute(line_item)).to eq(1.0)
end
context "extends LocalizedNumber" do
it_behaves_like "a model using the LocalizedNumber module", [:preferred_flat_percent]
it_behaves_like "a Spree Calculator model using the LocalizedNumber module",
[:preferred_flat_percent]
end
it "computes amount correctly for a given OrderManagement::Stock::Package" do
order = double(:order, line_items: [line_item] )
package = double(:package, order: order)

View File

@@ -19,10 +19,4 @@ describe Calculator::FlatPercentPerItem do
line_item = Spree::LineItem.new price: 0.86, quantity: 8
expect(calculator.compute(line_item)).to eq 1.36
end
context "extends LocalizedNumber" do
it_behaves_like "a model using the LocalizedNumber module", [:preferred_flat_percent]
it_behaves_like "a Spree Calculator model using the LocalizedNumber module",
[:preferred_flat_percent]
end
end

View File

@@ -11,9 +11,4 @@ describe Calculator::FlatRate do
should validate_numericality_of(:preferred_amount).
with_message("Invalid input. Please use only numbers. For example: 10, 5.5, -20")
end
context "extends LocalizedNumber" do
it_behaves_like "a model using the LocalizedNumber module", [:preferred_amount]
it_behaves_like "a Spree Calculator model using the LocalizedNumber module", [:preferred_amount]
end
end

View File

@@ -42,11 +42,4 @@ describe Calculator::FlexiRate do
Calculator::FlexiRate.new(preferred_first_item: 1, preferred_additional_item: 1,
preferred_max_items: 1)
end
context "extends LocalizedNumber" do
it_behaves_like "a model using the LocalizedNumber module",
[:preferred_first_item, :preferred_additional_item]
it_behaves_like "a Spree Calculator model using the LocalizedNumber module",
[:preferred_first_item, :preferred_additional_item]
end
end

View File

@@ -16,9 +16,4 @@ describe Calculator::PerItem do
allow(calculator).to receive_messages(calculable: shipping_calculable)
expect(calculator.compute(line_item).to_f).to eq(50) # 5 x 10
end
context "extends LocalizedNumber" do
it_behaves_like "a model using the LocalizedNumber module", [:preferred_amount]
it_behaves_like "a Spree Calculator model using the LocalizedNumber module", [:preferred_amount]
end
end

View File

@@ -90,13 +90,4 @@ describe Calculator::PriceSack do
end
end
end
context "extends LocalizedNumber" do
it_behaves_like "a model using the LocalizedNumber module",
[:preferred_minimal_amount, :preferred_normal_amount,
:preferred_discount_amount]
it_behaves_like "a Spree Calculator model using the LocalizedNumber module",
[:preferred_minimal_amount, :preferred_normal_amount,
:preferred_discount_amount]
end
end