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]}
end
if params[:subscriptions] && !params[:subscriptions][:data].nil?
params.delete(:subscriptions) unless params[:subscriptions][:data].any?{ |v| !!v[:type]}
end
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(card.id) expect(original.default_source).to_not eq(card.id)
end end
it "still has sources after save when sources unchanged" do
original = Stripe::Customer.create(source: gen_card_tk)
card = original.sources.data.first
card_id = card.id
expect(original.sources.total_count).to eq(1)
original.save
expect(original.sources.data.first.id).to eq(card_id)
expect(original.sources.total_count).to eq(1)
end
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 = original.subscriptions.data.first
subscription_id = subscription.id
expect(original.subscriptions.total_count).to eq(1)
original.save
expect(original.subscriptions.data.first.id).to eq(subscription_id)
expect(original.subscriptions.total_count).to eq(1)
end
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