# RESTFUL Authentification plugin Functional tests - howto?

**URL:** <https://www.ruby-forum.com/t/restful-authentification-plugin-functional-tests-howto/142932>\
**Category:** Rails\
**Created:** [July 13, 2008, 6:34pm UTC](https://www.ruby-forum.com/t/restful-authentification-plugin-functional-tests-howto/142932 "2008-07-13T18:34:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [July 13, 2008, 6:34pm UTC](https://www.ruby-forum.com/t/restful-authentification-plugin-functional-tests-howto/142932/1 "2008-07-13T18:34:25Z")

</div>

I am trying to write a functional test of my UserController index  
action

require File.dirname( **FILE** ) + ‘/…/test\_helper’  
require ‘users\_controller’

class UsersControllerTest \< Test::Unit::TestCase  
def setup  
@controller = UsersController.new  
@request = ActionController::TestRequest.new  
@response = ActionController::TestResponse.new  
end

def test\_should\_get\_index  
login\_as (:superadmin)  
get :index  
assert\_response :success  
assert\_not\_nil assigns(:users)  
assert\_equal 15, assigns(:users).total\_entries

```
login_as (:quentin)
get :index
assert_response :success
assert_not_nil assigns(:users)
assert_equal 6, assigns(:users).total_entries

```

end  
end

I am using the Restful Authentification plugin, without any problem  
running my index action

class UsersController \< ApplicationController  
before\_filter :login\_required  
def index  
@roles = …  
@users = User.display\_users(current\_user, @roles, params[:page])  
…  
end  
…  
end

on the first login\_as (:superadmin), it’s OK, current\_user is 1, but  
when doing the login\_as (:quentin), the current\_user is NOT modified,  
still being 1

I wrote in the login\_as in :  
module AuthenticatedTestHelper

# Sets the current user in the session from the user fixtures.

def login\_as(user)  
@request.session[:user\_id] = user ? users(user).id : nil  
end  
…  
end

the @request.session[:user\_id] is correctlt modified (user\_id 1, then  
user\_id 2) but current\_user in my index action is not… where  
could be the problem located ??

thanks a lot to any info !

erwin
