Fixed Webrat not finding <button type='submit'>

This commit is contained in:
Gwyn Morfey 2008-04-16 15:35:10 +01:00
parent cdafd2ec0f
commit 44745f6891
4 changed files with 21 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.DS_Store
pkg
doc
ri

View File

@ -3,7 +3,7 @@ module Webrat
def self.class_for_element(element)
if element.name == "input"
if %w[submit image].include?(element["type"])
if %w[submit image button].include?(element["type"])
field_class = "button"
else
field_class = element["type"] || "text" #default type; 'type' attribute is not mandatory
@ -11,7 +11,6 @@ module Webrat
else
field_class = element.name
end
Webrat.const_get("#{field_class.capitalize}Field")
#rescue NameError
# raise "Invalid field element: #{element.inspect}"

View File

@ -45,7 +45,7 @@ module Webrat
@fields = []
(@element / "input, textarea, select").each do |field_element|
(@element / "input, textarea, select, button").each do |field_element|
@fields << Field.class_for_element(field_element).new(self, field_element)
end

View File

@ -77,6 +77,23 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button
end
#<button type='submit'> is also valid HTML.
def test_should_work_with_button_submit
@response.stubs(:body).returns(<<-EOS)
<form action="/form1" method="post"><p><label for="login">Login</label><br/>
<input type="text" class="text" name="login"/></p>
<p><label for="password">Password</label><br/>
<input type="password" class="password" name="password"/></p>
<p><button type="submit">Log in</button></p>
</form>
EOS
@session.expects(:post_via_redirect)
@session.clicks_button
end
def test_should_not_explode_on_file_fields
@response.stubs(:body).returns(<<-EOS)
<form method="get" action="/form1">