Skip to content

Commit

Permalink
Properly handle multiline param values (previously, subsequent lines …
Browse files Browse the repository at this point in the history
…were lost)
  • Loading branch information
brynary committed Sep 7, 2009
1 parent ad06a77 commit b0ef59f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/webrat/core/elements/field.rb
Expand Up @@ -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,
Expand Down Expand Up @@ -415,7 +415,7 @@ def options
end

def unset(value)
@value = []
@value = nil
end

protected
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/public/fill_in_spec.rb
Expand Up @@ -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>
<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
Expand Down

0 comments on commit b0ef59f

Please sign in to comment.