Can anyone point me to an easy way to load fixture data into the development (not test) database? - Tim __________________________________ Celebrate Yahoo!''s 10th Birthday! Yahoo! Netrospective: 100 Moments of the Web http://birthday.yahoo.com/netrospective/
Timothy Myrtle wrote:> Can anyone point me to an easy way to load fixture > data into the development (not test) database?I added the following to my Rakefile: desc "Load fixtures data into the development database" task :load_fixtures_data_to_development do require ''active_record/fixtures'' ActiveRecord::Base.establish_connection( ActiveRecord::Base.configurations["development"]) Fixtures.create_fixtures("test/fixtures", ActiveRecord::Base.configurations[:fixtures_load_order]) end I''ve defined configurations[:fixtures_load_order] in my environment.rb since this is also used by similar code in my test suite to load the fixutures in the correct order, since I have foreign key constraints to satisfy. Tim. -- Tim Bates tim-kZbwfhiKUx26c6uEtOJ/EA@public.gmane.org
Exactly what I was looking for -- Thanks Tim! -Tim
Just to continue this Tim-only thread ;) On 03/03/2005, at 6:23 PM, Tim Bates wrote:> Timothy Myrtle wrote: >> Can anyone point me to an easy way to load fixture >> data into the development (not test) database? > > I added the following to my Rakefile: > > desc "Load fixtures data into the development database" > task :load_fixtures_data_to_development do > require ''active_record/fixtures'' > ActiveRecord::Base.establish_connection( > ActiveRecord::Base.configurations["development"]) > Fixtures.create_fixtures("test/fixtures", > ActiveRecord::Base.configurations[:fixtures_load_order]) > end > > I''ve defined configurations[:fixtures_load_order] in my environment.rb > since this is also used by similar code in my test suite to load the > fixutures in the correct order, since I have foreign key constraints > to satisfy.I like! =) Don''t mind if i add this as a howto? - tim lucas
Tim Lucas wrote:> On 03/03/2005, at 6:23 PM, Tim Bates wrote: >> I''ve defined configurations[:fixtures_load_order] in my environment.rb >> since this is also used by similar code in my test suite to load the >> fixutures in the correct order, since I have foreign key constraints >> to satisfy. > > I like! =) > Don''t mind if i add this as a howto?Tim(opoly), are you using PostgreSQL and trying to satisfy foreign key constraints among your fixtures? If so, check out http://article.gmane.org/gmane.comp.lang.ruby.rails/3737 and http://dev.rubyonrails.com/ticket/760 You can generate the "scratch" test database from a template containing all your fixtures, then wrap your test cases in BEGIN ... ROLLBACK. It''s way faster than tons of DELETE + INSERT per test case and you no longer need to keep track of which fixtures need to be declared where. jeremy