Skip to content

Instantly share code, notes, and snippets.

@carpeliam
Created January 30, 2009 21:09
Show Gist options
  • Save carpeliam/55259 to your computer and use it in GitHub Desktop.
Save carpeliam/55259 to your computer and use it in GitHub Desktop.
desc "Run with same args as db:fixtures:load, but uses semi-sequential IDs"
task :load_fixtures => :environment do
require 'active_record/fixtures'
class Fixtures
def self.identify(label)
@@id_lookups ||= {}
@@id_lookups[label] ||= @@id_lookups.size + 1
end
end
ActiveRecord::Base.establish_connection(Rails.env)
base_dir = ENV['FIXTURES_PATH'] ? File.join(Rails.root, ENV['FIXTURES_PATH']) : File.join(Rails.root, 'test', 'fixtures')
fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment