Skip to content

Commit

Permalink
Always return the result of APIResource#refresh in APIResource.retrie…
Browse files Browse the repository at this point in the history
…ve (#1473)

* Always return the result of .refresh in .retrieve

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.

* Update install instructions for stripe-mock
  • Loading branch information
AnotherJoSmith authored Oct 23, 2024
1 parent a2e2881 commit 042918c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ background terminal ([stripe-mock's README][stripe-mock] also contains
instructions for installing via Homebrew and other methods):
```sh
go get -u github.com/stripe/stripe-mock
go install github.com/stripe/stripe-mock@latest
stripe-mock
```
Expand Down
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 042918c

Please sign in to comment.