From 91bcf0c58064673852ee3426a226919bd8e0b0d4 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Mon, 22 Sep 2014 11:21:12 +0200 Subject: [PATCH] Avoid out of range error when using big numbers in financial transactions. The database schema allows numbers up (+/-) 999_999.99. But as we are also adding the amount to the Ordergroup#account_balance, we use lower barriers to avoid running in errors when updating the account balance. So, technically the user has to make 10 times the maximum input to raise an account balance error. This should be sufficient, I hope. --- app/models/financial_transaction.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/financial_transaction.rb b/app/models/financial_transaction.rb index 354a3d2a..631390b6 100644 --- a/app/models/financial_transaction.rb +++ b/app/models/financial_transaction.rb @@ -3,9 +3,10 @@ class FinancialTransaction < ActiveRecord::Base belongs_to :ordergroup belongs_to :user - + validates_presence_of :amount, :note, :user_id, :ordergroup_id - validates_numericality_of :amount + validates_numericality_of :amount, greater_then: -100_000, + less_than: 100_000 localize_input_of :amount @@ -14,4 +15,3 @@ class FinancialTransaction < ActiveRecord::Base ordergroup.add_financial_transaction! amount, note, user end end -