Forum: Ruby on Rails Ezra's acl_system2 and flash not getting populated in functi

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
1f8a2831a8b45f62eee765c96c67747a?d=identicon&s=25 Nickolay Kolev (nmk)
on 2006-05-10 12:28
(Received via mailing list)
Hi all,

I am using the LoginGenerator and Ezra's acl_system2 to protect
certain actions in my controllers. I have written some functional
tests to check for correct handling of redirects, flashes, etc. The
flashes however only get populated on the first get action in any
given test. Here is what I have so far:

In the controller:

class PageController < AC
   before_filter => :login_required
   access_control :DEFAULT => 'admin'

   def index

   def permission_denied
     flash[:message] = "You must log in as an administrator."
     redirect_to :controller => "account", :action => "login

In the test:

ACTIONS = [:index, :new, :edit, :create, :update, :destroy]

def test_redirect_not_authenticated_user
   ACTIONS.each do |a|
     get a
     assert_redirected_to :controller => 'account', :action => 'login'

def test_redirect_not_admin
   assert not_admin = User.authenticate("not_admin", "her_password")
   ACTIONS.each do |a|
     get a, {}, { :user => route_admin }, nil
     assert_redirected_to :controller => "account", :action => "login"
     #assert flash.has_key?(:message), "No flash after action #{a}"
     #assert_equal "You must log in as an administrator.", flash

The flash assertions work only for the first action. In the example
above the assert flash.has_key?(:message) test fails on the second
action :new. If I delete the :index element from ACTIONS, the test
fails on :edit and so on.

Why does the flash get populated only on the first get action?

Many thanks for any pointers,
This topic is locked and can not be replied to.