I've been trying to figure out a strange bug in one of my applications
that I think I've narrowed down to a problem with rails fixtures. It
seems as though the after_create callback is being run twice when I
save a record. This is only happening a) in the test environment, and
b) when there is a fixture file for that table.
The test below only prints "Doing stuff" one time if I remove the
'fixtures' line. Likewise, saving the item through ./script/console
in development mode also does not call the do_stuff method twice.
I'm inclined to think that this is a bug in the handling of fixtures,
but I'd love to be proven wrong. I couldn't find this in trac, but if
there's an open ticket, then I'd like to know about it. If not, and
if everyone agrees that this is a likely bug, then I'll open one.
class Item < ActiveRecord::Base
puts "Doing stuff"
require File.dirname(__FILE__) + '/../test_helper'
class ItemTest < Test::Unit::TestCase
@item = Item.new
The fixture file:
The rake run:
# rake test:units
/opt/local/bin/ruby -Ilib:test "/opt/local/lib/ruby/gems/1.8/gems/
Loaded suite /opt/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/