Forum: Rails Engines Functional Tests and "user_engine" protected actions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Riko (Guest)
on 2006-05-30 16:41
(Received via mailing list)
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 |
site:  http://www.akropolix.net/rik0/      |
forum: http://www.akropolix.net/forum/     |
Enrico F. (Guest)
on 2006-05-30 20:18
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.
Enrico F. (Guest)
on 2006-06-23 11:32
(Received via mailing list)
On 5/30/06, Enrico F. <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.
This topic is locked and can not be replied to.