Skip to content

Commit

Permalink
Merge pull request #687 from khustochka/textarea-newline
Browse files Browse the repository at this point in the history
Rack-test driver should ignore the first leading newline in textarea (fixes #677)
  • Loading branch information
jnicklas committed Apr 9, 2012
2 parents 1656b5c + a0e0644 commit 755a724
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/capybara/node/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def path
#
def value
if tag_name == 'textarea'
native.content
native.content.sub(/\A\n/, '')
elsif tag_name == 'select'
if native['multiple'] == 'multiple'
native.xpath(".//option[@selected='selected']").map { |option| option[:value] || option.content }
Expand Down
6 changes: 5 additions & 1 deletion lib/capybara/spec/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@
end

it "should allow retrieval of the value" do
@driver.find('//textarea').first.value.should == 'banana'
@driver.find('//textarea[@id="normal"]').first.value.should == 'banana'
end

it "should not swallow extra newlines in textarea" do
@driver.find('//textarea[@id="additional_newline"]').first.value.should == "\nbanana"
end

it "should allow assignment of field value" do
Expand Down
6 changes: 5 additions & 1 deletion lib/capybara/spec/views/with_html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@

<p>
<input type="text" id="test_field" value="monkey"/>
<textarea>banana</textarea>
<textarea id="normal">
banana</textarea>
<textarea id="additional_newline">

banana</textarea>
<a href="/redirect_back">BackToMyself</a>
<a title="twas a fine link" href="/redirect">A link came first</a>
<a title="a fine link" href="/with_simple_html">A link</a>
Expand Down

0 comments on commit 755a724

Please sign in to comment.