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 end
def escaped_value def escaped_value
CGI.escape([*@value].first.to_s) CGI.escape(@value.to_s)
end end
# Because we have to escape it before sending it to the above case statement, # Because we have to escape it before sending it to the above case statement,
@ -415,7 +415,7 @@ module Webrat
end end
def unset(value) def unset(value)
@value = [] @value = nil
end end
protected protected
@ -427,17 +427,21 @@ module Webrat
selected_options.map do |option| selected_options.map do |option|
return "" if option.nil? return "" if option.nil?
option["value"] || option.inner_html option["value"] || option.inner_html
end.uniq end.uniq.first
end end
end end
class MultipleSelectField < SelectField #:nodoc: class MultipleSelectField < Field #:nodoc:
def self.xpath_search def self.xpath_search
[".//select[@multiple='multiple']"] [".//select[@multiple='multiple']"]
end end
def options
@options ||= SelectOption.load_all(@session, @element)
end
def set(value) def set(value)
@value << value @value << value
end end

View File

@ -16,6 +16,21 @@ describe "fill_in" do
click_button click_button
end 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 it "should work with password fields" do
with_html <<-HTML with_html <<-HTML
<html> <html>