fiveruns / data_fabric

Sharding support for ActiveRecord 2.x

This URL has Read+Write access

data_fabric / test / test_helper.rb
100644 41 lines (33 sloc) 1.089 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
ENV['RAILS_ENV'] = 'test'
RAILS_ENV = 'test'
ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), ".."))
DATABASE_YML_PATH = File.join(ROOT_PATH, "test", "database.yml")
Dir.chdir(ROOT_PATH)
 
require 'rubygems'
require 'test/unit'
 
version = ENV['AR_VERSION']
if version
  puts "Testing ActiveRecord #{version}"
  gem 'activerecord', "=#{version}"
end
 
require 'active_record'
require 'active_record/version'
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.logger.level = Logger::WARN
 
# Bootstrap DF
deps = defined?(ActiveSupport::Dependencies) ? ActiveSupport::Dependencies : Dependencies
deps.load_paths << File.join(File.dirname(__FILE__), '../lib')
require 'init'
 
def load_database_yml
  filename = DATABASE_YML_PATH
  YAML::load(ERB.new(IO.read(filename)).result)
end
 
def ar22?
  ActiveRecord::VERSION::STRING >= '2.2.0'
end
 
if !File.exist?(DATABASE_YML_PATH)
  puts "\n*** ERROR ***:\n" <<
    "You must have a 'test/database.yml' file in order to run the unit tests. " <<
    "An example is provided in 'test/database.yml.example'.\n\n"
  exit 1
end