Skip to content

Instantly share code, notes, and snippets.

@trevorturk
Last active December 16, 2015 23:49
Show Gist options
  • Save trevorturk/5516046 to your computer and use it in GitHub Desktop.
Save trevorturk/5516046 to your computer and use it in GitHub Desktop.
Insert an additional, separate set of fixtures from db/seeds
desc "Insert an additional, separate set of fixtures from db/seeds"
task :seed_fixtures => :environment do
require 'active_record/fixtures'
files = "#{Rails.root}/db/seeds/*.yml"
connection = ActiveRecord::Base.connection
fixtures = Dir[files].collect do |file|
extname = File.extname(file)
name = File.basename(file).chomp(extname)
class_name = name.classify
path = file.chomp(extname)
ActiveRecord::FixtureSet.new(connection, name, class_name, path)
end
connection.transaction do
fixtures.each do |file|
file.table_rows.each do |name, rows|
rows.each do |row|
connection.insert_fixture(row, name)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment