diff --git a/lib/pro_account_bans.rb b/lib/pro_account_bans.rb index 20805060..b5f05473 100644 --- a/lib/pro_account_bans.rb +++ b/lib/pro_account_bans.rb @@ -2,7 +2,9 @@ module ProAccountBans module ModelMethods PRO_ACCOUNT_BANS_CONFIG = Rails.root.join('config/pro_account_bans.yml') - def update_source + def update_stripe_customer + return unless feature_enabled?(:pro_pricing) + return super unless @token return super unless pro_account_banned? sleep (4...10).to_a.sample unless Rails.env.test? # simulate random delay diff --git a/spec/pro_account_bans_spec.rb b/spec/pro_account_bans_spec.rb index 66f373ed..d5971209 100644 --- a/spec/pro_account_bans_spec.rb +++ b/spec/pro_account_bans_spec.rb @@ -11,7 +11,7 @@ let(:card_params) { { number: '4242424242424242', address_zip: 'AB1 1AB' } } let(:pro_account) { FactoryBot.build(:pro_account, token: stripe_token) } - let(:customer) { Stripe::Customer.new(id: 'test_cus_123') } + let(:customer) { Stripe::Customer.create(id: 'test_cus_123') } let(:stripe_token) do token_id = stripe_helper.generate_card_token(card_params) @@ -21,13 +21,13 @@ before do allow(pro_account).to receive(:bans_config).and_return(bans_config) allow(pro_account).to receive(:stripe_customer).and_return(customer) - allow(customer).to receive(:save) + allow(Stripe::Customer).to receive(:update).and_return(customer) end context 'with a valid token' do it 'updates the Stripe customer successfully' do expect(pro_account.update_stripe_customer).to be_truthy - expect(customer).to have_received(:save) + expect(Stripe::Customer).to have_received(:update) end end