Added option for rack-test driver to disable data method hack closes #184

This commit is contained in:
Jonas Nicklas and Kim Burgestrand 2011-08-30 11:20:29 +02:00
parent e9b8a45f84
commit 0188693ced
5 changed files with 30 additions and 6 deletions

View File

@ -1,12 +1,19 @@
class Capybara::RackTest::Browser
include ::Rack::Test::Methods
attr_reader :app, :options
attr_reader :driver
attr_accessor :current_host
def initialize(app, options={})
@app = app
@options = options
def initialize(driver)
@driver = driver
end
def app
driver.app
end
def options
driver.options
end
def visit(path, attributes = {})

View File

@ -14,7 +14,7 @@ class Capybara::RackTest::Driver < Capybara::Driver::Base
end
def browser
@browser ||= Capybara::RackTest::Browser.new(app, options)
@browser ||= Capybara::RackTest::Browser.new(self)
end
def response

View File

@ -51,7 +51,8 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
def click
if tag_name == 'a'
method = self["data-method"] || :get
method = self["data-method"] if driver.options[:respect_data_method]
method ||= :get
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")

View File

@ -63,6 +63,10 @@ class TestApp < Sinatra::Base
"The requested object was deleted"
end
get "/delete" do
"Not deleted"
end
get '/redirect_back' do
redirect back
end

View File

@ -20,10 +20,22 @@ describe Capybara::Session do
describe '#click_link' do
it "should use data-method if available" do
@session.driver.options[:respect_data_method] = true
@session.visit "/with_html"
@session.click_link "A link with data-method"
@session.body.should include('The requested object was deleted')
end
it "should not use data-method if option is false" do
@session.driver.options[:respect_data_method] = false
@session.visit "/with_html"
@session.click_link "A link with data-method"
@session.body.should include('Not deleted')
end
after do
@session.driver.options[:respect_data_method] = true
end
end
describe "#attach_file" do