Permalink
Browse files

Handle arrays of strings

  • Loading branch information...
1 parent 3c9e7d8 commit 4e68e36c53fb99ced0d0ae323a8a215e70ea2644 @pengwynn pengwynn committed Nov 1, 2012
Showing with 11 additions and 2 deletions.
  1. +1 −2 lib/sawyer/response.rb
  2. +10 −0 test/response_test.rb
View
3 lib/sawyer/response.rb
@@ -29,8 +29,7 @@ def process_data(data)
when Hash then Resource.new(agent, data)
when Array then data.map { |hash| process_data(hash) }
when nil then nil
- else
- raise ArgumentError, "Unable to process #{data.inspect}. Want a Hash or Array"
+ else data
end
end
View
10 test/response_test.rb
@@ -16,6 +16,11 @@ def setup
}
)]
end
+
+ stub.get '/emails' do
+ emails = %w(rick@example.com technoweenie@example.com)
+ [200, {'Content-Type' => 'application/json'}, Sawyer::Agent.encode(emails)]
+ end
end
end
@@ -55,6 +60,11 @@ def test_makes_request_from_relation
assert_equal 201, res.status
assert_nil res.data
end
+
+ def test_handles_arrays_of_strings
+ res = @agent.call(:get, '/emails')
+ assert_equal 'rick@example.com', res.data.first
+ end
end
end

0 comments on commit 4e68e36

Please sign in to comment.