diff --git a/history.md b/history.md index 2055a5e..4077007 100644 --- a/history.md +++ b/history.md @@ -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. diff --git a/lib/restclient/payload.rb b/lib/restclient/payload.rb index 3b2ee57..43b779a 100644 --- a/lib/restclient/payload.rb +++ b/lib/restclient/payload.rb @@ -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 diff --git a/spec/payload_spec.rb b/spec/payload_spec.rb index 20552ce..85abaf6 100644 --- a/spec/payload_spec.rb +++ b/spec/payload_spec.rb @@ -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"