@@ 3,7 3,8 @@
class PaymentMethods
def self.for(braintree_customer, badcards)
methods = braintree_customer.payment_methods.reject { |m|
- badcards.include?(m.unique_number_identifier)
+ badcards.include?(m.unique_number_identifier) ||
+ (m.respond_to?(:expired?) && m.expired?)
}
if methods.empty?
Empty.new
@@ 30,6 30,57 @@ class PaymentMethodsTest < Minitest::Test
assert methods.empty?
end
+ def test_for_expired_cards
+ braintree_customer = Minitest::Mock.new
+ braintree_customer.expect(:payment_methods, [
+ OpenStruct.new(
+ card_type: "Test",
+ last_4: "1234",
+ unique_number_identifier: "abc",
+ expired?: true
+ )
+ ])
+
+ methods = PaymentMethods.for(braintree_customer, [])
+ assert_kind_of PaymentMethods, methods
+ assert_equal 0, methods.to_a.length
+ assert methods.empty?
+ end
+
+ def test_for_badcards_and_expired_cards
+ braintree_customer = Minitest::Mock.new
+ braintree_customer.expect(:payment_methods, [
+ OpenStruct.new(
+ card_type: "Test",
+ last_4: "1234",
+ unique_number_identifier: "abc",
+ expired?: true
+ )
+ ])
+
+ methods = PaymentMethods.for(braintree_customer, ["abc"])
+ assert_kind_of PaymentMethods, methods
+ assert_equal 0, methods.to_a.length
+ assert methods.empty?
+ end
+
+ def test_for_non_expired_cards
+ braintree_customer = Minitest::Mock.new
+ braintree_customer.expect(:payment_methods, [
+ OpenStruct.new(
+ card_type: "Test",
+ last_4: "1234",
+ unique_number_identifier: "abc",
+ expired?: false
+ )
+ ])
+
+ methods = PaymentMethods.for(braintree_customer, [])
+ assert_kind_of PaymentMethods, methods
+ assert_equal 1, methods.to_a.length
+ refute methods.empty?
+ end
+
def test_for_no_methods
braintree_customer = Minitest::Mock.new
braintree_customer.expect(:payment_methods, [])