diff --git a/core/app/models/spree/credit_card.rb b/core/app/models/spree/credit_card.rb index 21bc709ec10..4351b3611e4 100644 --- a/core/app/models/spree/credit_card.rb +++ b/core/app/models/spree/credit_card.rb @@ -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) diff --git a/core/spec/models/spree/credit_card_spec.rb b/core/spec/models/spree/credit_card_spec.rb index 0142064c768..d0aa01f12db 100644 --- a/core/spec/models/spree/credit_card_spec.rb +++ b/core/spec/models/spree/credit_card_spec.rb @@ -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'