Reputation: 2319
I am using the Devise gem for authentication. I would like to know how to test the functionality in my Rails Tests (using Test::Unit) and what tests people normally write after applying the gem?
Devise is applied on my User Model.
Upvotes: 1
Views: 79
Reputation: 10592
Depending on what kind of authentication you have, you may wish to take different approaches. In my last app I'm using Devise with omniauth-facebook and hence I did also some high-level tests with capybara to see if app is properly handling all cases (ex. user did not grant extended permissions)
In case you have some simple login/password based authentication it should be sufficient to test if all restricted resources (controllers) are calling authenticate_user!
. Also in such scenario there's no point in testing Devise itself so you may just check if views are calling proper helpers to render login/out links.
Upvotes: 0
Reputation: 319
If you're trying to test devise or really any sort of user interaction you should probably try integration testing with rspec and capybara(or something similar). You can even test confirmation e-mails with the email_spec gem. This book: http://www.manning.com/bigg2/ Rails 4 in Action has three chapters of using/testing devise authentication/authorization, I would check it out if you want details.
Upvotes: 1