@@ -8,6 +8,9 @@ class SchemaCacheTest < ActiveRecord::TestCase
8
8
self . use_transactional_tests = false
9
9
10
10
def setup
11
+ @deduplicable_registries_were = deduplicable_classes . index_with do |klass |
12
+ klass . registry . dup
13
+ end
11
14
@pool = ARUnit2Model . connection_pool
12
15
@connection = ARUnit2Model . lease_connection
13
16
@cache = new_bound_reflection
@@ -16,18 +19,47 @@ def setup
16
19
17
20
def teardown
18
21
SchemaReflection . check_schema_cache_dump_version = @check_schema_cache_dump_version_was
22
+ @deduplicable_registries_were . each do |klass , registry |
23
+ klass . registry . clear
24
+ klass . registry . merge! ( registry )
25
+ end
19
26
end
20
27
21
28
def new_bound_reflection ( pool = @pool )
22
29
BoundSchemaReflection . new ( SchemaReflection . new ( nil ) , pool )
23
30
end
24
31
25
32
def load_bound_reflection ( filename , pool = @pool )
33
+ reset_deduplicable!
26
34
BoundSchemaReflection . new ( SchemaReflection . new ( filename ) , pool ) . tap do |cache |
27
35
cache . load!
28
36
end
29
37
end
30
38
39
+ def deduplicable_classes
40
+ klasses = [
41
+ ActiveRecord ::ConnectionAdapters ::SqlTypeMetadata ,
42
+ ActiveRecord ::ConnectionAdapters ::Column ,
43
+ ]
44
+
45
+ if defined? ( ActiveRecord ::ConnectionAdapters ::PostgreSQL )
46
+ klasses << ActiveRecord ::ConnectionAdapters ::PostgreSQL ::TypeMetadata
47
+ end
48
+ if defined? ( ActiveRecord ::ConnectionAdapters ::MySQL ::TypeMetadata )
49
+ klasses << ActiveRecord ::ConnectionAdapters ::MySQL ::TypeMetadata
50
+ end
51
+
52
+ klasses . flat_map do |klass |
53
+ [ klass ] + klass . descendants
54
+ end . uniq
55
+ end
56
+
57
+ def reset_deduplicable!
58
+ deduplicable_classes . each do |klass |
59
+ klass . registry . clear
60
+ end
61
+ end
62
+
31
63
def test_cached?
32
64
cache = new_bound_reflection
33
65
assert_not cache . cached? ( "courses" )
@@ -38,6 +70,8 @@ def test_cached?
38
70
tempfile = Tempfile . new ( [ "schema_cache-" , ".yml" ] )
39
71
cache . dump_to ( tempfile . path )
40
72
73
+ reset_deduplicable!
74
+
41
75
reflection = SchemaReflection . new ( tempfile . path )
42
76
43
77
# `check_schema_cache_dump_version` forces us to have an active connection
@@ -60,6 +94,8 @@ def test_yaml_dump_and_load
60
94
# Dump it. It should get populated before dumping.
61
95
cache . dump_to ( tempfile . path )
62
96
97
+ reset_deduplicable!
98
+
63
99
# Load the cache.
64
100
cache = load_bound_reflection ( tempfile . path )
65
101
@@ -94,6 +130,8 @@ def test_yaml_dump_and_load_with_gzip
94
130
# Dump it. It should get populated before dumping.
95
131
cache . dump_to ( tempfile . path )
96
132
133
+ reset_deduplicable!
134
+
97
135
# Unzip and load manually.
98
136
cache = Zlib ::GzipReader . open ( tempfile . path ) do |gz |
99
137
YAML . respond_to? ( :unsafe_load ) ? YAML . unsafe_load ( gz . read ) : YAML . load ( gz . read )
0 commit comments