1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00

Fixed parameters managment when using hash with several values. Fix #11

This commit is contained in:
Julien Kirch 2010-03-02 20:21:04 +01:00
parent 965d20899e
commit 923c457501
3 changed files with 11 additions and 1 deletions

View file

@ -1,3 +1,7 @@
# 1.5.0
- fixed parameters managment when using hash with several values
# 1.4.0
- Response is no more a String, and the mixin is replaced by an abstract_response, existing calls are redirected to response body with a warning.

View file

@ -58,7 +58,7 @@ module RestClient
params.each do |key, value|
calculated_key = parent_key ? "#{parent_key}[#{escape key}]" : escape(key)
if value.is_a? Hash
result << flatten_params(value, calculated_key).flatten
result += flatten_params(value, calculated_key)
elsif value.is_a? Array
value.each do |elem|
result << [calculated_key, elem]
@ -67,6 +67,7 @@ module RestClient
result << [calculated_key, value]
end
end
p result.length
result
end

View file

@ -21,6 +21,11 @@ describe RestClient::Payload do
should == "foo[bar][baz]=qux"
end
it "should handle many attributes inside a hash" do
parameters = RestClient::Payload::UrlEncoded.new({:foo => {:bar => 'baz', :baz => 'qux'}}).to_s
parameters.should include("foo[bar]=baz", "foo[baz]=qux")
end
it "should form properly use symbols as parameters" do
RestClient::Payload::UrlEncoded.new({:foo => :bar}).to_s.
should == "foo=bar"