On 5/2/07, Sean H. [email protected] wrote:
that new object and save it to the database both user.memberships and
club.memberships are not populated; let alone user.clubs or
club.users (the through relationships) No matter how many ways I
save and load the active records nothing seems to work as expected.
Would like to see your code. This sounds like you don’t have
set up correctly.
The other problem I have with yml fixtures is that it’s hard to build
relationships with them since they only represent one table. I guess I
could manually connect them with the ‘id’ field across multiple yml
files, but that’s pretty clunky compared to creating only what you need
in the specific test. It also means lots of objects in my fixtures
which clutters things up and makes it unclear what exactly is required
to demonstrate the functionality being tested.
It sounds like you don’t like thinking about the database. Unless you
an absolute ton of relationships (questionable in itself, of course),
not hard to put together data exactly as you want for testing. You do
to understand what goes on in the database itself and what ActiveRecord
expects to properly use Rails with AR.
You are of course able to write ActiveRecord code to build objects (such
in setup, or in a separate file required in tests), but that requires
your relationships are set up correctly. If you’re using ActiveRecord,
need to manually set up data in fixtures to test your relationships.
Is there something you’re confused about with fixtures or ActiveRecord
I’ve been searching for information about best-practices in unit testing
rails and this information just doesn’t seem to exist. Most of the
examples are pretty brain-dead and don’t deal with relationships and
object interactions which is where most of the bugs and interesting
design problems are.
class MyModelTest < Test::Unit::TestCase
fixtures :my_models, :pieces
model = MyModel.new
assert_equal 3, model.pieces.size
Please define “brain-dead”. It unit-testing supposed to be witty and
exciting and something hard to figure out? Or do you need a tutorial on