Take the 2-minute tour ×

When I create a new rails app with mongoid:

rails new tddapp --skip-active-record
cd tddapp
echo "gem 'mongoid'" >> Gemfile
rails g mongoid:config

And then generate a simple scaffold:

rails g scaffold building height:Integer name:String

The scaffolding is created and the minimal app runs just fine. But the scaffold-generated tests fail with:

NoMethodError: undefined method `buildings' for #<BuildingsControllerTest:0x007fa6afbf78d8>

The offending line shows that the test controller can't find the fixtures:

@building = buildings(:one)

The mongoid generator was nice enough to create fixtures in test/fixtures/buildings.yml indicating some level of cooperation with the whole idea of functional tests for the scaffold.

Is there some configuration setting or something I need to change to get the functional tests to load mongoid's fixtures? Or are the scaffolding functional tests expected to fail with mongoid? (And if so, why does mongoid bother creating fixture files?)

share|improve this question
Are you using test-unit or rspec? –  gylaz Mar 21 '13 at 2:07
Scaffold tests subclass ActiveSupport::TestCase which I believe is based on test-unit / minitest. –  Leopd Mar 21 '13 at 22:11
add comment

1 Answer

up vote 0 down vote accepted

Mongoid doesn't have support for fixtures out of the box (source). I recommend you forgo fixtures and go the routes of factories. factory_girl is an excellent option.

share|improve this answer
add comment

Your Answer


