Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 188 lines (150 sloc) 4.847 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
require 'rubygems'
require "bundler"
Bundler.setup(:default, :development)

$:.unshift(File.expand_path('../../lib', __FILE__))

require 'rspec'

if !defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby'
  puts "==> Running specs with MRI version #{RUBY_VERSION}"
  require 'oci8'
elsif RUBY_ENGINE == 'jruby'
  puts "==> Running specs with JRuby version #{JRUBY_VERSION}"
end

ENV['RAILS_GEM_VERSION'] ||= '3.2-master'
NO_COMPOSITE_PRIMARY_KEYS = true if ENV['RAILS_GEM_VERSION'] >= '2.3.5' || ENV['RAILS_GEM_VERSION'] =~ /^2\.3\.1\d$/

puts "==> Running specs with Rails version #{ENV['RAILS_GEM_VERSION']}"

require 'active_record'

if ENV['RAILS_GEM_VERSION'] >= '3.0'
  require 'action_dispatch'
  require 'active_support/core_ext/module/attribute_accessors'
  require 'active_support/core_ext/class/attribute_accessors'

  if ENV['RAILS_GEM_VERSION'] =~ /^3.0.0.beta/
    require "rails/log_subscriber"
    require 'active_record/railties/log_subscriber'
  else
    require "active_support/log_subscriber"
    require 'active_record/log_subscriber'
  end

  require 'logger'
elsif ENV['RAILS_GEM_VERSION'] =~ /^2.3/
  require 'action_pack'
  require 'action_controller/session/abstract_store'
  require 'active_record/session_store'
elsif ENV['RAILS_GEM_VERSION'] <= '2.3'
  require 'action_pack'
  require 'action_controller/session/active_record_store'
end

require 'active_record/connection_adapters/oracle_enhanced_adapter'
require 'ruby-plsql'

module LoggerSpecHelper
  def set_logger
    @logger = MockLogger.new
    @old_logger = ActiveRecord::Base.logger

    if ENV['RAILS_GEM_VERSION'] >= '3.0'
      @notifier = ActiveSupport::Notifications::Fanout.new

      ActiveSupport::LogSubscriber.colorize_logging = false

      ActiveRecord::Base.logger = @logger
      @old_notifier = ActiveSupport::Notifications.notifier
      ActiveSupport::Notifications.notifier = @notifier

      ActiveRecord::LogSubscriber.attach_to(:active_record)
      if ENV['RAILS_GEM_VERSION'] >= '3.2'
        ActiveSupport::Notifications.subscribe("sql.active_record", ActiveRecord::ExplainSubscriber.new)
      end
    else # ActiveRecord 2.x
      if ActiveRecord::Base.respond_to?(:connection_pool)
        ActiveRecord::Base.connection_pool.clear_reloadable_connections!
      else
        ActiveRecord::Base.clear_active_connections!
      end
      ActiveRecord::Base.logger = @logger
      ActiveRecord::Base.colorize_logging = false
      # ActiveRecord::Base.logger.level = Logger::DEBUG
    end

  end

  class MockLogger
    attr_reader :flush_count

    def initialize
      @flush_count = 0
      @logged = Hash.new { |h,k| h[k] = [] }
    end

    # used in AtiveRecord 2.x
    def debug?
      true
    end

    def method_missing(level, message)
      @logged[level] << message
    end

    def logged(level)
      @logged[level].compact.map { |l| l.to_s.strip }
    end

    def output(level)
      logged(level).join("\n")
    end

    def flush
      @flush_count += 1
    end

    def clear(level)
      @logged[level] = []
    end
  end

  def clear_logger
    ActiveRecord::Base.logger = @old_logger
    @logger = nil

    if ENV['RAILS_GEM_VERSION'] >= '3.0'
      ActiveSupport::Notifications.notifier = @old_notifier
      @notifier = nil
    end

  end

  # Wait notifications to be published (for Rails 3.0)
  # should not be currently used with sync queues in tests
  def wait
    @notifier.wait if @notifier
  end

end

module SchemaSpecHelper
  def schema_define(&block)
    ActiveRecord::Schema.define do
      suppress_messages do
        instance_eval(&block)
      end
    end
  end
end

DATABASE_NAME = ENV['DATABASE_NAME'] || 'orcl'
DATABASE_HOST = ENV['DATABASE_HOST']
DATABASE_PORT = ENV['DATABASE_PORT']
DATABASE_USER = ENV['DATABASE_USER'] || 'oracle_enhanced'
DATABASE_PASSWORD = ENV['DATABASE_PASSWORD'] || 'oracle_enhanced'
DATABASE_SYS_PASSWORD = ENV['DATABASE_SYS_PASSWORD'] || 'admin'

CONNECTION_PARAMS = {
  :adapter => "oracle_enhanced",
  :database => DATABASE_NAME,
  :host => DATABASE_HOST,
  :port => DATABASE_PORT,
  :username => DATABASE_USER,
  :password => DATABASE_PASSWORD
}

SYS_CONNECTION_PARAMS = {
  :adapter => "oracle_enhanced",
  :database => DATABASE_NAME,
  :host => DATABASE_HOST,
  :port => DATABASE_PORT,
  :username => "sys",
  :password => DATABASE_SYS_PASSWORD,
  :privilege => "SYSDBA"
}

SYSTEM_CONNECTION_PARAMS = {
  :adapter => "oracle_enhanced",
  :database => DATABASE_NAME,
  :host => DATABASE_HOST,
  :port => DATABASE_PORT,
  :username => "system",
  :password => DATABASE_SYS_PASSWORD
}

DATABASE_NON_DEFAULT_TABLESPACE = ENV['DATABASE_NON_DEFAULT_TABLESPACE'] || "SYSTEM"

# Set default $KCODE to UTF8
if RUBY_VERSION < "1.9"
  $KCODE = "UTF8"
end

# set default time zone in TZ environment variable
# which will be used to set session time zone
ENV['TZ'] ||= 'Europe/Riga'
Something went wrong with that request. Please try again.