# Functional Tests and "user\_engine" protected actions

**URL:** <https://www.ruby-forum.com/t/functional-tests-and-user-engine-protected-actions/61978>\
**Category:** Engines\
**Created:** [May 30, 2006, 2:41pm UTC](https://www.ruby-forum.com/t/functional-tests-and-user-engine-protected-actions/61978 "2006-05-30T14:41:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![riko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/919ad9/32.png) [@riko](https://www.ruby-forum.com/u/riko)\
**Post date:** [May 30, 2006, 2:41pm UTC](https://www.ruby-forum.com/t/functional-tests-and-user-engine-protected-actions/61978/1 "2006-05-30T14:41:08Z")

</div>

I had a quick search on the archive, but actually I did not find  
anything useful to me.

My problem is that I need to do some functional tests on controllers  
that are restricted to only some kind of users (I’m using user\_engine).  
While “manually” everything works, I’d like to test it authomatically. I  
think I can do it with integration tests on rails 1.1, however for now I  
must stick to 1.0.

Is there a “standard” solution to solve my problem? I tried to edit the  
session object, but it looks read only. I have the login as user/login  
and have to test actions from other controllers. I thought I could add a  
login method to the tested controllers in the file where the tests are  
defined, but it would be sub-optimal in my opinion.

It is the only way?

–  
blog: [http://www.akropolix.net/rik0/blogs](http://www.akropolix.net/rik0/blogs) |  
site: [http://www.akropolix.net/rik0/](http://www.akropolix.net/rik0/) |  
forum: [http://www.akropolix.net/forum/](http://www.akropolix.net/forum/) |

---

<div class="post-metadata">

**Author:** ![riko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/919ad9/32.png) [@riko](https://www.ruby-forum.com/u/riko)\
**Post date:** [May 30, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/functional-tests-and-user-engine-protected-actions/61978/2 "2006-05-30T18:18:45Z")

</div>

Riko wrote:

> It is the only way?

I found the solution. I have to put an user in the session and it works.  
Actually I have to call it @request.session and not just session (the  
first one is a TestSession that supports key based insertion, while the  
latter is just an Array).

I defined a

def login(user)  
@request.session[:user] = user  
@request.session[:user].logged\_in\_at = Time.now  
end

method and then call it if I need to simulate authentication. Good.

---

<div class="post-metadata">

**Author:** ![riko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/919ad9/32.png) [@riko](https://www.ruby-forum.com/u/riko)\
**Post date:** [June 23, 2006, 9:32am UTC](https://www.ruby-forum.com/t/functional-tests-and-user-engine-protected-actions/61978/3 "2006-06-23T09:32:24Z")

</div>

On 5/30/06, Enrico F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I found the solution. I have to put an user in the session and it works.

However now that we have integration tests, this kind of testing is  
more appropriate there.  
We should just disable checking when testing, in my opinion.
