Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing redirect after login with Devise

I've followed the recommendation from the Devise github pages for this:

http://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in

Now this works great, but how would you test that you have this behavior now?

like image 252
stuartc Avatar asked Oct 27 '10 19:10

stuartc


2 Answers

Well there are two ways of testing it one in the unit level by writing tests in the controllers that inherit the application controller. The code will look something like

it "should redirect to page_x after logged in" do
  sign_in :user_role, @user 
  set_devise_mapping(:user_role) 
  get :new 
  response.should redirect_to(user_roles_dashboard_path) 
end

For cucumber you should probably write a step to do the login and assert if u are on the expected after sign_in page.

like image 151
Kunday Avatar answered Oct 21 '22 14:10

Kunday


Hm... I think you should write own integration tests to check the behavior. No need of unit tests or functional tests if you did not mess with the Devise code.

like image 34
Lachezar Avatar answered Oct 21 '22 15:10

Lachezar