Merge pull request #301 from stripe/brandur-symbolize-names

Perform deep name symbolization from .construct_from
This commit is contained in:
Brandur 2015-09-29 19:02:16 -07:00
commit f308bb3a52
2 changed files with 7 additions and 0 deletions

View File

@ -21,6 +21,7 @@ module Stripe
end
def self.construct_from(values, opts={})
values = Stripe::Util.symbolize_names(values)
self.new(values[:id]).refresh_from(values, opts)
end

View File

@ -9,6 +9,12 @@ module Stripe
assert !obj.respond_to?(:baz)
end
should "marshal be insensitive to strings vs. symbols when constructin" do
obj = Stripe::StripeObject.construct_from({ :id => 1, 'name' => 'Stripe' })
assert_equal 1, obj[:id]
assert_equal 'Stripe', obj[:name]
end
should "marshal a stripe object correctly" do
obj = Stripe::StripeObject.construct_from({ :id => 1, :name => 'Stripe' }, {:api_key => 'apikey'})
m = Marshal.load(Marshal.dump(obj))