1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

fix loading of different elements in array then int and string [#5036 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Josef Reidinger 2010-07-27 09:55:33 +02:00 committed by José Valim
parent e1344bf504
commit 59693c4c49
2 changed files with 15 additions and 3 deletions

View file

@ -1222,10 +1222,10 @@ module ActiveResource
when Array when Array
resource = find_or_create_resource_for_collection(key) resource = find_or_create_resource_for_collection(key)
value.map do |attrs| value.map do |attrs|
if attrs.is_a?(String) || attrs.is_a?(Numeric) if attrs.is_a?(Hash)
attrs.duplicable? ? attrs.dup : attrs
else
resource.new(attrs) resource.new(attrs)
else
attrs.duplicable? ? attrs.dup : attrs
end end
end end
when Hash when Hash

View file

@ -47,6 +47,8 @@ class BaseLoadTest < Test::Unit::TestCase
{ :id => 1, :name => 'Willamette' }, { :id => 1, :name => 'Willamette' },
{ :id => 2, :name => 'Columbia', :rafted_by => @matz }], { :id => 2, :name => 'Columbia', :rafted_by => @matz }],
:postal_codes => [ 97018, 1234567890 ], :postal_codes => [ 97018, 1234567890 ],
:dates => [ Time.now ],
:votes => [ true, false, true ],
:places => [ "Columbia City", "Unknown" ]}}} :places => [ "Columbia City", "Unknown" ]}}}
@person = Person.new @person = Person.new
@ -149,6 +151,16 @@ class BaseLoadTest < Test::Unit::TestCase
assert_kind_of Array, places assert_kind_of Array, places
assert_kind_of String, places.first assert_kind_of String, places.first
assert_equal @deep[:street][:state][:places].first, places.first assert_equal @deep[:street][:state][:places].first, places.first
dates = state.dates
assert_kind_of Array, dates
assert_kind_of Time, dates.first
assert_equal @deep[:street][:state][:dates].first, dates.first
votes = state.votes
assert_kind_of Array, votes
assert_kind_of TrueClass, votes.first
assert_equal @deep[:street][:state][:votes].first, votes.first
end end
def test_nested_collections_within_the_same_namespace def test_nested_collections_within_the_same_namespace