From db3fe608ea7a3f1072ab0417c02d455275e59ef4 Mon Sep 17 00:00:00 2001 From: Kamal Fariz Mahyuddin Date: Tue, 4 Mar 2008 17:59:40 +0800 Subject: [PATCH] Serialize empty text field values just like browsers --- History.txt | 1 + lib/webrat/session.rb | 4 ++-- test/clicks_button_test.rb | 11 +++++++++++ test/fills_in_test.rb | 4 ++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/History.txt b/History.txt index 008db42..66f5664 100644 --- a/History.txt +++ b/History.txt @@ -1,5 +1,6 @@ == Trunk +* Serialize empty text field values just like browsers (Patch from Kamal Fariz Mahyuddi) * Added clicks_link_within(selector, link_text), allowing restricting link search to within a given css selector (Path from Luke Melia) * Change clicks_link to find the shortest matching link (Patch from Luke Melia) diff --git a/lib/webrat/session.rb b/lib/webrat/session.rb index aa2c417..b1c8da7 100644 --- a/lib/webrat/session.rb +++ b/lib/webrat/session.rb @@ -399,8 +399,8 @@ module ActionController end def add_default_params_from_inputs_for(form) # :nodoc: - ((form / "input[@type='text']") + (form / "input[@type='hidden']")).each do |input| - next if input.attributes["value"].blank? + (form / "input").each do |input| + next unless %w[text hidden].include?(input.attributes["type"]) add_form_data(input, input.attributes["value"]) end end diff --git a/test/clicks_button_test.rb b/test/clicks_button_test.rb index c3b9964..ec529ff 100644 --- a/test/clicks_button_test.rb +++ b/test/clicks_button_test.rb @@ -272,4 +272,15 @@ class ClicksButtonTest < Test::Unit::TestCase @session.expects(:post_via_redirect).with("/login", "contestant" => {"scores" => {'1' => '2', '3' => '4'}}) @session.clicks_button end + + def test_should_send_default_empty_text_field_values + @response.stubs(:body).returns(<<-EOS) +
+ + +
+ EOS + @session.expects(:get_via_redirect).with("/login", "user" => {"email" => ""}) + @session.clicks_button + end end diff --git a/test/fills_in_test.rb b/test/fills_in_test.rb index 2edd320..9074f24 100644 --- a/test/fills_in_test.rb +++ b/test/fills_in_test.rb @@ -54,7 +54,7 @@ class FillsInTest < Test::Unit::TestCase EOS - @session.expects(:post_via_redirect).with("/login", "user" => {"mail2" => "value"}) + @session.expects(:post_via_redirect).with("/login", "user" => {"mail1" => "", "mail2" => "value"}) @session.fills_in "Some", :with => "value" @session.clicks_button end @@ -70,7 +70,7 @@ class FillsInTest < Test::Unit::TestCase EOS - @session.expects(:post_via_redirect).with("/login", "user" => {"mail1" => "value"}) + @session.expects(:post_via_redirect).with("/login", "user" => {"mail1" => "value", "mail2" => ""}) @session.fills_in "Some mail", :with => "value" @session.clicks_button end