Sha256: 7b8db368ce614e5f00c213cbf3c6b83a0b5a38b0eab7c6e243f161ec9661331d
Contents?: true
Size: 1.45 KB
Versions: 6
Compression:
Stored size: 1.45 KB
Contents
class TestDB def self.connect ActiveRecord::Base.configurations = YAML::load(File.open(File.join(File.dirname(__FILE__),'..','database.yml'))) ActiveRecord::Base.establish_connection('test') end def self.clean [:foos,:fruits,:baskets,:fruit_baskets,:regions,:types].each do |t| DBSpecManagement.connection.execute("DELETE FROM #{t.to_s}") end end #Class to clean tables class DBSpecManagement < ActiveRecord::Base end end #Put all the test migrations here class TestMigrations < ActiveRecord::Migration # all the ups def self.up begin create_table :foos do |t| t.string :name end create_table :fruits do |t| t.string :name t.integer :region_id t.timestamps end create_table :baskets do |t| t.string :name t.timestamps end create_table :fruit_baskets do |t| t.integer :fruit_id t.integer :basket_id t.timestamps end create_table :regions do |t| t.string :name t.timestamps end create_table :types do |t| t.string :name t.timestamps end rescue => e puts "tables failed to create: #{e}" end end # all the downs def self.down begin [:foos,:fruits,:baskets,:fruit_baskets,:regions,:types].each do |t| drop_table t end rescue => e puts "tables were not dropped: #{e}" end end end
Version data entries
6 entries across 6 versions & 1 rubygems