Sha256: 9d807f8413b8edd58f61a3bc266078ec2343116586004825251ec0c15e20bf40

Contents?: true

Size: 1.03 KB

Versions: 14

Compression:

Stored size: 1.03 KB

Contents

require 'support/active_record/database_setup'
require 'support/active_record/schema_setup'

module PostgreSQLHelper
  puts "Active Record #{ActiveRecord::VERSION::STRING}, pg"

  # ActiveRecord::Base.logger = Logger.new(STDERR)

  def config
    db_config['postgres']
  end

  def create_db
    @encoding = config['encoding'] || ENV['CHARSET'] || 'utf8'
    begin
      establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
      ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding))
    rescue Exception => e
      $stderr.puts e, *(e.backtrace)
      $stderr.puts "Couldn't create database for #{config.inspect}"
    end
  end

  def establish_connection config = config
    ActiveRecord::Base.establish_connection(config)
  end

  def active_record_pg_setup
    create_db
    establish_connection
    load_schema
  end

  def active_record_pg_connection
    ActiveRecord::Base.connection
  end
end

RSpec.configure do |c|
  c.include PostgreSQLHelper
end

Version data entries

14 entries across 9 versions & 3 rubygems

Version Path
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/database_cleaner-1.2.0/spec/support/active_record/postgresql_setup.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/database_cleaner-1.2.0/spec/support/active_record/postgresql_setup.rb
apl-library-0.0.90 vendor/bundle/ruby/1.8/gems/database_cleaner-1.2.0/spec/support/active_record/postgresql_setup.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/database_cleaner-1.2.0/spec/support/active_record/postgresql_setup.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.8/gems/database_cleaner-1.2.0/spec/support/active_record/postgresql_setup.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/database_cleaner-1.2.0/spec/support/active_record/postgresql_setup.rb
database_cleaner-1.3.0 spec/support/active_record/postgresql_setup.rb
database_cleaner-1.2.0 spec/support/active_record/postgresql_setup.rb
database_cleaner-1.1.1 spec/support/active_record/postgresql_setup.rb
database_cleaner-1.1.0 spec/support/active_record/postgresql_setup.rb
database_cleaner-1.0.1 spec/support/active_record/postgresql_setup.rb
database_cleaner-1.0.0.RC1 spec/support/active_record/postgresql_setup.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/database_cleaner-0.9.1/spec/support/active_record/postgresql_setup.rb
database_cleaner-0.9.1 spec/support/active_record/postgresql_setup.rb