Fixtures dilemma - hard coded id values

Hi all,

Ruby 1.8.5
Rails 1.1.6

I have a dilemma. For some of my tables I want to use the fixture data
as the initial set of data for that table. This was easy enough using
the migrations helper, but I discovered a problem - I had to remove the
hard coded id values because it was causing confusion with regards to
the autogenerated sequence value (PostgreSQL) for the id column.

Ok, no problem, remove the hard coded id values and all is well.

Except that now I get “Couldn’t find MyModel without an ID” when I try
to run the unit tests. My test case is pretty basic:

class MyModelTest < Test::Unit::TestCase
fixtures :mymodel

def setup
@mymodel = MyModel.find(1)
end

run some standard tests.

end

Why do I need to hard code the ID value in the fixture in order to get
the tests to work? In development this works without issue - the
database just assigns sequence.nextval as the ID for the next inserted
record.

What should I do?

Thanks,

Dan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs