From 05c50e63e3ba8b4892c6b0f0d18b8e753b941409 Mon Sep 17 00:00:00 2001 From: Helen Ye Date: Mon, 28 Oct 2024 09:29:32 -0400 Subject: [PATCH 1/2] Fix refresh bug not returning specific instance type for custom resources --- lib/stripe/api_resource.rb | 3 ++- test/stripe/api_resource_test.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/stripe/api_resource.rb b/lib/stripe/api_resource.rb index 4a4c9ef9..532e2f80 100644 --- a/lib/stripe/api_resource.rb +++ b/lib/stripe/api_resource.rb @@ -98,7 +98,8 @@ def refresh "It is not possible to refresh v2 objects. Please retrieve the object using the StripeClient instead." end - @requestor.execute_request_initialize_from(:get, resource_url, :api, self, params: @retrieve_params) + @obj = @requestor.execute_request_initialize_from(:get, resource_url, :api, self, params: @retrieve_params) + initialize_from(@obj.last_response.data, {}, @obj.lat_response, api_mode: :v1, requestor: @requestor) end def self.retrieve(id, opts = {}) diff --git a/test/stripe/api_resource_test.rb b/test/stripe/api_resource_test.rb index c283aa5a..b43e7c63 100644 --- a/test/stripe/api_resource_test.rb +++ b/test/stripe/api_resource_test.rb @@ -931,7 +931,7 @@ def self.resource_url .to_return(body: JSON.generate({ id: "id", object: "custom_stripe_object", result: "hello" })) custom_stripe_object = CustomStripeObject.retrieve("id") - assert_instance_of Stripe::StripeObject, custom_stripe_object + assert_instance_of CustomStripeObject, custom_stripe_object assert_equal "hello", custom_stripe_object.result end end From 845b19cfa6167545a2c81a6d2fb734399b639786 Mon Sep 17 00:00:00 2001 From: Helen Ye Date: Mon, 28 Oct 2024 09:39:07 -0400 Subject: [PATCH 2/2] tests --- lib/stripe/api_resource.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/stripe/api_resource.rb b/lib/stripe/api_resource.rb index 532e2f80..d1e5f078 100644 --- a/lib/stripe/api_resource.rb +++ b/lib/stripe/api_resource.rb @@ -99,7 +99,13 @@ def refresh end @obj = @requestor.execute_request_initialize_from(:get, resource_url, :api, self, params: @retrieve_params) - initialize_from(@obj.last_response.data, {}, @obj.lat_response, api_mode: :v1, requestor: @requestor) + initialize_from( + @obj.last_response.data, + @obj.instance_variable_get(:@opts), + @obj.last_response, + api_mode: :v1, + requestor: @requestor + ) end def self.retrieve(id, opts = {})