mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
add spec for deleting the default card
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user