I am new to Rails. We use Devise for user authentication and RSpec for testing the application (Rails 4).
I have a model Adminthat has access to some authenticated routes. Here is an excerpt from routes.rb:
devise_for :admins
authenticate :admin do
get 'admin', to: 'admin#index'
end
It (obviously) works flawlessly: if I visit /admin, I get redirected to /admins/sign_in, and as soon as I log in (or if I'm already in a session), I have direct access to /admin.
Now, as I understand it, routes should be tested internally spec/routes/<controller_name>_routes_spec.rb. I like the idea of testing routes (and that the right controller handles each route with the right action, etc.) independently.
We encounter the problem of testing routes when the indicated routes authenticated. Including
config.include Devise::TestHelpers[, type: :controller]
internally spec/spec_helper.rbstill does not allow the use of methods sign_in(or sign_[out|up]) inside route specifications.
What should we do? How should we test authenticated routes? It just seems wrong to me that non-authenticated routes are checked how spec/routes, while authenticated routes should be tested inside integration tests, manually filling out login forms with things similar to Capybara.
( note : I read this one , but that didn't help)
source
share