Topic: redirection failing in functional testing

In Login controller:

def login_check

    if session['user']=User.find(:first,:conditions =>["username=? and             
       password=?",params[:username],params[:password]])
        if session['user'].role_id==2
        redirect_to :controller=>"users",:action=>"list"
        elsif session['user'].role_id==1

        redirect_to :controller=>"users",:action=>"list"

        end
     else
          flash[:notice]="Login Unsuccessful"
          redirect_to :action=>"login"
         end
  end


In login controller_test

def test_login
     post :login_check,:user=>{:username=>"admin",:password=>"admin"}
    assert_response :redirected
    assert_redirected_to :controller=>"users",:action=>"list"
  end

i gave the correct username and password.
I got the error like :

Test::Unit::AssertionFailedError: Expected response to be a <:redirected>, but was <302>
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/assertions/response_assertions.rb:26:in `assert_response'C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/assertions/response_assertions.rb:18:in `assert_response'D:\Project\employeproj/test/functional/login_controller_test.rb:31:in `test_login'

Re: redirection failing in functional testing

Hi lucky,

I feel your pain.

First of all, it seems that you have a typo.  Try switching this in your test:

assert_response :redirected

with this:

assert_response :redirect

Let us know if it works,

c.