Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 71 lines (54 sloc) 1.757 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

ACTIVERECORD_GEM_VERSION = ENV['ACTIVERECORD_GEM_VERSION'] || '~> 3.0.3'

require 'rubygems'
gem 'activerecord', ACTIVERECORD_GEM_VERSION

require 'active_record'
require 'test/unit'
require File.join(File.dirname(__FILE__), *%w{ .. lib activerecord-postgresql-extensions })

ActiveRecord::Base.configurations = {
  'arunit' => {
    :adapter => 'postgresql',
    :database => 'postgresql_extensions_unit_tests',
    :min_messages => 'warning'
  }
}

ActiveRecord::Base.establish_connection 'arunit'
#ActiveRecord::Base.connection.drop_database('postgresql_extensions_unit_tests')
#ActiveRecord::Base.connection.create_database('postgresql_extensions_unit_tests')

ARBC = ActiveRecord::Base.connection

puts "Testing against ActiveRecord #{Gem.loaded_specs['activerecord'].version.to_s}"
if postgresql_version = ARBC.query('SELECT version()').flatten.to_s
  puts "PostgreSQL info from version(): #{postgresql_version}"
end

class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
  def statements
    @statements ||= []
  end

  def execute_with_statement_capture(sql, name = nil)
    statements << sql
    #execute_without_statement_capture(sql, name)
  end
  alias_method_chain :execute, :statement_capture

  def query_with_statement_capture(sql, name = nil)
    statements << sql
    #query_without_statement_capture(sql, name)
  end
  alias_method_chain :query, :statement_capture

  def clear_statements!
    @statements = []
  end
end

module PostgreSQLExtensionsTestHelper
  def clear_statements!
    ActiveRecord::Base.connection.clear_statements!
  end

  def statements
    ActiveRecord::Base.connection.statements
  end

  def setup
    clear_statements!
  end
end

class Mig < ActiveRecord::Migration
end

class Foo < ActiveRecord::Base
end
Something went wrong with that request. Please try again.