From d3e40bb1de2005e1d64ff5f75cd6363f3564d462 Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Thu, 16 Mar 2017 00:49:37 +0100 Subject: [PATCH] Exclude client when dumping objects --- lib/stripe/stripe_object.rb | 7 ++++++- test/stripe/stripe_object_test.rb | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/stripe/stripe_object.rb b/lib/stripe/stripe_object.rb index fea190ad..4ea943e5 100644 --- a/lib/stripe/stripe_object.rb +++ b/lib/stripe/stripe_object.rb @@ -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) diff --git a/test/stripe/stripe_object_test.rb b/test/stripe/stripe_object_test.rb index d8dbc454..a5246a0c 100644 --- a/test/stripe/stripe_object_test.rb +++ b/test/stripe/stripe_object_test.rb @@ -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