Topic: Problem with functional testing and restful_authentication

Hi,

I'm using restful_authentication plugin and got problem with functional testing. In application controller I've got "before_filter :login_required". How can I simulate logged in user in my functional tests? I tried doing something like this:

@request.session[:user] = 1

but it doesn't work - all of my assert_redirected_to fail (I guess I'm being redirected to login page).

Additionally I get error on the following test case, which was generated automatically by scaffold_resource generator:

def test_should_update_project
  put :update, :id => 1, :project => { :name => "Updated project" }
  assert_redirected_to project_path(assigns(:project))
end

The error message is:
Exception: project_url failed to generate from {:controller=>"projects", :id=>nil, :action=>"show"}, expected: {:controller=>"projects", :action=>"show"}, diff: {:id=>nil}
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1273:in `raise_named_route_error'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1245:in `generate'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/url_rewriter.rb:104:in `rewrite_path'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/url_rewriter.rb:69:in `rewrite'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:522:in `url_for'
(eval):19:in `project_path'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/test_process.rb:451:in `send'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/test_process.rb:451:in `method_missing'
./test/functional/projects_controller_test.rb:48:in `test_should_update_project'
c:/ruby/lib/ruby/1.8/test/unit/testcase.rb:78:in `__send__'
c:/ruby/lib/ruby/1.8/test/unit/testcase.rb:78:in `run'
c:/ruby/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
c:/ruby/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'
c:/ruby/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'
c:/ruby/lib/ruby/1.8/test/unit/testsuite.rb:34:in `run'
c:/ruby/lib/ruby/1.8/test/unit/testsuite.rb:33:in `each'
c:/ruby/lib/ruby/1.8/test/unit/testsuite.rb:33:in `run'
c:/ruby/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:46:in `run_suite'
C:/workspace/.metadata/.plugins/org.rubypeople.rdt.testunit/RemoteTestRunner.rb:107:in `start_mediator'
C:/workspace/.metadata/.plugins/org.rubypeople.rdt.testunit/RemoteTestRunner.rb:52:in `start'
C:/workspace/.metadata/.plugins/org.rubypeople.rdt.testunit/RemoteTestRunner.rb:298

The fixtures are correct (there's user with id=1 and project with id=1 as well).

I'm very new to the whole testing stuff, so I'd really appreciate any feedback.

[EDIT] I've figured out that there's "login_as" method, so I just added "login_as :quentin" to the setup method and it works smile It also fixed the error I was having.

Last edited by g0nzo (2007-08-06 09:24:56)