Exclude client when dumping objects

This commit is contained in:
Olivier Bellone 2017-03-16 00:49:37 +01:00
parent eb0883ee75
commit d3e40bb1de
2 changed files with 15 additions and 2 deletions

View File

@ -137,7 +137,12 @@ module Stripe
end
def _dump(level)
Marshal.dump([@values, @opts])
# The StripeClient instance in @opts is not serializable and is not
# really a property of the StripeObject, so we exclude it when
# dumping
opts = @opts.clone
opts.delete(:client)
Marshal.dump([@values, opts])
end
def self._load(args)

View File

@ -36,7 +36,15 @@ module Stripe
end
should "marshal a stripe object correctly" do
obj = Stripe::StripeObject.construct_from({ :id => 1, :name => 'Stripe' }, {:api_key => 'apikey'})
obj = Stripe::StripeObject.construct_from(
{ :id => 1, :name => 'Stripe' },
{
:api_key => 'apikey',
# StripeClient is not serializable and is expected to be removed
# when marshalling StripeObjects
:client => StripeClient.active_client,
}
)
m = Marshal.load(Marshal.dump(obj))
assert_equal 1, m.id
assert_equal 'Stripe', m.name