mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-06 01:08:21 +01:00
adds rake task to generate fixtures from db, adds a class method to ActiveRecord::Base to generate fixtures
This commit is contained in:
parent
3e112c13eb
commit
a2c09a3ff2
@ -6,4 +6,13 @@ ActiveRecord::Base.class_eval do
|
|||||||
to_yaml.sub!(/---\s?/, "\n"))
|
to_yaml.sub!(/---\s?/, "\n"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.dump_fixtures
|
||||||
|
fixture_file = "#{Rails.root}/test/fixtures/#{self.table_name}.yml"
|
||||||
|
File.open(fixture_file, "w") do |f|
|
||||||
|
self.all.each do |instance|
|
||||||
|
f.puts({ "#{self.table_name.singularize}_#{instance.id}" => instance.attributes }.to_yaml.sub!(/---\s?/, "\n"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -177,4 +177,13 @@ namespace :fablab do
|
|||||||
|
|
||||||
puts "\nUsers successfully notified\n\n"
|
puts "\nUsers successfully notified\n\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "generate fixtures from db"
|
||||||
|
task generate_fixtures: :environment do
|
||||||
|
Rails.application.eager_load!
|
||||||
|
ActiveRecord::Base.descendants.reject { |c| c == ActiveRecord::SchemaMigration }.each do |ar_base|
|
||||||
|
p "========== #{ar_base} =============="
|
||||||
|
ar_base.dump_fixtures
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user