Skip to content

Commit

Permalink
Merge pull request teamcapybara#1064 from twalpole/no_form
Browse files Browse the repository at this point in the history
Ignore form submit clicks when no associated form
  • Loading branch information
twalpole committed Apr 22, 2013
2 parents 085581e + 0c22d98 commit 52e0caf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/capybara/rack_test/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions lib/capybara/spec/session/click_button_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/spec/views/form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -402,3 +404,5 @@
<input type="submit" name="form[no_action]" value="No Action" />
</p>
</form>


0 comments on commit 52e0caf

Please sign in to comment.