Fix bug with empty select list

This commit is contained in:
Joe Van Dyk 2008-04-13 16:02:35 -07:00
parent 275611a0a3
commit f9ff509f02
2 changed files with 12 additions and 0 deletions

View File

@ -237,6 +237,7 @@ module Webrat
selected_options = @element / "option[@selected='selected']" selected_options = @element / "option[@selected='selected']"
selected_options = @element / "option:first" if selected_options.empty? selected_options = @element / "option:first" if selected_options.empty?
selected_options.map do |option| selected_options.map do |option|
return "" if option.nil?
option["value"] || option.innerHTML option["value"] || option.innerHTML
end end
end end

View File

@ -57,6 +57,17 @@ class SelectsTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end end
def test_should_work_with_empty_select_lists
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
<select name="month"></select>
<input type="submit" />
</form>
EOS
@session.expects(:post_via_redirect).with("/login", 'month' => '')
@session.clicks_button
end
def test_should_work_without_specifying_the_field_name_or_label def test_should_work_without_specifying_the_field_name_or_label
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login"> <form method="post" action="/login">