# Session\[:return\_to\] breaks in functional test

**URL:** <https://www.ruby-forum.com/t/session-return-to-breaks-in-functional-test/114895>\
**Category:** Rails\
**Created:** [September 18, 2007, 5:03pm UTC](https://www.ruby-forum.com/t/session-return-to-breaks-in-functional-test/114895 "2007-09-18T17:03:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [September 18, 2007, 5:03pm UTC](https://www.ruby-forum.com/t/session-return-to-breaks-in-functional-test/114895/1 "2007-09-18T17:03:47Z")

</div>

I’ve made use of much this code for user authentication:  
[http://www.aidanf.net/rails\_user\_authentication\_tutorial](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?
