Commit aa460045 authored by Alexander Mamonchik's avatar Alexander Mamonchik
Browse files

Merge pull request #283 from benjie/fix-customer-with-sources-save

Fix for saving a customer invalidating sources
parents 29dbe255 be47b34b
...@@ -62,6 +62,13 @@ module StripeMock ...@@ -62,6 +62,13 @@ module StripeMock
# Delete those params if their value is nil. Workaround of the problematic way Stripe serialize objects # Delete those params if their value is nil. Workaround of the problematic way Stripe serialize objects
params.delete(:sources) if params[:sources] && params[:sources][:data].nil? params.delete(:sources) if params[:sources] && params[:sources][:data].nil?
params.delete(:subscriptions) if params[:subscriptions] && params[:subscriptions][:data].nil? params.delete(:subscriptions) if params[:subscriptions] && params[:subscriptions][:data].nil?
# Delete those params if their values aren't valid. Workaround of the problematic way Stripe serialize objects
if params[:sources] && !params[:sources][:data].nil?
params.delete(:sources) unless params[:sources][:data].any?{ |v| !!v[:type]}
if params[:subscriptions] && !params[:subscriptions][:data].nil?
params.delete(:subscriptions) unless params[:subscriptions][:data].any?{ |v| !!v[:type]}
cus.merge!(params) cus.merge!(params)
if params[:source] if params[:source]
...@@ -318,6 +318,31 @@ shared_examples 'Customer API' do ...@@ -318,6 +318,31 @@ shared_examples 'Customer API' do
expect(original.default_source).to_not eq( expect(original.default_source).to_not eq(
end end
it "still has sources after save when sources unchanged" do
original = Stripe::Customer.create(source: gen_card_tk)
card =
card_id =
expect(original.sources.total_count).to eq(1)
expect( eq(card_id)
expect(original.sources.total_count).to eq(1)
it "still has subscriptions after save when subscriptions unchanged" do
plan = stripe_helper.create_plan(id: 'silver')
original = Stripe::Customer.create(source: gen_card_tk, plan: 'silver')
subscription =
subscription_id =
expect(original.subscriptions.total_count).to eq(1)
expect( eq(subscription_id)
expect(original.subscriptions.total_count).to eq(1)
it "deletes a customer" do it "deletes a customer" do
customer = Stripe::Customer.create(id: 'test_customer_sub') customer = Stripe::Customer.create(id: 'test_customer_sub')
customer = customer.delete customer = customer.delete
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment