Missing users method means your fixtures aren’t getting loaded

Another confusing bit in getting Restful Authentication to work in my specs… I was getting a number of errors like this:

NoMethodError in ‘AppsController handling GET /apps/new user IS logged in should assign the new app for the view’
undefined method `users’ for #
/var/forkolator/apps/forkolator/lib/authenticated_test_helper.rb:4:in `login_as’

The basic problem here is that the login_as helper, which is provided by the Restful Authentication plugin, and which resides in lib/authenticated_test_helper.rb, relies on the user fixture which is automatically installed in spec/fixtures/users.yml. The problem was, these fixtures weren’t getting loaded in my spec. To do this, all I had to do was add a fixtures line in my spec:

describe "handling GET /apps/new" do
fixtures :users
...

Annoyingly it looks like I’ll have to do this in every describe block in every spec that uses the login stuff. Maybe I can move it into the helper…

… yes, in fact there are directions for that in spec/spec_helper.rb. Just add

config.global_fixtures = :users

Leave a Reply