diff --git a/lib/stripe/stripe_client.rb b/lib/stripe/stripe_client.rb index 27f95afcb..782b862a4 100644 --- a/lib/stripe/stripe_client.rb +++ b/lib/stripe/stripe_client.rb @@ -76,7 +76,7 @@ def raw_request(method, url, base_address: :api, params: {}, opts: {}) def deserialize(data, api_mode: :v1) data = JSON.parse(data) if data.is_a?(String) - Util.convert_to_stripe_object(data, {}, api_mode: api_mode) + Util.convert_to_stripe_object(data, {}, api_mode: api_mode, requestor: @requestor) end end end diff --git a/lib/stripe/stripe_object.rb b/lib/stripe/stripe_object.rb index c73f8ee50..2b262e2b2 100644 --- a/lib/stripe/stripe_object.rb +++ b/lib/stripe/stripe_object.rb @@ -153,7 +153,7 @@ def inspect def update_attributes(values, opts = {}, dirty: true) values.each do |k, v| add_accessors([k], values) unless metaclass.method_defined?(k.to_sym) - @values[k] = Util.convert_to_stripe_object(v, opts, api_mode: @api_mode) + @values[k] = Util.convert_to_stripe_object(v, opts, api_mode: @api_mode, requestor: @requestor) dirty_value!(@values[k]) if dirty @unsaved_values.add(k) end @@ -361,7 +361,7 @@ class << self; self; end "We interpret empty strings as nil in requests. " \ "You may set (object).#{k} = nil to delete the property." end - @values[k] = Util.convert_to_stripe_object(v, @opts, api_mode: @api_mode) + @values[k] = Util.convert_to_stripe_object(v, @opts, api_mode: @api_mode, requestor: @requestor) dirty_value!(@values[k]) @unsaved_values.add(k) end @@ -534,7 +534,7 @@ class << self; self; end # example by appending a new hash onto `additional_owners` for an # account. elsif value.is_a?(Hash) - Util.convert_to_stripe_object(value, @opts).serialize_params + Util.convert_to_stripe_object(value, @opts, api_mode: @api_mode, requestor: @requestor).serialize_params elsif value.is_a?(StripeObject) update = value.serialize_params(force: force) diff --git a/lib/stripe/util.rb b/lib/stripe/util.rb index d03e758c2..1fe3da44b 100644 --- a/lib/stripe/util.rb +++ b/lib/stripe/util.rb @@ -127,7 +127,7 @@ def self.convert_to_stripe_object_with_params( case data when Array - data.map { |i| convert_to_stripe_object(i, opts, api_mode: api_mode) } + data.map { |i| convert_to_stripe_object(i, opts, api_mode: api_mode, requestor: requestor) } when Hash # TODO: This is a terrible hack. # Waiting on https://jira.corp.stripe.com/browse/API_SERVICES-3167 to add diff --git a/test/stripe/list_object_test.rb b/test/stripe/list_object_test.rb index 7debc8bf9..0f4a888c2 100644 --- a/test/stripe/list_object_test.rb +++ b/test/stripe/list_object_test.rb @@ -14,6 +14,13 @@ class ListObjectTest < Test::Unit::TestCase assert_equal 1, list.count end + should "be able to refresh objects in list" do + list = Stripe::Customer.list + assert_not_nil list.first.instance_variable_get(:@requestor) + cus = list.first.refresh + assert cus.is_a?(Stripe::Customer) + end + should "provide #each" do arr = [ { id: 1 }, diff --git a/test/stripe/search_result_object_test.rb b/test/stripe/search_result_object_test.rb index 9a87ff944..4926a4480 100644 --- a/test/stripe/search_result_object_test.rb +++ b/test/stripe/search_result_object_test.rb @@ -14,6 +14,13 @@ class SearchResultObjectTest < Test::Unit::TestCase assert_equal 1, list.count end + should "be able to refresh objects in search" do + list = Stripe::Customer.search({ query: "name:'fakename'" }) + assert_not_nil list.first.instance_variable_get(:@requestor) + cus = list.first.refresh + assert cus.is_a?(Stripe::Customer) + end + should "provide #each" do arr = [ { id: 1 }, diff --git a/test/stripe/stripe_client_test.rb b/test/stripe/stripe_client_test.rb index a94080aff..056182c9c 100644 --- a/test/stripe/stripe_client_test.rb +++ b/test/stripe/stripe_client_test.rb @@ -309,6 +309,19 @@ class StripeClientTest < Test::Unit::TestCase assert_equal obj.id, "acc_123" end + should "allow refresh on deserialized object" do + expected_body = "{\"id\": \"acc_123\", \"object\": \"account\"}" + + stub_request(:get, "#{Stripe::DEFAULT_API_BASE}/v1/accounts/acc_123") + .to_return(status: 200, body: expected_body) + + obj = @client.deserialize(expected_body) + obj = obj.refresh + + assert_equal obj.class, Stripe::Account + assert_equal obj.id, "acc_123" + end + should "deserializes hash into unknown object" do expected_body = { "id" => "acc_123", "object" => "unknown" }