Skip to content

Commit

Permalink
changed validates_true_for for validates with :numerality
Browse files Browse the repository at this point in the history
  • Loading branch information
jairodiaz committed Jan 13, 2012
1 parent d96e7a9 commit 55f248f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/sage_pay/server/authorise.rb
Expand Up @@ -12,8 +12,8 @@ class Authorise < Command

validates_inclusion_of :apply_avs_cv2, :allow_blank => true, :in => (0..3).to_a

validates_true_for :amount, :key => :amount_minimum_value, :logic => lambda { amount.nil? || amount >= BigDecimal.new("0.01") }, :message => "is less than the minimum value (0.01)"
validates_true_for :amount, :key => :amount_maximum_value, :logic => lambda { amount.nil? || amount <= BigDecimal.new("100000") }, :message => "is greater than the maximum value (100,000.00)"
validates :amount, :numericality => {:message => "is less than the minimum value (0.01)", :greater_than_or_equal_to => BigDecimal.new("0.01")}
validates :amount, :numericality => {:message => "is greater than the maximum value (100,000.00)", :less_than_or_equal_toi => BigDecimal.new("100000")}

def post_params
params = super.merge({
Expand Down
5 changes: 2 additions & 3 deletions lib/sage_pay/server/refund.rb
Expand Up @@ -11,9 +11,8 @@ class Refund < Command
validates_length_of :currency, :is => 3
validates_length_of :description, :maximum => 100


validates_true_for :amount, :key => :amount_minimum_value, :logic => lambda { amount.nil? || amount >= BigDecimal.new("0.01") }, :message => "is less than the minimum value (0.01)"
validates_true_for :amount, :key => :amount_maximum_value, :logic => lambda { amount.nil? || amount <= BigDecimal.new("100000") }, :message => "is greater than the maximum value (100,000.00)"
validates :amount, :numericality => {:message => "is less than the minimum value (0.01)", :greater_than_or_equal_to => BigDecimal.new("0.01")}
validates :amount, :numericality => {:message => "is greater than the maximum value (100,000.00)", :less_than_or_equal_to => BigDecimal.new("100000")}

def post_params
super.merge({
Expand Down
4 changes: 2 additions & 2 deletions lib/sage_pay/server/registration.rb
Expand Up @@ -24,8 +24,8 @@ class Registration < Command
validates_inclusion_of :billing_agreement, :allow_blank => true, :in => [true, false]
validates_inclusion_of :account_type, :allow_blank => true, :in => [:ecommerce, :continuous_authority, :mail_order]

validates_true_for :amount, :key => :amount_minimum_value, :logic => lambda { amount.nil? || amount >= BigDecimal.new("0.01") }, :message => "is less than the minimum value (0.01)"
validates_true_for :amount, :key => :amount_maximum_value, :logic => lambda { amount.nil? || amount <= BigDecimal.new("100000") }, :message => "is greater than the maximum value (100,000.00)"
validates :amount, :numericality => {:message => "is less than the minimum value (0.01)", :greater_than_or_equal_to => BigDecimal.new("0.01")}
validates :amount, :numericality => {:message => "is greater than the maximum value (100,000.00)", :less_than_or_equal_to => BigDecimal.new("100000")}

def run!
if @response.nil? || (@vendor_tx_code_sent != vendor_tx_code)
Expand Down
5 changes: 2 additions & 3 deletions lib/sage_pay/server/release.rb
Expand Up @@ -12,9 +12,8 @@ class Release < Command
validates_length_of :vps_tx_id, :is => 38
validates_length_of :security_key, :is => 10


validates_true_for :release_amount, :key => :release_amount_minimum_value, :logic => lambda { release_amount.nil? || release_amount >= BigDecimal.new("0.01") }, :message => "is less than the minimum value (0.01)"
validates_true_for :release_amount, :key => :release_amount_maximum_value, :logic => lambda { release_amount.nil? || release_amount <= BigDecimal.new("100000") }, :message => "is greater than the maximum value (100,000.00)"
validates :amount, :numericality => {:message => "is less than the minimum value (0.01)", :greater_than_or_equal_to => BigDecimal.new("0.01")}
validates :amount, :numericality => {:message => "is greater than the maximum value (100,000.00)", :less_than_or_equal_toi => BigDecimal.new("100000")}

def post_params
super.merge({
Expand Down
4 changes: 2 additions & 2 deletions lib/sage_pay/server/repeat.rb
Expand Up @@ -11,8 +11,8 @@ class Repeat < Command
validates_length_of :currency, :is => 3
validates_length_of :description, :maximum => 100

validates_true_for :amount, :key => :amount_minimum_value, :logic => lambda { amount.nil? || amount >= BigDecimal.new("0.01") }, :message => "is less than the minimum value (0.01)"
validates_true_for :amount, :key => :amount_maximum_value, :logic => lambda { amount.nil? || amount <= BigDecimal.new("100000") }, :message => "is greater than the maximum value (100,000.00)"
validates :amount, :numericality => {:message => "is less than the minimum value (0.01)", :greater_than_or_equal_to => BigDecimal.new("0.01")}
validates :amount, :numericality => {:message => "is greater than the maximum value (100,000.00)", :less_than_or_equal_toi => BigDecimal.new("100000")}

def post_params
params = super.merge({
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/sage_pay/server_spec.rb
Expand Up @@ -3,7 +3,7 @@
if run_integration_specs?
describe SagePay::Server, "integration specs" do
before(:each) do
@vendor = "codescrumpills"
@vendor = "codescrumjairo"
#@notification_url = "https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorRegisterTx"
@notification_url = "http://190.146.87.50"

Expand Down

0 comments on commit 55f248f

Please sign in to comment.