Skip to content

Commit

Permalink
Always return the result of .refresh in .retrieve
Browse files Browse the repository at this point in the history
With the refactor of v13, there are now cases where `self` is not
mutated in the call to refresh and instead a new object is returned.
This change ensures that the new object is always returned by returning
the result of refresh instead.
  • Loading branch information
AnotherJoSmith committed Oct 23, 2024
1 parent a2e2881 commit 5face29
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/stripe/api_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def self.retrieve(id, opts = {})
opts = Util.normalize_opts(opts)
instance = new(id, opts)
instance.refresh
instance
end

def request_stripe_object(method:, path:, params:, base_address: :api, opts: {})
Expand Down
17 changes: 17 additions & 0 deletions test/stripe/api_resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,23 @@ def self.object_name
end
end

class CustomStripeObject < APIResource
def self.resource_url
"/v1/custom_stripe_object"
end
end

context "custom class extending APIResource" do
should "return StripeObject instance when calling retrieve" do
stub_request(:get, "#{Stripe.api_base}/v1/custom_stripe_object/id")
.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_equal "hello", custom_stripe_object.result
end
end

@@fixtures = {} # rubocop:disable Style/ClassVars
setup do
if @@fixtures.empty?
Expand Down

0 comments on commit 5face29

Please sign in to comment.