Hallo -- I have a function in test_helper.rb that looks not a little like this: def login(username="gowondapiddlehead",unhashed_password="gowonda_piddlehead") post(:login,:system_user=>{:username=>username,:unhashed_password=>unhashed_password}) assert_redirected_to(:controller=>''home'') assert_not_nil(session[:system_user_id]) system_user=SystemUser.find(session[:system_user_id]) assert_equal(username,system_user.username,"Login name should match session name.") end When I run the test, however, I get the following error: 1) Error: test_index(HomeControllerTest): NoMethodError: undefined method `login'' for Test::Unit::TestCase:Class test/functional/home_controller_test.rb:18:in `test_index'' I guess this is because I need to specify the controller being called as well as the action in the post() function. Does anyone know how to do this? Cheers, doug. -- Posted via http://www.ruby-forum.com/.
doug wrote:> Hallo -- I have a function in test_helper.rb that looks not a little > like this: > > def > login(username="gowondapiddlehead",unhashed_password="gowonda_piddlehead") > post(:login,:system_user=>{:username=>username,:unhashed_password=>unhashed_password}) > assert_redirected_to(:controller=>''home'') > assert_not_nil(session[:system_user_id]) > system_user=SystemUser.find(session[:system_user_id]) > assert_equal(username,system_user.username,"Login name should match > session name.") > end > > When I run the test, however, I get the following error: > > 1) Error: > test_index(HomeControllerTest): > NoMethodError: undefined method `login'' for Test::Unit::TestCase:Class > test/functional/home_controller_test.rb:18:in `test_index'' > > I guess this is because I need to specify the controller being called as > well as the action in the post() function. > Does anyone know how to do this? > Cheers, > doug.Doug, I''m having the exact same problem. I have an account controller that handles the login cycle. In testing another controller that depends on this cycle I cannot specify the controller, only the action. The option to specify another controller should be added. Does anyone know a work-around? Zack -- Posted via http://www.ruby-forum.com/.
Tom Mornini
2005-Dec-19 07:58 UTC
Re: Re: functional testing -- using post() w/ a different contro
On Dec 19, 2005, at 2:22 AM, Zack wrote:> I''m having the exact same problem. I have an account controller > that > handles the login cycle. In testing another controller that depends on > this cycle I cannot specify the controller, only the action. > The option to specify another controller should be added. > Does anyone know a work-around?The functional test operators take a session argument, where you can set the session up. Just test the pages by setting the session that indicates a login... get :show, # <- method { }, # <- params { :user_id => 4 } # <- session -- -- Tom Mornini