Skip to content

Commit 59693c4

Browse files
jreidingerjosevalim
authored andcommitted
fix loading of different elements in array then int and string [rails#5036 state:resolved]
Signed-off-by: José Valim <[email protected]>
1 parent e1344bf commit 59693c4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

activeresource/lib/active_resource/base.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,10 +1222,10 @@ def load(attributes)
12221222
when Array
12231223
resource = find_or_create_resource_for_collection(key)
12241224
value.map do |attrs|
1225-
if attrs.is_a?(String) || attrs.is_a?(Numeric)
1226-
attrs.duplicable? ? attrs.dup : attrs
1227-
else
1225+
if attrs.is_a?(Hash)
12281226
resource.new(attrs)
1227+
else
1228+
attrs.duplicable? ? attrs.dup : attrs
12291229
end
12301230
end
12311231
when Hash

activeresource/test/cases/base/load_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def setup
4747
{ :id => 1, :name => 'Willamette' },
4848
{ :id => 2, :name => 'Columbia', :rafted_by => @matz }],
4949
:postal_codes => [ 97018, 1234567890 ],
50+
:dates => [ Time.now ],
51+
:votes => [ true, false, true ],
5052
:places => [ "Columbia City", "Unknown" ]}}}
5153

5254
@person = Person.new
@@ -149,6 +151,16 @@ def test_recursively_loaded_collections
149151
assert_kind_of Array, places
150152
assert_kind_of String, places.first
151153
assert_equal @deep[:street][:state][:places].first, places.first
154+
155+
dates = state.dates
156+
assert_kind_of Array, dates
157+
assert_kind_of Time, dates.first
158+
assert_equal @deep[:street][:state][:dates].first, dates.first
159+
160+
votes = state.votes
161+
assert_kind_of Array, votes
162+
assert_kind_of TrueClass, votes.first
163+
assert_equal @deep[:street][:state][:votes].first, votes.first
152164
end
153165

154166
def test_nested_collections_within_the_same_namespace

0 commit comments

Comments
 (0)