add spec for deleting the default card

This commit is contained in:
Andy Brett
2020-12-10 12:31:58 -08:00
parent 3daccb6420
commit 3b7313f7e3
2 changed files with 21 additions and 0 deletions

View File

@@ -47,6 +47,7 @@ module Spree
# Using try because we may not have a card here
if @credit_card.try(:destroy)
remove_shop_authorizations if @credit_card.is_default
flash[:success] = I18n.t(:card_has_been_removed, number: "x-#{@credit_card.last_digits}")
else
flash[:error] = I18n.t(:card_could_not_be_removed)

View File

@@ -188,6 +188,26 @@ describe Spree::CreditCardsController, type: :controller do
expect(flash[:success]).to eq I18n.t(:card_has_been_removed, number: "x-#{card.last_digits}")
expect(response).to redirect_to spree.account_path(anchor: 'cards')
end
context "the card is the default card and there are existing authorizations for the user" do
before do
card.update_attribute(:is_default, true)
end
let!(:customer1) { create(:customer, allow_charges: true) }
let!(:customer2) { create(:customer, allow_charges: true) }
it "removes the authorizations" do
customer1.user = card.user
customer2.user = card.user
customer1.save
customer2.save
expect(customer1.reload.allow_charges).to be true
expect(customer2.reload.allow_charges).to be true
spree_delete :destroy, params
expect(customer1.reload.allow_charges).to be false
expect(customer2.reload.allow_charges).to be false
end
end
end
end
end