M lib/payment_methods.rb => lib/payment_methods.rb +5 -1
@@ 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
M test/test_payment_methods.rb => test/test_payment_methods.rb +9 -1
@@ 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