Sha256: 78d48dd33808910431eca5cc8bbc8e5eb4258f04634aeb3eb31bf7bb85673d5d
Contents?: true
Size: 1.04 KB
Versions: 6
Compression:
Stored size: 1.04 KB
Contents
require 'active_record' class PGInitializer def self.initialize! config = { 'adapter' => 'postgresql', 'encoding' => 'unicode', 'database' => 'superstore_test', 'pool' => 5, 'host' => 'localhost', 'password' => 'postgres', 'username' => 'postgres' } ActiveRecord::Base.configurations = { test: config } ActiveRecord::Tasks::DatabaseTasks.drop config ActiveRecord::Tasks::DatabaseTasks.create config ActiveRecord::Base.establish_connection config create_users_table end def self.create_users_table ActiveRecord::Migration.create_table :users do |t| t.string :special_id, null: false t.index :special_id, unique: true end end def self.table_names %w(users) end end PGInitializer.initialize! ActiveRecord::Migration.verbose = false module ActiveSupport class TestCase teardown do PGInitializer.table_names.each do |table_name| ActiveRecord::Base.connection.execute "TRUNCATE #{table_name}" end end end end
Version data entries
6 entries across 6 versions & 1 rubygems