Skip to content

Commit

Permalink
Check for presence in Spree::CreditCard#expiry method
Browse files Browse the repository at this point in the history
The expiry method needs to check for presence before parsing. An empty card expiration field will raise the error "no implicit conversion of nil into String" on submission.

Fixes spree#3847
Fixes spree#3896
  • Loading branch information
SkylerRogers authored and radar committed Oct 22, 2013
1 parent 3958934 commit 6c962f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/app/models/spree/credit_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class CreditCard < ActiveRecord::Base
alias_attribute :brand, :cc_type

def expiry=(expiry)
self[:month], self[:year] = expiry.split(" / ")
self[:year] = "20" + self[:year]
if expiry.present?
self[:month], self[:year] = expiry.split(" / ")
self[:year] = "20" + self[:year]
end
end

def number=(num)
Expand Down
19 changes: 19 additions & 0 deletions core/spec/models/spree/credit_card_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ def stub_rails_env(environment)
end
end

# Regression test for #3847 & #3896
context "#expiry=" do
it "can set with a 2-digit month and year" do
credit_card.expiry = '04 / 14'
credit_card.month = '04'
credit_card.year = '2014'
end

it "can set with a 2-digit month and 4-digit year" do
credit_card.expiry = '04 / 2014'
credit_card.month = '04'
credit_card.year = '2014'
end

it "does not blow up when passed an empty string" do
lambda { credit_card.expiry = '' }.should_not raise_error
end
end

context "#cc_type=" do
it "converts between the different types" do
credit_card.cc_type = 'mastercard'
Expand Down

0 comments on commit 6c962f4

Please sign in to comment.