About this user

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

Copy data from database into fixtures

Take from pylonhead.com

  def self.to_fixture
    write_file(File.expand_path("test/fixtures/#{table_name}.yml", RAILS_ROOT),
      self.find(:all).inject("---\n") { |s, record|
        self.columns.inject(s+"#{record.id}:\n") { |s, c|
          s+"  #{{c.name => record.attributes[c.name]}.to_yaml[5..-1]}\n" }
    })
  end
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed