Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RackTest extension for submitting a form without a button #529

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/capybara/driver/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def click
raise NotImplementedError
end

def submit_form
raise NotImplementedError
end

def drag_to(element)
raise NotImplementedError
end
Expand All @@ -59,7 +63,7 @@ def selected?
def path
raise NotSupportedByDriverError
end

def trigger(event)
raise NotSupportedByDriverError
end
Expand Down
8 changes: 8 additions & 0 deletions lib/capybara/node/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ def click
wait_until { base.click }
end

##
#
# Submit the Element
#
def submit_form
wait_until { base.submit_form }
end

##
#
# @return [String] The tag name of the element
Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/rack_test/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def click
end
end

def submit_form
Capybara::RackTest::Form.new(driver, form).submit({})
end

def tag_name
native.node_name
end
Expand Down
9 changes: 8 additions & 1 deletion spec/driver/rack_test_driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,17 @@ def capture(*streams)
@driver.body.should include('foobar')
end

it 'should keep headers on form submit' do
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
@driver.visit('/form')
@driver.find('//input[@id="form_middle_name"]')[0].submit_form
@driver.body.should include('middle_name: Darren')
end

it 'should keep headers on redirects' do
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
@driver.visit('/get_header_via_redirect')
@driver.body.should include('foobar')
end
end
end
end