Has_session_object

Hi,

No matter what I do, has_session_object always return false…
The site itself has no problem logging in users.
Can someone help please ?

in my test unit:

class AccountControllerTest < Test::Unit::TestCase

fixtures :users

def setup
@controller = AccountController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@request.host = “127.0.0.1”
end

def test_auth_bob
#check we can login
login_as :bob #post :login, :user=> { :login => “bob”, :password
=> “test” }
assert @response.has_session_object?(:user)
assert_equal @bob, session[:user]
assert_response :redirect
assert_redirected_to :controller=>‘welcome’, :action=>‘index’
end

end

my fixtures:

bob:
id: 1
name: Bob
login: bob
email: [email protected]
password: <%=Digest::SHA1.hexdigest(“laphrasedelamorttestquitue”)%>

‘test’ is inside a long sentence

My controller:

class AccountController < ApplicationController
layout ‘login’

def index
redirect_to :action => :login
end

def login
puts “Login”
case request.method
when :post
if session[‘user’] = User.authenticate(params[‘user’]
[‘login’], params[‘user’][‘password’])
puts “OK”
AppMailer.deliver_alert(“Login Alert”,"#{session[‘user’]
[‘name’]} just logged on PTM")
flash[‘notice’] = “Login successful”
redirect_back_or_default :controller => “welcome”
else
puts “Error”
@login = params[‘user_login’]
@message = “Login unsuccessful”
end
end
end

[…]

end

My model:

require ‘digest/sha1’

this model expects a certain database layout and its based on the

name/login pattern.
class User < ActiveRecord::Base
has_many :tasks
has_many :notes
has_and_belongs_to_many :projects

def self.authenticate(login, pass)
puts login # gets printed out
puts pass # gets printed out
find(:first, :conditions=>[“login=? AND password=?”, login,
sha1(pass)])
end

protected

def self.sha1(pass)
Digest::SHA1.hexdigest(“laphrasedelamort#{pass}quitue”)
end

[…]

end

OK gets printed out. (see controller)
The site works.
The unit test does not…

Thanks for any help,
Mickael.

I am still puzzled by this error.
I can not run my tests, snif :frowning:

Could someone help ? :slight_smile:

Mickael.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs