Guest User

Untitled

a guest
Apr 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. desc 'Create YAML test fixtures from data in an existing database.
  2. Defaults to development database. Set RAILS_ENV to override.'
  3.  
  4. task :extract_fixtures => :environment do
  5. sql = "SELECT * FROM %s"
  6. skip_tables = ["schema_info"]
  7. ActiveRecord::Base.establish_connection
  8. (ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
  9. i = "000"
  10. File.open("#{RAILS_ROOT}/test/fixtures/#{table_name}.yml", 'w') do |file|
  11. data = ActiveRecord::Base.connection.select_all(sql % table_name)
  12. file.write data.inject({}) { |hash, record|
  13. hash["#{table_name}_#{i.succ!}"] = record
  14. hash
  15. }.to_yaml
  16. end
  17. end
  18. end
Add Comment
Please, Sign In to add comment