10.2 protect pages.
?
?2. we will add before_filter to user controller to make this test pass:
?4. now to make the test pass, we need to add a new before filter to user controller.response.should render_template('users/edit') endend?you may wondering, why I use?should render_template()instead of?should redirect_to()
because, in integration test, it will follow the redirect, so response.should redirect_to will not work.
6. next, we will do the implementation to make the test pass.how do we do this?a. since http is stateless, we have to use session to store the requested url in last request, then get it from session in the new request.(the things in session will expire when browser close.)b. we will use the request object to get the url.module SessionsHelper . . . def deny_access store_location redirect_to signin_path, :notice => "Please sign in to access this page." end def redirect_back_or(default) redirect_to(session[:return_to] || default) clear_return_to end private . . . def store_location session[:return_to] = request.fullpath end def clear_return_to session[:return_to] = nil endend?