Hi,
I’m having a problem getting past the authentication mechanism in rails
using my controller functional tests.
my functional tests look like this
def test_4
$stdout.puts 'TEST 4: cookies is ’ + cookies.to_s
:user => {:id => users(:testuser).id}
cookies[:user_id] = '2222'
$stdout.puts '1. cookies is ' + cookies.to_s
get 'login/login_uid', :id => '2222'
$stdout.puts '2. cookies is ' + cookies.to_s
assert_redirected_to :controller => "admin", :action => "home"
$stderr.puts @response.to_s
end
and i expect the login controller to redirect me to “/admin/home” after
i have successfully logged in, but i keep getting a redirect back to the
login controller, “/login”, and i cant figure out what i’m doing wrong.
my only guess is that i’m not successfully putting the user id in the
cookies. can someone take a look and give me their opinion ? it would be
really appreciated.
here is the first few lines of my admin controller
class AdminController < ApplicationController
include DbHelper
before_filter :authorize, :except => [ :index, :init ]
and here is the code for my login controller
class LoginController < ApplicationController
include DbHelper
note: no filter, all methods can be accessed
def index
# get the uid for the template
#@user_id = get_uid
render :template => 'login/login'
end
def finger_uid
$stderr.puts “in ‘fingeruid’”
# get the uid
@ppid = params[:id]
# get the uid; check with the db
begin
user = get_user_from_ppid @ppid
#user = User.find( @user_id )
@msg = "Existing user - " + user.nick_name + ""
rescue Exception
# todo: determine if the exception was thrown
# because the database is not running
@msg = "New user"
end
render :partial => "finger_uid"
$stderr.puts "out 'fingeruid'"
end
def login_uid
# get the uid
@ppid = params[:id]
# check the uid
begin
user = get_user_from_ppid @ppid
$stderr.puts 'should have thrown an exception'
rescue Exception
user = User.new;
user.id_prod_peer = @ppid;
user.save!;
user.reload;
end
if user == nil
user = User.new;
user.id_prod_peer = @ppid;
user.nick_name = ' '
user.save!;
user.reload;
end
params[:id] = user.id
# set the cookie with the id
set_uid user.id;
user.nick_name.tr! ' ',''
if user.nick_name == nil || user.nick_name.empty?
#render :action => 'user/edit', :object => user
flash[:notice] = 'Please enter a nickname'
redirect_to :controller => 'user', :action => 'edit', :id =>
user.id,
:bl => ‘admin’
else
# show the logged in page
redirect_to :controller => 'admin', :action => 'home'
end
end