Permalink
Browse files

Merge branch 'master' of https://github.com/mustafaturan/http_request.rb



Conflicts:
	test/test_http_request.rb
  • Loading branch information...
2 parents 6d2093a + 003057c commit b90062c3102403acf48f70b881e689d0f7c66f02 @xianhuazhou committed Aug 13, 2012
Showing with 15 additions and 2 deletions.
  1. +7 −2 lib/http_request.rb
  2. +8 −0 spec/http_request_spec.rb
View
@@ -310,8 +310,13 @@ def parse_options(method, options)
# parse parameters for the options[:parameters] and @uri.query
def parse_parameters
if @options[:parameters].is_a?(Hash)
- @options[:parameters] = @options[:parameters].collect{|k, v|
- "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
+ @options[:parameters] = @options[:parameters].collect{|k, v|
+ unless v.is_a?(Array)
+ "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
+ else
+ prefix = "#{k}[]"
+ v.collect { |value| "#{CGI.escape(prefix)}=#{CGI.escape(value.to_s)}" }.join('&')
+ end
}.join('&')
end
@options[:parameters] = '' if @options[:parameters].nil?
@@ -110,6 +110,10 @@
hr.get(:url => URL + '/get', :parameters => {'ids[a]' => 1, 'ids[b]' => 2}).body.should include('"ids"=>{')
hr.get(:url => URL + '/get', :parameters => {'ids[a]' => 1, 'ids[b]' => 2}).body.should include('"a"=>"1"')
hr.get(:url => URL + '/get', :parameters => {'ids[a]' => 1, 'ids[b]' => 2}).body.should include('"b"=>"2"')
+
+ hr.get(:url => URL + '/get', :parameters => {:ids => ['1', '2']}).body.should == {
+ 'ids' => ['1', '2']
+ }.inspect
end
it "should work with the post method" do
@@ -155,6 +159,10 @@
hr.post(:url => URL + '/get', :parameters => {'ids[a]' => 1, 'ids[b]' => 2}).body.should include('"ids"=>{')
hr.post(:url => URL + '/get', :parameters => {'ids[a]' => 1, 'ids[b]' => 2}).body.should include('"a"=>"1"')
hr.post(:url => URL + '/get', :parameters => {'ids[a]' => 1, 'ids[b]' => 2}).body.should include('"b"=>"2"')
+
+ hr.post(:url => URL + '/get', :parameters => {:ids => ['1','2']}).body.should == {
+ 'ids' => ['1', '2']
+ }.inspect
end
end

0 comments on commit b90062c

Please sign in to comment.