Nickolay Kolev
2006-May-10 10:28 UTC
[Rails] Ezra''s acl_system2 and flash not getting populated in functional tests
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