From 58520a0c4c4bda45cbffeed7010daaa61b044ffe Mon Sep 17 00:00:00 2001 From: Zil Norvilis Date: Wed, 25 Feb 2026 19:49:10 +0200 Subject: [PATCH] test: Add specs for the `stripe_card_options` helper method, verifying card formatting and month padding. --- spec/helpers/checkout_helper_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/helpers/checkout_helper_spec.rb b/spec/helpers/checkout_helper_spec.rb index d42ef87e87..f949a237fc 100644 --- a/spec/helpers/checkout_helper_spec.rb +++ b/spec/helpers/checkout_helper_spec.rb @@ -193,4 +193,25 @@ RSpec.describe CheckoutHelper do end end end + + describe "#stripe_card_options" do + let(:year) { Time.zone.now.year + 1 } + let(:card) { create(:credit_card, cc_type: 'visa', last_digits: '1111', month: 1, year:) } + let(:cards) { [card] } + + it "formats credit cards for Stripe options" do + options = helper.stripe_card_options(cards) + + expect(options).to eq([ + ["visa 1111 Exp:01/#{year}", card.id] + ]) + end + + it "zero-pads the month" do + card.update(month: 5) + options = helper.stripe_card_options(cards) + + expect(options.first.first).to match(%r{05/#{year}}) + end + end end