fix post method in mechanize adapter to handle data as array or hash

it fixes spec/integration/mechanize/sample_app.rb:20
This commit is contained in:
Álvaro Gil 2010-04-13 14:29:49 -03:00 committed by Damian Janowski
parent c49123c772
commit 06bb72d24f
1 changed files with 11 additions and 5 deletions

View File

@ -22,13 +22,19 @@ module Webrat #:nodoc:
def post(url, data, headers_argument_not_used = nil)
post_data = data.inject({}) do |memo, param|
case param.last
case param
when Hash
param.last.each {|attribute, value| memo["#{param.first}[#{attribute}]"] = value }
else
memo[param.first] = param.last
param.each {|attribute, value| memo[attribute] = value }
memo
when Array
case param.last
when Hash
param.last.each {|attribute, value| memo["#{param.first}[#{attribute}]"] = value }
else
memo[param.first] = param.last
end
memo
end
memo
end
@response = mechanize.post(url, post_data)
end