Sha256: c36ccb5cf5b5fd7047087266bdddfc5711f5b8b127fce6a3183dcb3ecb1593fd

Contents?: true

Size: 997 Bytes

Versions: 8

Compression:

Stored size: 997 Bytes

Contents

require 'active_record'

class PGInitializer
  def self.initialize!
    config = {
      'adapter'   => 'postgresql',
      'encoding'  => 'unicode',
      'database'  => 'superstore_test',
      'pool'      => 5,
      '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

8 entries across 8 versions & 1 rubygems

Version Path
superstore-1.0.12 test/support/pg.rb
superstore-1.0.11 test/support/pg.rb
superstore-1.0.10 test/support/pg.rb
superstore-1.0.9 test/support/pg.rb
superstore-1.0.8 test/support/pg.rb
superstore-1.0.7 test/support/pg.rb
superstore-1.0.6 test/support/pg.rb
superstore-1.0.5 test/support/pg.rb