mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-06-03 00:01:47 -04:00
Merge pull request #479 from Amos47/recurse-on-stripe-objects
Allow to_s to also pretty_generate embedded StripeObjects
This commit is contained in:
commit
1c4d43aad5
@ -43,7 +43,7 @@ module Stripe
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s(*args)
|
def to_s(*args)
|
||||||
JSON.pretty_generate(@values)
|
JSON.pretty_generate(to_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
|
@ -292,6 +292,38 @@ module Stripe
|
|||||||
assert_equal({ :id => 'id', :metadata => { :foo => 'bar' } }, serialized)
|
assert_equal({ :id => 'id', :metadata => { :foo => 'bar' } }, serialized)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "#to_s will call to_s for all embedded stripe objects" do
|
||||||
|
obj = Stripe::StripeObject.construct_from({
|
||||||
|
id: 'id',
|
||||||
|
#embeded list object
|
||||||
|
refunds: Stripe::ListObject.construct_from({ data: [
|
||||||
|
#embedded object in list
|
||||||
|
Stripe::StripeObject.construct_from({
|
||||||
|
id: 'id',
|
||||||
|
#embedded object in an object in a list object
|
||||||
|
metadata: Stripe::StripeObject.construct_from({
|
||||||
|
foo: 'bar',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
]}),
|
||||||
|
# embeded stripe object
|
||||||
|
metadata: Stripe::StripeObject.construct_from({
|
||||||
|
foo: 'bar',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
expected = JSON.pretty_generate({
|
||||||
|
id: 'id',
|
||||||
|
refunds: {
|
||||||
|
data: [
|
||||||
|
{id: 'id', metadata: {foo: 'bar'}}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
metadata: { foo: 'bar' }
|
||||||
|
})
|
||||||
|
|
||||||
|
assert_equal(expected, obj.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
should "warn that .serialize_params is deprecated" do
|
should "warn that .serialize_params is deprecated" do
|
||||||
old_stderr = $stderr
|
old_stderr = $stderr
|
||||||
$stderr = StringIO.new
|
$stderr = StringIO.new
|
||||||
|
Loading…
x
Reference in New Issue
Block a user