Fraser Campbell
2006-Sep-13  15:00 UTC
Using erb in fixture to dynamically find a foreign key
Hi,
I have some unit tests that run perfectly when running the individual test but 
not when run via "rake test_units" ... here is a snippet from my
fixture:
first:
    id: 1
    state_id: <%= State.find_by_name(''Ontario'').id %>
In my unit test for clubs I do load the related fixtures:
  fixtures :states, :clubs
Run test directly ...
  fraser@xxx:~/src/yyy$ ruby test/unit/club_test.rb
  ...
  1 tests, 32 assertions, 0 failures, 0 errors
Run test via "rake test_units" ...
  1) Error:
  test_fixtures(ClubTest): Fixture::FormatError: a YAML error occured
  parsing /home/fraser/src/naasc/config/../test/fixtures/clubs.yml. Please
  note that YAML must be consistently indented using spaces. Tabs are not
  allowed. Please have a look at http://www.yaml.org/faq.html
  The exact error was: RuntimeError: Called id for nil, which would mistakenly
  be 4 -- if you really wanted the id of nil, use object_id
Can anyone point out where I''m going wrong?  It is rails 1.1.6, ruby
1.8.4,
postgresql, foreign key constraints are being enforced at db level (as well 
as in models of course).
Thx!
-- 
Fraser Campbell <fraser-Txk5XLRqZ6CsTnJN9+BGXg@public.gmane.org>          
http://www.wehave.net/
Georgetown, Ontario, Canada                               Debian GNU/Linux
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---