Commit be47b34b authored by Benjie Gillam's avatar Benjie Gillam
Browse files

Restore total_count functionality.

parent 454a71c7
......@@ -62,13 +62,12 @@ module StripeMock
# 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(: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?
# Copy old sources over empty objects
params[:sources][:data].collect!.with_index {|v, i| !v[:type] ? cus[:sources][:data][i].clone : v }
params.delete(:sources) unless params[:sources][:data].any?{ |v| !!v[:type]}
end
if params[:subscriptions] && !params[:subscriptions][:data].nil?
# Copy old subscriptions over empty objects
params[:subscriptions][:data].collect!.with_index {|v, i| !v[:type] ? cus[:subscriptions][:data][i].clone : v }
params.delete(:subscriptions) unless params[:subscriptions][:data].any?{ |v| !!v[:type]}
end
cus.merge!(params)
......
......@@ -322,10 +322,12 @@ shared_examples 'Customer API' 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
......@@ -333,10 +335,12 @@ shared_examples 'Customer API' do
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
......
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