Everything seems to work well in the development and production environments:
> script/console Loading development environment (Rails 2.3.8) ruby-1.8.7-p302 > Tape.find(:first, :conditions => "deleted_at is not null").deleted_at.nil? => false ruby-1.8.7-p302 > Tape.find(:first, :conditions => "deleted_at is null").deleted_at.nil? => true
So why am I getting the exact opposite results in the test environment?
> script/console test Loading test environment (Rails 2.3.8) ruby-1.8.7-p302 > Tape.find(:first, :conditions => "deleted_at is not null").deleted_at.nil? => true
Searching for deleted_at is null
never returns any records in the test environment, even when some calls have deleted_at = nil
and some have a timestamp there.
Here's a partial readout of the mysql table:
mysql> describe tapes; +-----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | ... | deleted_at | datetime | YES | | NULL | | +-----------------+--------------+------+-----+---------+----------------+
Does anyone know what's going on? Is this a bug?
So it turns out that the method I was using to create null values in my fixture was incorrect. It seems that if you want a real null value from a csv fixture is to have that field default to null and just don't include that column in your csv. Hopefully this will help someone else :)