Rails 3.0.9 + Devise + Cucumber + Capybara the infamous “No route matches /users/sign_out”

后端 未结 6 1752
我寻月下人不归
我寻月下人不归 2021-02-02 09:27

I am using devise 1.4.2 with rails 3.0.9, cucumber-rails 1.0.2, capybara 1.0.0. I got No route matches \"/users/sign_out\" error when I clicked logout. I added

6条回答
  •  抹茶落季
    2021-02-02 10:06

    Devise 1.4.1 (27 June 2011) changed the default behavior for sign out requests:

    https://github.com/plataformatec/devise/commit/adb127bb3e3b334cba903db2c21710e8c41c2b40

    Jose Valim explained why: "GET requests should not change the state of the server. When sign out is a GET request, CSRF can be used to sign you out automatically and things that preload links can eventually sign you out by mistake as well."

    Cucumber wants to test GET requests not DELETE requests for destroy_user_session_path. If you intend to use Cucumber with Devise, change the Devise default from DELETE to GET for the Rails test environment only with this change to config/initializers/devise.rb:

    config.sign_out_via = Rails.env.test? ? :get : :delete

    Don't try to tweak the routes.rb file to make the fix. It isn't necessary. If you're not going to use Cucumber, leave Devise's new default (DELETE) in place.

    The example source code here:

    https://github.com/RailsApps/rails3-devise-rspec-cucumber

    now includes the change to the Devise initializer for Cucumber.

    The application template here:

    https://github.com/RailsApps/rails3-application-templates

    now detects the collision between Devise and Cucumber and alters the Devise initializer as needed.

    These changes were tested with with Rails 3.1.0.rc4 but the behavior should be the same with Rails 3.0.9. Please add comments here if the issue is unresolved or if you have more information.

提交回复
热议问题