Add numericality validation for PriceSack

This commit is contained in:
James Wu
2023-01-24 16:25:44 +09:00
committed by David Cook
parent c68987c0f2
commit 6b1426d0c6
2 changed files with 20 additions and 0 deletions

View File

@@ -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

View File

@@ -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 }