-
Notifications
You must be signed in to change notification settings - Fork 25
/
helper.rb
91 lines (73 loc) · 2.03 KB
/
helper.rb
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
require File.join(File.dirname(__FILE__), 'setup')
require 'active_support/test_case'
module SlimScrooge
class Test
class << self
def setup
setup_constants
make_sqlite_config
make_sqlite_connection
load_models
load(SCHEMA_ROOT + "/schema.rb")
require 'test/unit'
end
def test_files
glob("#{File.dirname(__FILE__)}/**/*_test.rb")
end
def test_model_files
%w{course}
end
private
def setup_constants
set_constant('TEST_ROOT') {File.expand_path(File.dirname(__FILE__))}
set_constant('SCHEMA_ROOT') {TEST_ROOT + "/schema"}
end
def make_sqlite_config
ActiveRecord::Base.configurations = {
'db' => {
:adapter => 'sqlite3',
:database => 'test_db',
:timeout => 5000
}
}
end
def load_models
test_model_files.each {|f| require File.join(File.dirname(__FILE__), "models", f)}
end
def make_sqlite_connection
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['db'])
end
def set_constant(constant)
Object.const_set(constant, yield) unless Object.const_defined?(constant)
end
def glob(pattern)
Dir.glob(pattern)
end
end
end
class ActiveRecordTest < Test
class << self
def setup
setup_constants
end
def test_files
glob("#{AR_TEST_SUITE}/cases/**/*_test.rb").sort
end
def connection
File.join(AR_TEST_SUITE, 'connections', 'native_mysql')
end
private
def setup_constants
set_constant('MYSQL_DB_USER') {'rails'}
set_constant('AR_TEST_SUITE') {find_active_record_test_suite}
end
def find_active_record_test_suite
ts = ($:).grep(/activerecord/).last.split('/')
ts.pop
ts << 'test'
ts.join('/')
end
end
AR_TEST_SUITE = find_active_record_test_suite
end
end