Skip to content
Browse files

recursive mashing

  • Loading branch information...
1 parent 7cad490 commit 825fc6f3e8e3b19384b2667342f4d556ad152ed2 @7even 7even committed Jun 24, 2012
Showing with 8 additions and 1 deletion.
  1. +1 −1 lib/faraday_middleware/response/mashify.rb
  2. +7 −0 spec/mashify_spec.rb
View
2 lib/faraday_middleware/response/mashify.rb
@@ -25,7 +25,7 @@ def parse(body)
when Hash
mash_class.new(body)
when Array
- body.map { |item| item.is_a?(Hash) ? mash_class.new(item) : item }
+ body.map { |item| parse(item) }
else
body
end
View
7 spec/mashify_spec.rb
@@ -39,6 +39,13 @@
us.last.username.should == 'pengwynn'
end
+ it 'should handle nested arrays of hashes' do
+ env = { :body => [[{ "username" => "sferik" }, { "username" => "pengwynn" }]] }
+ us = mashify.on_complete(env)
+ us.first.first.username.should == 'sferik'
+ us.first.last.username.should == 'pengwynn'
+ end
+
it 'should handle mixed arrays' do
env = { :body => [123, { "username" => "sferik" }, 456] }
values = mashify.on_complete(env)

0 comments on commit 825fc6f

Please sign in to comment.
Something went wrong with that request. Please try again.