<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: yaml code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 08:28:50 GMT</pubDate>
    <description>DZone Snippets: yaml code</description>
    <item>
      <title>Create YAML test fixtures from database in Rails</title>
      <link>http://snippets.dzone.com/posts/show/2525</link>
      <description>As found at &lt;a href="http://media.pragprog.com/titles/fr_rr/code/CreateFixturesFromLiveData/lib/tasks/extract_fixtures.rake"&gt;http://media.pragprog.com/titles/fr_rr/code/CreateFixturesFromLiveData/lib/tasks/extract_fixtures.rake&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;desc 'Create YAML test fixtures from data in an existing database.  &lt;br /&gt;Defaults to development database.  Set RAILS_ENV to override.'&lt;br /&gt;&lt;br /&gt;task :extract_fixtures =&gt; :environment do&lt;br /&gt;  sql  = "SELECT * FROM %s"&lt;br /&gt;  skip_tables = ["schema_info"]&lt;br /&gt;  ActiveRecord::Base.establish_connection&lt;br /&gt;  (ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|&lt;br /&gt;    i = "000"&lt;br /&gt;    File.open("#{RAILS_ROOT}/test/fixtures/#{table_name}.yml", 'w') do |file|&lt;br /&gt;      data = ActiveRecord::Base.connection.select_all(sql % table_name)&lt;br /&gt;      file.write data.inject({}) { |hash, record|&lt;br /&gt;        hash["#{table_name}_#{i.succ!}"] = record&lt;br /&gt;        hash&lt;br /&gt;      }.to_yaml&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 04 Sep 2006 01:48:31 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2525</guid>
      <author>jswizard (JavaScript Wizard)</author>
    </item>
  </channel>
</rss>
