1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

adds a method to ActiveRecord::Base to dump a model to fixture

This commit is contained in:
Nicolas Florentin 2016-04-05 10:08:29 +02:00
parent 272400a889
commit 6bcc03834a

View File

@ -0,0 +1,9 @@
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
end