stewbawka
2006-Sep-20 14:35 UTC
unit test fails when trying to load legacy join table fixture
my misadventures in the realm of testing continue.. here''s the situation: testing the methods of a model and one of them does some link table look up to find records in a habtm relationship.. the join table wasn''t exactly made with rails in mind, but it is not so far off.. the message i get when trying to load the join table fixture is this: 1) Error: test_functions(InventoryTest): ActiveRecord::RecordNotFound: Couldn''t find InventoryDescription without an ID /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:939:in `find_from_ids'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:382:in `find'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:401:in `find'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:227:in `instantiate_fixtures'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:225:in `instantiate_fixtures'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:794:in `silence'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:224:in `instantiate_fixtures'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:589:in `instantiate_fixtures'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:588:in `instantiate_fixtures'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:525:in `setup_with_fixtures'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:547:in `setup'' I have another join table that is built the way it should be and the fixture loads fine.. anyways here''s the discrepancies with the join table who''s fixture doesn''t want to load properly: migration: create_table "inventory_descriptions", :id => false, :force => true do |t| t.column "inventory_id", :integer, :default => 0, :null => false t.column "description_id", :integer, :default => 0, :null => false t.column "lastupdate", :timestamp end as you can see the :id => false is set so that follows rails conventions.. not sure about whether giving the link an extra ''lastupdate'' attribute is kosher. the other join tables i did didn''t have any extra info for the links.. Also, i know that the name should be descriptions_inventory, but is that really that big of a deal? in the model i set the table name accordingly (see below) class InventoryDescription < ActiveRecord::Base set_table_name "inventory_descriptions" #set_primary_key "inventory_id, description_id" end Also, in inventory model i have: has_and_belongs_to_many :descriptions and in descriptions: has_and_belongs_to_many :inventory inventory model also sets tablename to ''inventory'' since i wasn''t sure if rails conventions would think it should be name inventories.. a sample of the fixture for the link table: inventory_descriptions_12852: description_id: "285" inventory_id: "1259" lastupdate: 2006-09-13 17:36:14 inventory_descriptions_1229: description_id: "257" inventory_id: "207" lastupdate: 2006-09-13 17:36:33 ...... etc So what steps do i need to take to get the fixture to load and continue testing? the actual app code seems to work fine for these tables although it doesn''t use the magical linking stuff (inv_instance.descriptions or desc_instance.inventory) thanks in advance, stuart --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---