Hello, even after several months of Rails development I’m still facing
few problems with unit testing.
- 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
- 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 !