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

Explicitly pass a parameter as hash to be more ruby 2.7 friendly #892

Merged
merged 4 commits into from
Jan 10, 2020
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
3 changes: 2 additions & 1 deletion lib/stripe/stripe_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ def inspect
# ==== Attributes
#
# * +values+ - Hash of values to use to update the current attributes of
# the object.
# the object. If you are on ruby 2.7 or higher make sure to wrap in curly
# braces to be ruby 3 compatible.
# * +opts+ - Options for +StripeObject+ like an API key that will be reused
# on subsequent API calls.
#
Expand Down
13 changes: 8 additions & 5 deletions test/stripe/stripe_object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,26 +212,29 @@ def to_hash

should "mass assign values with #update_attributes" do
obj = Stripe::StripeObject.construct_from(id: 1, name: "Stripe")
obj.update_attributes(name: "STRIPE")

obj.update_attributes({ name: "STRIPE" }) # rubocop:disable Style/BracesAroundHashParameters

assert_equal "STRIPE", obj.name

# unfortunately, we even assign unknown properties to duplicate the
# behavior that we currently have via magic accessors with
# method_missing
obj.update_attributes(unknown: "foo")
obj.update_attributes({ unknown: "foo" }) # rubocop:disable Style/BracesAroundHashParameters

assert_equal "foo", obj.unknown
end

should "#update_attributes with a hash" do
obj = Stripe::StripeObject.construct_from({})
obj.update_attributes(metadata: { foo: "bar" })
obj.update_attributes({ metadata: { foo: "bar" } }) # rubocop:disable Style/BracesAroundHashParameters
assert_equal Stripe::StripeObject, obj.metadata.class
end

should "create accessors when #update_attributes is called" do
obj = Stripe::StripeObject.construct_from({})
assert_equal false, obj.send(:metaclass).method_defined?(:foo)
obj.update_attributes(foo: "bar")
obj.update_attributes({ foo: "bar" }) # rubocop:disable Style/BracesAroundHashParameters
assert_equal true, obj.send(:metaclass).method_defined?(:foo)
end

Expand Down Expand Up @@ -268,7 +271,7 @@ def to_hash

should "#serialize_params on a basic object" do
obj = Stripe::StripeObject.construct_from(foo: nil)
obj.update_attributes(foo: "bar")
obj.update_attributes({ foo: "bar" }) # rubocop:disable Style/BracesAroundHashParameters
assert_equal({ foo: "bar" }, obj.serialize_params)
end

Expand Down