Fixtures in ActionController::TestCase

Hi guys,

Need some help.

I am using Rails 2.0 and while writing functional test, I encountered
the following problem

class UserControllerTest < ActionController::TestCase
fixtures :users

def do_something
attempt_login(users(:valid_user)) # assuming valid_user is a
proper line in

end

def attempt_login(user)
post :login, :user => { :login => user.login, :password =>
user.password }
end

Running the test:

  1. Error:
    do_something(UserControllerTest):
    NoMethodError: You have a nil object when you didn’t expect it!
    The error occurred while evaluating nil.login
    test/functional/user_controller_test.rb:41:in attempt_login' test/functional/user_controller_test.rb:32:indo_something’
    /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/
    testing/default.rb:7:in `run’
  • I tried putting fixtures :users within setup, still the same
    problem. This works if I derive Test::Unit::TestCase instead of the
    new rails 2.0 default class