@@ -6,9 +6,8 @@ module ActiveRecord
6
6
module ConnectionAdapters
7
7
class SchemaCacheTest < ActiveRecord ::TestCase
8
8
def setup
9
- @connection = ARUnit2Model . connection
10
- @cache = new_bound_reflection
11
- @database_version = @connection . get_database_version
9
+ @connection = ARUnit2Model . connection
10
+ @cache = new_bound_reflection
12
11
@check_schema_cache_dump_version_was = SchemaReflection . check_schema_cache_dump_version
13
12
end
14
13
@@ -67,7 +66,6 @@ def test_yaml_dump_and_load
67
66
assert cache . data_source_exists? ( "courses" )
68
67
assert_equal "id" , cache . primary_keys ( "courses" )
69
68
assert_equal 1 , cache . indexes ( "courses" ) . size
70
- assert_equal @database_version . to_s , cache . database_version . to_s
71
69
end
72
70
ensure
73
71
tempfile . unlink
@@ -104,7 +102,6 @@ def test_yaml_dump_and_load_with_gzip
104
102
assert cache . data_source_exists? ( @connection , "courses" )
105
103
assert_equal "id" , cache . primary_keys ( @connection , "courses" )
106
104
assert_equal 1 , cache . indexes ( @connection , "courses" ) . size
107
- assert_equal @database_version . to_s , cache . database_version ( @connection ) . to_s
108
105
end
109
106
110
107
# Load the cache the usual way.
@@ -116,7 +113,6 @@ def test_yaml_dump_and_load_with_gzip
116
113
assert cache . data_source_exists? ( "courses" )
117
114
assert_equal "id" , cache . primary_keys ( "courses" )
118
115
assert_equal 1 , cache . indexes ( "courses" ) . size
119
- assert_equal @database_version . to_s , cache . database_version . to_s
120
116
end
121
117
ensure
122
118
tempfile . unlink
@@ -141,18 +137,6 @@ def test_yaml_loads_5_1_dump_without_indexes_still_queries_for_indexes
141
137
end
142
138
end
143
139
144
- def test_yaml_loads_5_1_dump_without_database_version_still_queries_for_database_version
145
- cache = load_bound_reflection ( schema_dump_path )
146
-
147
- # We can't verify queries get executed because the database version gets
148
- # cached in both MySQL and PostgreSQL outside of the schema cache.
149
-
150
- assert_not_nil reflection = @cache . instance_variable_get ( :@schema_reflection )
151
- assert_nil reflection . instance_variable_get ( :@cache )
152
-
153
- assert_equal @database_version . to_s , cache . database_version . to_s
154
- end
155
-
156
140
def test_primary_key_for_existent_table
157
141
assert_equal "id" , @cache . primary_keys ( "courses" )
158
142
end
@@ -189,18 +173,6 @@ def test_indexes_for_non_existent_table
189
173
assert_equal [ ] , @cache . indexes ( "omgponies" )
190
174
end
191
175
192
- def test_caches_database_version
193
- @cache . database_version # cache database_version
194
-
195
- assert_no_queries do
196
- assert_equal @database_version . to_s , @cache . database_version . to_s
197
-
198
- if current_adapter? ( :Mysql2Adapter , :TrilogyAdapter )
199
- assert_not_nil @cache . database_version . full_version_string
200
- end
201
- end
202
- end
203
-
204
176
def test_clearing
205
177
@cache . columns ( "courses" )
206
178
@cache . columns_hash ( "courses" )
@@ -211,9 +183,6 @@ def test_clearing
211
183
@cache . clear!
212
184
213
185
assert_equal 0 , @cache . size
214
- reflection = @cache . instance_variable_get ( :@schema_reflection )
215
- schema_cache = reflection . instance_variable_get ( :@cache )
216
- assert_nil schema_cache . instance_variable_get ( :@database_version )
217
186
end
218
187
219
188
def test_marshal_dump_and_load
@@ -223,10 +192,6 @@ def test_marshal_dump_and_load
223
192
# Populate it.
224
193
cache . add ( "courses" )
225
194
226
- # We're going to manually dump, so we also need to force
227
- # database_version to be stored.
228
- cache . database_version
229
-
230
195
# Create a new cache by marshal dumping / loading.
231
196
cache = Marshal . load ( Marshal . dump ( cache . instance_variable_get ( :@schema_reflection ) . instance_variable_get ( :@cache ) ) )
232
197
@@ -236,7 +201,6 @@ def test_marshal_dump_and_load
236
201
assert cache . data_source_exists? ( @connection , "courses" )
237
202
assert_equal "id" , cache . primary_keys ( @connection , "courses" )
238
203
assert_equal 1 , cache . indexes ( @connection , "courses" ) . size
239
- assert_equal @database_version . to_s , cache . database_version ( @connection ) . to_s
240
204
end
241
205
end
242
206
@@ -257,7 +221,6 @@ def test_marshal_dump_and_load_via_disk
257
221
assert cache . data_source_exists? ( "courses" )
258
222
assert_equal "id" , cache . primary_keys ( "courses" )
259
223
assert_equal 1 , cache . indexes ( "courses" ) . size
260
- assert_equal @database_version . to_s , cache . database_version . to_s
261
224
end
262
225
ensure
263
226
tempfile . unlink
@@ -316,7 +279,6 @@ def test_marshal_dump_and_load_with_gzip
316
279
assert cache . data_source_exists? ( @connection , "courses" )
317
280
assert_equal "id" , cache . primary_keys ( @connection , "courses" )
318
281
assert_equal 1 , cache . indexes ( @connection , "courses" ) . size
319
- assert_equal @database_version . to_s , cache . database_version ( @connection ) . to_s
320
282
end
321
283
322
284
# Load a new cache.
@@ -328,7 +290,6 @@ def test_marshal_dump_and_load_with_gzip
328
290
assert cache . data_source_exists? ( "courses" )
329
291
assert_equal "id" , cache . primary_keys ( "courses" )
330
292
assert_equal 1 , cache . indexes ( "courses" ) . size
331
- assert_equal @database_version . to_s , cache . database_version . to_s
332
293
end
333
294
ensure
334
295
tempfile . unlink
@@ -389,28 +350,28 @@ def test_when_lazily_load_schema_cache_is_set_cache_is_lazily_populated_when_est
389
350
ActiveRecord ::Base . establish_connection ( new_config )
390
351
391
352
# cache starts empty
392
- assert_equal 0 , ActiveRecord ::Base . connection . pool . schema_reflection . instance_variable_get ( :@cache ) . size
353
+ assert_nil ActiveRecord ::Base . connection . pool . schema_reflection . instance_variable_get ( :@cache )
393
354
394
355
# now we access the cache, causing it to load
395
- assert ActiveRecord ::Base . connection . schema_cache . version
356
+ assert_not_nil ActiveRecord ::Base . connection . schema_cache . version
396
357
397
358
assert File . exist? ( tempfile )
398
- assert ActiveRecord ::Base . connection . pool . schema_reflection . instance_variable_get ( :@cache )
359
+ assert_not_nil ActiveRecord ::Base . connection . pool . schema_reflection . instance_variable_get ( :@cache )
399
360
400
361
# assert cache is still empty on new connection (precondition for the
401
362
# following to show it is loading because of the config change)
402
363
ActiveRecord ::Base . establish_connection ( new_config )
403
364
404
365
assert File . exist? ( tempfile )
405
- assert_equal 0 , ActiveRecord ::Base . connection . pool . schema_reflection . instance_variable_get ( :@cache ) . size
366
+ assert_nil ActiveRecord ::Base . connection . pool . schema_reflection . instance_variable_get ( :@cache )
406
367
407
368
# cache is loaded upon connection when lazily loading is on
408
369
old_config = ActiveRecord . lazily_load_schema_cache
409
370
ActiveRecord . lazily_load_schema_cache = true
410
371
ActiveRecord ::Base . establish_connection ( new_config )
411
372
412
373
assert File . exist? ( tempfile )
413
- assert ActiveRecord ::Base . connection . pool . schema_reflection . instance_variable_get ( :@cache )
374
+ assert_not_nil ActiveRecord ::Base . connection . pool . schema_reflection . instance_variable_get ( :@cache )
414
375
ensure
415
376
ActiveRecord . lazily_load_schema_cache = old_config
416
377
ActiveRecord ::Base . establish_connection ( :arunit )
@@ -449,7 +410,6 @@ def test_when_lazily_load_schema_cache_is_set_cache_is_lazily_populated_when_est
449
410
assert_equal expected , coder [ "data_sources" ]
450
411
assert_equal expected , coder [ "indexes" ]
451
412
assert coder . key? ( "version" )
452
- assert coder . key? ( "database_version" )
453
413
end
454
414
455
415
private
0 commit comments