Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix APIResource#retrieve bug not returning instance of custom resources #1476

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading