2016-04-05 10:08:29 +02:00
|
|
|
ActiveRecord::Base.class_eval do
|
|
|
|
def dump_fixture
|
|
|
|
fixture_file = "#{Rails.root}/test/fixtures/#{self.class.table_name}.yml"
|
|
|
|
File.open(fixture_file, "a") do |f|
|
|
|
|
f.puts({ "#{self.class.table_name.singularize}_#{id}" => attributes }.
|
|
|
|
to_yaml.sub!(/---\s?/, "\n"))
|
|
|
|
end
|
|
|
|
end
|
2016-04-05 11:02:49 +02:00
|
|
|
|
|
|
|
def self.dump_fixtures
|
|
|
|
fixture_file = "#{Rails.root}/test/fixtures/#{self.table_name}.yml"
|
2016-04-05 12:05:40 +02:00
|
|
|
mode = (File.exists?(fixture_file) ? 'a' : 'w')
|
|
|
|
File.open(fixture_file, mode) do |f|
|
2016-04-05 12:28:22 +02:00
|
|
|
|
|
|
|
if self.attribute_names.include?("id")
|
|
|
|
self.all.each do |instance|
|
|
|
|
f.puts({ "#{self.table_name.singularize}_#{instance.id}" => instance.attributes }.to_yaml.sub!(/---\s?/, "\n"))
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.all.each_with_index do |instance, i|
|
|
|
|
f.puts({ "#{self.table_name.singularize}_#{i}" => instance.attributes }.to_yaml.sub!(/---\s?/, "\n"))
|
|
|
|
end
|
2016-04-05 11:02:49 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-05 10:08:29 +02:00
|
|
|
end
|