I’ve made use of much this code for user authentication:
http://www.aidanf.net/rails_user_authentication_tutorial
Most of what the user needs to do is controlled by a
‘repository_controller’, but when they try to log in it will be dealt
with by the ‘user_controller’. The test below should represent
re-directing them to login, then back to the page originally requested:
def test_return_to
get :controller => ‘repository’, :action => ‘view_downloads’
assert flash[:notice]
assert_response :redirect
assert_redirected_to :action=>‘login’
assert @response.has_session_object?(:return_to)
post :login, { :username => “bob”, :password => “test”}
assert_response :redirect
assert_redirected_to :controller => ‘repository’, :action =>
‘view_downloads’
assert @response.has_session_object?(:user)
end
However, the test fails with:
response is not a redirection to all of the options supplied
(redirection is <{“action”=>“actionview_downloadscontrollerrepository”,
“controller”=>“user”}>), difference: <{“action”=>“view_downloads”,
“controller”=>“repository”}>
When redirected to ‘login’, sesson[:return_to] should be set to
request.request_uri. It seems that ‘get’ does not do this. Is there a
way around that problem?