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 pkg
doc doc
ri ri

View File

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

View File

@ -45,7 +45,7 @@ module Webrat
@fields = [] @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) @fields << Field.class_for_element(field_element).new(self, field_element)
end end

View File

@ -77,6 +77,23 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button @session.clicks_button
end 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 def test_should_not_explode_on_file_fields
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)
<form method="get" action="/form1"> <form method="get" action="/form1">