I am still puzzled by this error.
I can not run my tests, snif :(
Could someone help ? :)
Mickael.
On Aug 12, 4:11 pm, MickTaiwan
<faiv...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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: b...-vRmjhqX1jfVBDgjK7y7TUQ@public.gmane.org
> 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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---