Properly handle multiline param values (previously, subsequent lines were lost)

This commit is contained in:
Bryan Helmkamp 2009-09-07 14:04:32 -04:00
parent ad06a777fb
commit b0ef59f5ec
2 changed files with 23 additions and 4 deletions

View File

@ -139,7 +139,7 @@ module Webrat
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 @@ module Webrat
end
def unset(value)
@value = []
@value = nil
end
protected
@ -427,17 +427,21 @@ module Webrat
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

View File

@ -16,6 +16,21 @@ describe "fill_in" do
click_button
end
it "should support multiline values" do
with_html <<-HTML
<html>
<form method="post" action="/login">
<label for="user_text">User Text</label>
<textarea id="user_text" name="user[text]"></textarea>
<input type="submit" />
</form>
</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
<html>