Hi All, I''m using rails 1.0rc3 and I''m not sure what I''m doing wrong, but I hope someone can give me a little guidance. I''ve got an authorize function that is called on ''before_filter'' for controllers that I would like to secure, it works fine but the problem come when I want to do functional testing on controllers that are secured using the before_filter. Within the the Rails book they have the following function placed in the ''test_helper.rb'': def login(name=''fred'', password=''abracadabra'') post :login, :user => {:name => name, :password => password} assert_redirected_to :action => "index" assert_not_nil(session[:user_id]) user = User.find(session[:user_id]) assert_equal name, user.name, "Login name should match session name" end The difference that I have is that the login is in a different controller ( UserController), so I guess that I would change the following line. post :login, :user => {:name => name, :password => password} So I have tried the following without success. post :user, :login, :user => {:name => name, :password => password} post ''user'', ''user'', :user => {:name => name, :password => password} post ( {:controller => :user, :action => :login}, :user => {:name => name, :password => password}) post ( {:controller => ''user'', :action => ''login''}, :user => {:name => name, :password => password}) post :controller => :user, :action => :login, :user => {:name => name, :password => password} post :controller => ''user'', :action => ''login'', :user => {:name => name, :password => password} Some of these were just plain errors but none called the login function :(, So I thought well why not just put the user_id into session before I make the request, but can''t do that either :(. Any help / advice greatly received. David Stubbs
David Stubbs wrote:> Hi All, > > I''m using rails 1.0rc3 and I''m not sure what I''m doing wrong, but I hope > someone can give me a little guidance. I''ve got an authorize function > that is called on ''before_filter'' for controllers that I would like to > secure, it works fine but the problem come when I want to do functional > testing on controllers that are secured using the before_filter. > > Within the the Rails book they have the following function placed in the > ''test_helper.rb'': > > def login(name=''fred'', password=''abracadabra'') > post :login, :user => {:name => name, :password => password} > assert_redirected_to :action => "index" > assert_not_nil(session[:user_id]) > user = User.find(session[:user_id]) > assert_equal name, user.name, "Login name should match session name" > end > > The difference that I have is that the login is in a different > controller ( UserController), so I guess that I would change the > following line. > > post :login, :user => {:name => name, :password => password} > > So I have tried the following without success. > > post :user, :login, :user => {:name => name, :password => password} > post ''user'', ''user'', :user => {:name => name, :password => password} > > post ( {:controller => :user, :action => :login}, :user => {:name > => name, :password => password}) > post ( {:controller => ''user'', :action => ''login''}, :user => {:name > => name, :password => password}) > > post :controller => :user, :action => :login, :user => {:name => > name, :password => password} > post :controller => ''user'', :action => ''login'', :user => {:name => > name, :password => password} > > Some of these were just plain errors but none called the login function > :(, So I thought well why not just put the user_id into session before I > make the request, but can''t do that either :(. > > Any help / advice greatly received. > > David StubbsWe''ve talked about this stuff before: http://search.gmane.org/?query=login+test+post&group=gmane.comp.lang.ruby.rails Hope this helps -- Robert Jones