Change summary
lib/payment_methods.rb | 6 +++++-
test/test_payment_methods.rb | 10 +++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
Detailed changes
@@ -19,6 +19,10 @@ class PaymentMethods
end
def default_payment_method
+ @methods.find(&:default?)
+ end
+
+ def default_payment_method_index
@methods.index(&:default?)&.to_s
end
@@ -37,7 +41,7 @@ class PaymentMethods
type: "list-single",
label: "Credit card to pay with",
required: true,
- value: default_payment_method,
+ value: default_payment_method_index,
options: to_options
}.merge(kwargs)
end
@@ -27,7 +27,15 @@ class PaymentMethodsTest < Minitest::Test
OpenStruct.new(card_type: "Test", last_4: "1234"),
OpenStruct.new(card_type: "Test", last_4: "1234", default?: true)
])
- assert_equal "1", methods.default_payment_method
+ assert_equal methods.fetch(1), methods.default_payment_method
+ end
+
+ def test_default_payment_method_index
+ methods = PaymentMethods.new([
+ OpenStruct.new(card_type: "Test", last_4: "1234"),
+ OpenStruct.new(card_type: "Test", last_4: "1234", default?: true)
+ ])
+ assert_equal "1", methods.default_payment_method_index
end
def test_to_options