From b0ef59f5ece797592730f393c4b2d7bdc0694e1f Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 7 Sep 2009 14:04:32 -0400 Subject: [PATCH] Properly handle multiline param values (previously, subsequent lines were lost) --- lib/webrat/core/elements/field.rb | 12 ++++++++---- spec/public/fill_in_spec.rb | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/webrat/core/elements/field.rb b/lib/webrat/core/elements/field.rb index 53a72d05..4d74f6e8 100644 --- a/lib/webrat/core/elements/field.rb +++ b/lib/webrat/core/elements/field.rb @@ -139,7 +139,7 @@ def name end def escaped_value - CGI.escape([*@value].first.to_s) + CGI.escape(@value.to_s) end # Because we have to escape it before sending it to the above case statement, @@ -415,7 +415,7 @@ def options end def unset(value) - @value = [] + @value = nil end protected @@ -427,17 +427,21 @@ def default_value selected_options.map do |option| return "" if option.nil? option["value"] || option.inner_html - end.uniq + end.uniq.first end end - class MultipleSelectField < SelectField #:nodoc: + class MultipleSelectField < Field #:nodoc: def self.xpath_search [".//select[@multiple='multiple']"] end + def options + @options ||= SelectOption.load_all(@session, @element) + end + def set(value) @value << value end diff --git a/spec/public/fill_in_spec.rb b/spec/public/fill_in_spec.rb index f6b8f1e0..8e9cb7be 100644 --- a/spec/public/fill_in_spec.rb +++ b/spec/public/fill_in_spec.rb @@ -15,6 +15,21 @@ fill_in "User Text", :with => "filling text area" click_button end + + it "should support multiline values" do + with_html <<-HTML + +
+ + + +
+ + HTML + webrat_session.should_receive(:post).with("/login", "user" => {"text" => "One\nTwo"}) + fill_in "User Text", :with => "One\nTwo" + click_button + end it "should work with password fields" do with_html <<-HTML