1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

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')
@ -237,6 +243,7 @@ Capybara::SpecHelper.spec '#click_button' do
end
end
context "with value given on an image button" do
it "should submit the associated form" do
@session.click_button('okay')

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>