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

后端 未结 6 1755
我寻月下人不归
我寻月下人不归 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

    The easiest way to correct this problem (albeit probably not the most correct one) is to modify your routes file to match the rest of the application. E.g. make the GET version of destroy_user_session_path work. You can do this by modifying the routes file as follows

    Remove:

    devise_for :users
    

    Add:

    devise_for :users do
      get "/users/sign_out" => "devise/sessions#destroy", :as => :destroy_user_session
    end
    

    This is a bit dirty. I'm sure that Devise deprecated the GET route for good reason. However, fixing it any other way is beyond my Cucumber knowledge at this point, as every test in that suite ultimately relies on visit('/users/logout') which just isn't possible with the out-of-the-box Devise routes.

    UPDATE

    You can also fix this by commenting out the following in config/initialers/devise.rb

    #config.sign_out_via = :delete
    

提交回复
热议问题