Permalink
Browse files

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

it fixes spec/integration/mechanize/sample_app.rb:20
  • Loading branch information...
1 parent c49123c commit 06bb72d24fd79a49a2922ac56058634cbcd1eb84 @zevarito zevarito committed with djanowski Apr 13, 2010
Showing with 11 additions and 5 deletions.
  1. +11 −5 lib/webrat/adapters/mechanize.rb
@@ -22,13 +22,19 @@ def get(url, data, headers_argument_not_used = nil)
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

0 comments on commit 06bb72d

Please sign in to comment.