Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
knowmalaria
stripe-ruby-mock
Commits
aa460045
Commit
aa460045
authored
Jan 11, 2016
by
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/stripe_mock/request_handlers/customers.rb
View file @
aa460045
...
...
@@ -62,6 +62,13 @@ 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?
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
)
if
params
[
:source
]
...
...
spec/shared_stripe_examples/customer_examples.rb
View file @
aa460045
...
...
@@ -318,6 +318,31 @@ shared_examples 'Customer API' do
expect
(
original
.
default_source
).
to_not
eq
(
card
.
id
)
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
customer
=
Stripe
::
Customer
.
create
(
id:
'test_customer_sub'
)
customer
=
customer
.
delete
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment