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

View File

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