Skip to content

Commit

Permalink
Fix APIResource#retrieve bug not returning instance of custom resourc…
Browse files Browse the repository at this point in the history
…es (#1476)

* Fix refresh bug not returning specific instance type for custom resources

* tests
  • Loading branch information
helenye-stripe authored Oct 28, 2024
1 parent 4c3593e commit fb11d83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/stripe/api_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ 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.instance_variable_get(:@opts),
@obj.last_response,
api_mode: :v1,
requestor: @requestor
)
end

def self.retrieve(id, opts = {})
Expand Down
2 changes: 1 addition & 1 deletion test/stripe/api_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb11d83

Please sign in to comment.