Merge pull request #528 from iamvery/iamvery/add-boolean-predicates-when-accessor-is-missing

Include predicate for lazily added boolean accessors
This commit is contained in:
Brandur 2017-04-14 09:46:56 -07:00 committed by GitHub
commit 34b524547a
2 changed files with 9 additions and 1 deletions

View File

@ -262,9 +262,10 @@ module Stripe
# TODO: only allow setting in updateable classes.
if name.to_s.end_with?('=')
attr = name.to_s[0...-1].to_sym
val = args.first
# the second argument is only required when adding boolean accessors
add_accessors([attr], {})
add_accessors([attr], { attr => val })
begin
mth = method(name)

View File

@ -80,6 +80,13 @@ module Stripe
refute obj.respond_to?(:not_bool?)
end
should "assign question mark accessors for booleans added after initialization" do
obj = Stripe::StripeObject.new
obj.bool = true
assert obj.respond_to?(:bool?)
assert obj.bool?
end
should "mass assign values with #update_attributes" do
obj = Stripe::StripeObject.construct_from({ :id => 1, :name => 'Stripe' })
obj.update_attributes(:name => 'STRIPE')