Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4628

Where should I put authenticated routes tests using Devise + RSpec?

$
0
0

I'm pretty new to Rails.We are using Devise to handle user authentication and RSpec for testing the application (Rails 4).

I have an Admin devise model which has access to some authenticated routes. Here's an excerpt from routes.rb:

devise_for :adminsauthenticate :admin do  get 'admin', to: 'admin#index'end

It (obviously) works flawlessly: if I visit /admin, I get redirected to /admins/sign_in and, once I sign in (or if I already am in session) I have direct access to /admin.

Now, as I understand, routes should be tested inside spec/routes/<controller_name>_routes_spec.rb. I like the idea of testing routes (and that the right controller handle each route with the right action etc.) on their own.

We're facing the issue of testing routes when the said routes are authenticated. Including

config.include Devise::TestHelpers[, type: :controller]

inside spec/spec_helper.rb still doesn't make the sign_in (or sign_[out|up]) methods available inside routes specs.

What are we supposed to do? How should we test authenticated routes?It just feels wrong to me that non authenticated routes are tested as spec/routes, while authenticated routes should be tested inside integration tests, manually filling sign-in forms with Capybara-like stuff.

(note: I read this, but it didn't help at all)


Viewing all articles
Browse latest Browse all 4628

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>