mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-23 05:28:53 +00:00
Add numericality validation for PerItem
This commit is contained in:
@@ -10,6 +10,9 @@ module Calculator
|
||||
|
||||
localize_number :preferred_amount
|
||||
|
||||
validates :preferred_amount,
|
||||
numericality: { message: :calculator_preferred_value_error }
|
||||
|
||||
def self.description
|
||||
I18n.t(:flat_rate_per_item)
|
||||
end
|
||||
|
||||
@@ -7,6 +7,11 @@ describe Calculator::PerItem do
|
||||
let(:shipping_calculable) { double(:calculable) }
|
||||
let(:line_item) { build_stubbed(:line_item, quantity: 5) }
|
||||
|
||||
it do
|
||||
should validate_numericality_of(:preferred_amount).
|
||||
with_message("Invalid input. Please use only numbers. For example: 10, 5.5, -20")
|
||||
end
|
||||
|
||||
it "correctly calculates on a single line item object" do
|
||||
allow(calculator).to receive_messages(calculable: shipping_calculable)
|
||||
expect(calculator.compute(line_item).to_f).to eq(50) # 5 x 10
|
||||
|
||||
Reference in New Issue
Block a user