Fix rack driver to support buttons with no 'type' attribute

(type defaults to 'submit' according to HTML 4/5 specs)
This commit is contained in:
bodhi 2010-10-06 13:08:36 +11:00
parent 55476db4bd
commit 500aff259e
3 changed files with 9 additions and 1 deletions

View File

@ -70,7 +70,8 @@ class Capybara::Driver::RackTest < Capybara::Driver::Base
if tag_name == 'a'
method = self["data-method"] || :get
driver.process(method, self[:href].to_s)
elsif (tag_name == 'input' or tag_name == 'button') and %w(submit image).include?(type)
elsif (tag_name == 'input' and %w(submit image).include?(type)) or
((tag_name == 'button') and type.nil? or type == "submit")
Form.new(driver, form).submit(self)
end
end

View File

@ -12,6 +12,12 @@ shared_examples_for "click_link_or_button" do
extract_results(@session)['first_name'].should == 'John'
end
it "should click on a button with no type attribute" do
@session.visit('/form')
@session.click_link_or_button('no_type')
extract_results(@session)['first_name'].should == 'John'
end
it "should be aliased as click for backward compatibility" do
Capybara.should_receive(:deprecate).with("click", "click_link_or_button")
@session.visit('/form')

View File

@ -217,6 +217,7 @@
<input type="image" name="form[okay]" id="okay556" value="okay" alt="oh hai thar"/>
<button type="submit" id="click_me_123" value="click_me">Click me!</button>
<button type="submit" name="form[no_value]">No Value!</button>
<button id="no_type">No Type!</button>
</p>
</form>