Permalink
Browse files

Merge branch 'payment_method_year' of https://github.com/jmoline/zuora

…into jmoline-payment_method_year
  • Loading branch information...
2 parents c47d919 + 8c14557 commit fc6328a64dede5fa111279fe5dda5c5bb39e3e2f @oesmith oesmith committed Jun 27, 2012
Showing with 25 additions and 2 deletions.
  1. +1 −1 lib/zuora/objects/payment_method.rb
  2. +24 −1 spec/zuora/objects/payment_method_spec.rb
@@ -23,7 +23,7 @@ class PaymentMethod < Base
validates_length_of :credit_card_postal_code, :maximum => 20, :if => :card?
validates_length_of :credit_card_country, :maximum => 40, :allow_nil => true, :if => :card?
validates_numericality_of :credit_card_expiration_month, :integer_only => true, :within => 1..12, :if => :card?
- validates_numericality_of :credit_card_expiration_year, :integer_only => true, :greater_than => lambda{|e| Date.today.year }, :if => :card?
+ validates_numericality_of :credit_card_expiration_year, :integer_only => true, :greater_than => lambda{|e| (Date.today - 1.year).year }, :if => :card?
validates_length_of :credit_card_holder_name, :maximum => 50, :if => :card?
validates_length_of :credit_card_number, :maximum => 16, :if => :card?
validates_inclusion_of :credit_card_type, :in => %w(AmericanExpress Discover MasterCard Visa), :if => :card?
@@ -34,10 +34,33 @@
:credit_card_security_code, :gateway_option_data, :skip_validation]
end
+ describe "validations" do
+ describe "credit_card_expiration_year" do
+ let(:payment_method) {Zuora::Objects::PaymentMethod.new(:type => "CreditCard")}
+ it "should allow this year" do
+ payment_method.credit_card_expiration_year = Time.now.year
+ payment_method.valid?
+ payment_method.errors[:credit_card_expiration_year].should_not include("must be greater than #{(Time.now - 1.year).year}")
+ end
+
+ it "should not allow last year" do
+ payment_method.credit_card_expiration_year = (Time.now - 1.year).year
+ payment_method.valid?
+ payment_method.errors[:credit_card_expiration_year].should include("must be greater than #{(Time.now - 1.year).year}")
+ end
+
+ it "should allow next year" do
+ payment_method.credit_card_expiration_year = (Time.now + 1.year).year
+ payment_method.valid?
+ payment_method.errors[:credit_card_expiration_year].should_not include("must be greater than #{(Time.now - 1.year).year}")
+ end
+ end
+ end
+
describe "Credit Card" do
it "generates proper request xml" do
MockResponse.responds_with(:payment_method_credit_card_create_success) do
-
+
FactoryGirl.create(:payment_method_credit_card, :account => @account)
xml = Zuora::Api.instance.last_request

0 comments on commit fc6328a

Please sign in to comment.