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

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.
Nickolay K. (Guest)
on 2006-05-10 14: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
   end

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

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'
   end
end

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
[:message]
   end
end

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,
Nickolay
This topic is locked and can not be replied to.