Ignore form submit clicks when no associated form

This commit is contained in:
Thomas Walpole 2013-04-22 09:12:35 -07:00
parent 085581e28e
commit 0c22d98bbe
3 changed files with 13 additions and 1 deletions

View File

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

View File

@ -225,6 +225,12 @@ Capybara::SpecHelper.spec '#click_button' do
end
end
context "with submit button not associated with any form" do
it "should not error when clicked" do
lambda { @session.click_button('no_form_button') }.should_not raise_error
end
end
context "with alt given on an image button" do
it "should submit the associated form" do
@session.click_button('oh hai thar')
@ -236,6 +242,7 @@ Capybara::SpecHelper.spec '#click_button' do
extract_results(@session)['first_name'].should == 'John'
end
end
context "with value given on an image button" do
it "should submit the associated form" do

View File

@ -283,6 +283,8 @@
<button type="submit" name="form[other_form_button]" value="other_form_button" form="form1">Form1</button>
</form>
<button type="submit" name="form[no_form_button]" value="no_form_button">No Form</button>
<textarea name="form[outside_textarea]" form="form1">Some text here</textarea>
<select name="form[outside_select]" form="form1">
<option>Lisp</option>
@ -402,3 +404,5 @@
<input type="submit" name="form[no_action]" value="No Action" />
</p>
</form>