DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Loading Fixtures To Development Database

07.02.2005
| 7687 views |
  • submit to reddit
        Fixed the previous example so it would load environment first:

desc "Load fixtures data into the development database"
task :load_fixtures_to_development => :environment do
  ActiveRecord::Base.establish_connection(:development)
  require 'active_record/fixtures'
  Fixtures.create_fixtures("test/fixtures", ActiveRecord::Base.configurations[:fixtures_load_order])
  puts "Loaded these fixtures: " + ActiveRecord::Base.configurations[:fixtures_load_order].collect { |f| f.to_s }.join(', ')
end

This requires a fixture list in database.yml (or you can specify in environment.rb if you wish:

:fixtures_load_order:
  - :fixture_1
  - :fixture_2
  - :fixture_3
  - :fixture_4
  - :fixture_5