mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add numericality validation for PriceSack
This commit is contained in:
@@ -14,6 +14,11 @@ module Calculator
|
||||
:preferred_normal_amount,
|
||||
:preferred_discount_amount
|
||||
|
||||
validates :preferred_minimal_amount,
|
||||
:preferred_normal_amount,
|
||||
:preferred_discount_amount,
|
||||
numericality: { message: :calculator_preferred_value_error }
|
||||
|
||||
def self.description
|
||||
I18n.t(:price_sack)
|
||||
end
|
||||
|
||||
@@ -12,6 +12,21 @@ describe Calculator::PriceSack do
|
||||
end
|
||||
let(:line_item) { build_stubbed(:line_item, price: price, quantity: 2) }
|
||||
|
||||
it do
|
||||
should validate_numericality_of(:preferred_minimal_amount).
|
||||
with_message("Invalid input. Please use only numbers. For example: 10, 5.5, -20")
|
||||
end
|
||||
|
||||
it do
|
||||
should validate_numericality_of(:preferred_normal_amount).
|
||||
with_message("Invalid input. Please use only numbers. For example: 10, 5.5, -20")
|
||||
end
|
||||
|
||||
it do
|
||||
should validate_numericality_of(:preferred_discount_amount).
|
||||
with_message("Invalid input. Please use only numbers. For example: 10, 5.5, -20")
|
||||
end
|
||||
|
||||
context 'when the order amount is below preferred minimal' do
|
||||
let(:price) { 2 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user