I''m looking for a plugin/whatever for preloading fixtures, to run tests with FKs defined. Specifying load order just doesn''t work for me, I need to purge the test db, load all fixtures, and only then create the FK constraints. Any suggestions? Isak --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On 11/10/06, Isak Hansen <isak.hansen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m looking for a plugin/whatever for preloading fixtures, to run > tests with FKs defined. > > Specifying load order just doesn''t work for me, I need to purge the > test db, load all fixtures, and only then create the FK constraints. > > Any suggestions? > > > Isak > > > >Isak, I use the foreign key support offered by the redhillonrails_core plugin. Redhill plugins: http://www.redhillconsulting.com.au/rails_plugins.html redhillonrails_core plugin svn repo: svn://rubyforge.org/var/svn/redhillonrails/trunk/vendor/plugins/redhillonrails_core To run tests I just clone the development database. $ rake db:test:clone_structure Now your test database has all your foreign keys. Just specify your fixtures in order (in your tests) and you shouldn''t have any problems. For example if a customer belongs to an account and has a foreign key contraint customers(account_id) to accounts(id) then the following order will load the fixtures fine. class CustomersControllerTest < Test::Unit::TestCase fixtures :accounts, :customers end If you really want to preload all the fixtures then just make a custom rake task: desc "Load fixtures into the current environment''s database in order" task :load => :environment do require ''active_record/fixtures'' ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) [ :accounts, :customers, :jobs ].each{|f| Fixtures.create_fixtures(''test/fixtures'', f) } end Hope this helps. -- Zack Chandler http://depixelate.com --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
apsoto-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Nov-12 04:51 UTC
Re: Testing with foreign keys
What we''re doing is define all the fixtures in test_helper.rb so you don''t have to define them in each test file. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---