Skip to content

Commit

Permalink
Fixed Webrat not finding <button type='submit'>
Browse files Browse the repository at this point in the history
  • Loading branch information
Gwyn Morfey committed Apr 16, 2008
1 parent cdafd2e commit 44745f6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,4 +1,5 @@
.DS_Store
pkg
doc
ri
email.txt
email.txt
3 changes: 1 addition & 2 deletions lib/webrat/field.rb
Expand Up @@ -3,15 +3,14 @@ class Field

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
end
else
field_class = element.name
end

Webrat.const_get("#{field_class.capitalize}Field")
#rescue NameError
# raise "Invalid field element: #{element.inspect}"
Expand Down
2 changes: 1 addition & 1 deletion lib/webrat/form.rb
Expand Up @@ -45,7 +45,7 @@ def 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)
end

Expand Down
17 changes: 17 additions & 0 deletions test/clicks_button_test.rb
Expand Up @@ -77,6 +77,23 @@ def test_should_submit_the_first_form_by_default
@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">
Expand Down

0 comments on commit 44745f6

Please sign in to comment.