#380 new

Fix for query string building when using Mechanize adapter

Reported by johnbintz | June 2nd, 2010 @ 09:23 AM

Webrat is incorrectly passing in an Array of Hashes to Mechanize for query string building, causing incorrect query strings to be constructed by Mechanize. This patch fixes the issue by correctly constructing a Hash for Mechanize rather than an Array of Hashes:

diff --git a/lib/webrat/core/elements/form.rb b/lib/webrat/core/elements/form.rb
index 5ab345c..77d9699 100644
--- a/lib/webrat/core/elements/form.rb
+++ b/lib/webrat/core/elements/form.rb
@@ -110,7 +110,7 @@ module Webrat
       when :rack, :sinatra
-        query_string.split('&').map {|query| { query.split('=').first => query.split('=').last }}
+        Hash[query_string.split('&').map {|query| [ query.split('=').first, query.split('=').last ]}]
diff --git a/spec/private/core/form_spec.rb b/spec/private/core/form_spec.rb
index aa28fa1..6c91eed 100644
--- a/spec/private/core/form_spec.rb
+++ b/spec/private/core/form_spec.rb
@@ -48,4 +48,22 @@ describe "Multiple nested params" do
     webrat_session.should_receive(:post).with("/family", params)
+  it "should correctly construct a query string" do
+    Webrat.configuration.mode = :mechanize
+    with_html <<-HTML
+      <html>
+        <form method="get" action="/search">
+          <input type="text" name="query" value="my-query" />
+          <input type="submit" />
+        </form>
+      </html>
+    HTML
+    params = { "query" => "my-query" }
+    webrat_session.should_receive(:get).with("/search", params)
+    click_button
+  end

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

People watching this ticket