Skip to content

Commit

Permalink
create tests for initiating recurring donation in store_controller#pr…
Browse files Browse the repository at this point in the history
…ocess_donation
  • Loading branch information
winsonwan committed Mar 6, 2024
1 parent a230d54 commit 43823d2
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec/controllers/store_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,36 @@
end
end

describe 'initiating a recurring donation' do
before :each do
@customer = create(:customer)
end
let (:monthly_donation_attempt) {
post :process_donation,
{:customer_id => @customer.id, :donation => 5, :donation_frequency => 'monthly', :credit_card_token => 'dummy'}
}
context 'when donation completes successful' do
before :each do
allow(Stripe::Charge).to receive(:create).and_return(double("Stripe::Charge", id: 1))
end
it 'creates a new RecurringDonation record' do
expect{monthly_donation_attempt}.to change {RecurringDonation.count}.by(1)
end
it 'adds a foreign key to the corresponding first donation instance' do
monthly_donation_attempt
expect(Donation.find(1).recurring_donation_id).to equal(RecurringDonation.find(1).id)
end
end
context 'when donation completes unsuccessfully' do
before :each do
allow(Stripe::Charge).to receive(:create).and_raise(Stripe::StripeError)
end
it 'does not create new RecurringDonation record if order fails to finalize' do
expect{monthly_donation_attempt}.to change {RecurringDonation.count}.by(0)
end
end
end

describe 'quick donation with nonexistent customer' do
before :each do
@new_valid_customer = attributes_for(:customer).except(:password,:password_confirmation)
Expand Down

0 comments on commit 43823d2

Please sign in to comment.