Hey Vinnie.
Actually, I think the test might be flawed in how it expects the redirect to work or perhaps it is acting differently on a Windows dev machine as opposed to the OSX machine the text was written on.
This particular test is to test whether the login + redirect will redirect the browser to the '/story/new' page. In live browser testing this does work as expected. It's only in functional testing that it doesn't. There are a few other threads in the Ruby forum that indicate others are having the exact same trouble and from the looks of things they are also using InstantRails on Windows with :
Ruby version 1.8.4 (i386-mswin32)
RubyGems version 0.8.11
Rails version 1.2.2
Active Record version 1.15.2
The login code is the following:
Code:
class AccountController < ApplicationController
def login
if request.post?
@current_user = User.find_by_login_and_password(params[:login], params[:password])
unless @current_user.nil?
session[:user_id] = @current_user.id
unless session[:return_to].blank?
redirect_to session[:return_to]
session[:return_to] = nil
else
redirect_to :controller => 'story'
end
end
end
end
def logout
session[:user_id] = @current_user = nil
end
end
The test in the text goes like this:
Code:
def test_should_redirect_after_login_with_return_url
post :login, { :login => 'patrick', :password => 'sekrit' },
:return_to => '/story/new'
assert_redirected_to '/story/new'
end
To be more explicit the last line could be:
assert_redirected_to :controller => 'story', :action => 'new'
The problem seems to be that
:return_to => '/story/new' does not do anything in the test harness. I can pull that statement right out of the test and it makes absolutely no difference. Once the login has completed the code is directed to 'story'. That's all.
In order to return the code somewhere useful, I found one of the other threads about this problem mentioned using:
'return_to' => '/story/new'
This works! I was able to test with:
assert_redirected_to :controller => 'story', :action => 'new'
and:
assert_redirected_to '/story/new'
I'm still baffled about it because I thought
:return_to and
'return_to' would do the same thing. Maybe it's a problem specific to the Windows version or this particular rails configuration.
I still have to figure out the other problem and that is the protected methods for
post_with_user and
get_with_user
Bookmarks