Permalink
Browse files

Ignore form submit clicks when no associated form

  • Loading branch information...
1 parent 085581e commit 0c22d98bbe7662b08428cb9545a27de877497dd6 @twalpole twalpole committed Apr 22, 2013
@@ -52,7 +52,8 @@ def click
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
@@ -225,6 +225,12 @@
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 @@
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
@@ -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>
+
+

0 comments on commit 0c22d98

Please sign in to comment.