From 677f31ffa838169aa2ea48df748b7d705b1880f8 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Wed, 26 Feb 2020 11:55:17 +0000 Subject: [PATCH] Make payment source_views/gateway work with nil credit card This will happen if user deletes a saved credit card used previously. In this case, the admin payment details page will render empty details and the payment amount --- .../payments/source_views/_gateway.html.haml | 14 +++++++------- spec/features/admin/payments_spec.rb | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/views/spree/admin/payments/source_views/_gateway.html.haml b/app/views/spree/admin/payments/source_views/_gateway.html.haml index bd366492ba..ebd63febc0 100644 --- a/app/views/spree/admin/payments/source_views/_gateway.html.haml +++ b/app/views/spree/admin/payments/source_views/_gateway.html.haml @@ -6,28 +6,28 @@ %dt = Spree.t(:card_number) \: - %dd= payment.source.display_number + %dd= payment.source&.display_number %dt = Spree.t(:expiration) \: %dd - = payment.source.month + = payment.source&.month \/ - = payment.source.year + = payment.source&.year %dt = Spree.t(:card_code) \: - %dd= payment.source.verification_value + %dd= payment.source&.verification_value .omega.six.columns %dl %dt = t(:maestro_or_solo_cards) \: - %dd= payment.source.issue_number + %dd= payment.source&.issue_number %dt = Spree.t(:start_date) \: %dd - = payment.source.start_month + = payment.source&.start_month \/ - = payment.source.start_year + = payment.source&.start_year diff --git a/spec/features/admin/payments_spec.rb b/spec/features/admin/payments_spec.rb index d6f402147e..2ea666f121 100644 --- a/spec/features/admin/payments_spec.rb +++ b/spec/features/admin/payments_spec.rb @@ -10,7 +10,6 @@ feature ' scenario "visiting the payment form" do quick_login_as_admin - visit spree.new_admin_order_payment_path order expect(page).to have_content "New Payment" @@ -28,7 +27,6 @@ feature ' scenario "visiting the payment form" do quick_login_as_admin - visit spree.new_admin_order_payment_path order expect(page).to have_content "New Payment" @@ -43,11 +41,24 @@ feature ' it "renders the payment details" do quick_login_as_admin - visit spree.admin_order_payments_path order page.click_link("StripeSCA") expect(page).to have_content order.payments.last.source.last_digits end + + context "with a deleted credit card" do + before do + order.payments.last.update_attribute(:source, nil) + end + + it "renders the payment details" do + quick_login_as_admin + visit spree.admin_order_payments_path order + + page.click_link("StripeSCA") + expect(page).to have_content order.payments.last.amount + end + end end end