Hello, even after several months of Rails development I'm still facing few problems with unit testing. 1) Inserting records during migration My migration.rb is def self.up create_table :rubriques do |t| t.column "libelle", :string t.column "rubrique_id", :integer t.column "visible", :boolean end Rubrique.create(:libelle => 'root', :rubrique_id => nil, :visible => true) end Problem is : the 'root' record is never inserted in the test database even when using rake db:migrate RAILS_ENV="test" or rake test:purge and then rake test:units Why ? No idea 2) Second common problem : I use fixtures which are loaded accordingly during unit testing. But when running functional tests which don't use any :fixtures statement, it's common to have the fixtures datas still loaded in the test database. The only solution I found was adding delete_existing_fixtures() in the setup() method... No the 'right' way in my point of view... Any help appreciated, thank you !
on 2007-04-16 14:34
on 2007-04-16 14:49
rake test:units / test:functionals blasts the test database away and rebuilds the schema from the development database (aka, no data). This does *not* use migrations; it uses db/schema.rb. If you want data in the test db, you need to either use fixtures or manually create the data in your tests (basically the same thing, when you think about it). Jason