mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-09-22 00:00:31 -04:00
In StripeObject#to_hash, call #to_hash on values which respond to it
This commit is contained in:
parent
218178ea54
commit
310c69e90d
@ -95,7 +95,10 @@ module Stripe
|
||||
end
|
||||
|
||||
def to_hash
|
||||
@values
|
||||
@values.inject({}) do |acc, (key, value)|
|
||||
acc[key] = value.respond_to?(:to_hash) ? value.to_hash : value
|
||||
acc
|
||||
end
|
||||
end
|
||||
|
||||
def each(&blk)
|
||||
|
@ -16,5 +16,12 @@ module Stripe
|
||||
assert_equal m.name, 'Stripe'
|
||||
assert_equal m.api_key, 'apikey'
|
||||
end
|
||||
|
||||
should "recursively call to_hash on its values" do
|
||||
nested = Stripe::StripeObject.construct_from({ :id => 7, :foo => 'bar' })
|
||||
obj = Stripe::StripeObject.construct_from({ :id => 1, :nested => nested })
|
||||
expected_hash = { :id => 1, :nested => { :id => 7, :foo => 'bar' } }
|
||||
assert_equal expected_hash, obj.to_hash
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user