Problems with testing embedded login and user engines

I am developing an application for RAILS that includes the login and
user
engines. I am now trying to write functional tests for that
application.
Of course the first thing that happens when I get or post any action is
a
redirection to user/login. So I created a login test to proceed all of
my
others. I have created user fixtures that are based on real users that
I
have logged in successfully many times via the browser. I simply
created
YAML directly from them. I also noticed that it was necessary to config
the salt which I have done, matching the salt from my environment.rb.

I cannot get past the user/login screen. Here is the code that calls
the
login test:

require File.dirname(FILE) + ‘/…/test_helper’
require ‘of_controller’

Re-raise errors caught by the controller.

class OfController; def rescue_action(e) raise e end; end

class OfControllerTest < Test::Unit::TestCase
fixtures :permissions, :users, :roles

def setup
LoginEngine::CONFIG[:salt] = “whatever”
@controller = OfController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new

@request.host = "localhost"

end

Replace this with your real tests.

def test_takeOrder
login
get :action => ‘takeOrder’, :context => ‘11111’
assert_response :success
end
end

And here is the login code:

def login(name=‘some_user’, password=‘some_password’)
post :controller => ‘user’, :action => ‘login’, :user => {:login =>
name, :password => password}
assert_session_has :user
assert_response :redirect
assert_redirected_to :controller => ‘user’, :action => “home”
end

The assert_redirected_to always fails. I get redirected to user/login
again. It appears that the login is invalid but the salt, username, and
password are identical to my development environment where they work.
Please forgive me if I am doing something stupid – I am a bit of a
newbie
to RAILS testing. I’d appreciate any help.

Thanks!No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 268.1.1/271 - Release Date: 2/28/2006

I’m not sure that you can send requests to ‘other’ controllers in
Rails’ functional testing at the moment (I believe that the upcoming
integration testing is going to cover that).

If you want to test the user login controller, you would need to set
the @controller instance variable to be a UserController object.

In most cases like this, it is sufficient to simply place a User
object in the test session directly, rather than log in via an actual
controller. There have been quite a few posts about this to the mail
Rails list over the past month or so; a trip to Google should find
them fairly quickly.

HTH

  • james

On 3/3/06, [email protected] [email protected] wrote:

fixtures :permissions, :users, :roles

Replace this with your real tests.

post :controller => 'user', :action => 'login', :user => {:login =>

to RAILS testing. I’d appreciate any help.

  • J *
    ~

I am having the exact same issue, but could not find any information on
how to “place a User object in the test session directly”. I tried
doing the following in my test, but it still wants to redirect to the
login page:

user = User.find(2)
@request.session[‘user’] = user

Any ideas?

James A. wrote:

I’m not sure that you can send requests to ‘other’ controllers in
Rails’ functional testing at the moment (I believe that the upcoming
integration testing is going to cover that).

If you want to test the user login controller, you would need to set
the @controller instance variable to be a UserController object.

In most cases like this, it is sufficient to simply place a User
object in the test session directly, rather than log in via an actual
controller. There have been quite a few posts about this to the mail
Rails list over the past month or so; a trip to Google should find
them fairly quickly.

HTH

  • james

On 3/3/06, [email protected] [email protected] wrote:

fixtures :permissions, :users, :roles

Replace this with your real tests.

post :controller => 'user', :action => 'login', :user => {:login =>

to RAILS testing. I’d appreciate any help.

  • J *
    ~

I figured out the problem… thought I would put it on here in case
anyone else had the same issue.

fixtures :special_ownerships, :users, :roles, :users_roles

def setup
@controller = Administer::SpecialOwnershipsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new

# Login User
@request.session[:user] = User.find(1)

end

I believe that my problem was not having fixtures for :roles and
:user_roles set up correctly.

Brandon H. wrote:

I am having the exact same issue, but could not find any information on
how to “place a User object in the test session directly”. I tried
doing the following in my test, but it still wants to redirect to the
login page:

user = User.find(2)
@request.session[‘user’] = user

Any ideas?

James A. wrote:

I’m not sure that you can send requests to ‘other’ controllers in
Rails’ functional testing at the moment (I believe that the upcoming
integration testing is going to cover that).

If you want to test the user login controller, you would need to set
the @controller instance variable to be a UserController object.

In most cases like this, it is sufficient to simply place a User
object in the test session directly, rather than log in via an actual
controller. There have been quite a few posts about this to the mail
Rails list over the past month or so; a trip to Google should find
them fairly quickly.

HTH

  • james

On 3/3/06, [email protected] [email protected] wrote:

fixtures :permissions, :users, :roles

Replace this with your real tests.

post :controller => 'user', :action => 'login', :user => {:login =>

to RAILS testing. I’d appreciate any help.

  • J *
    ~