@@ -43,6 +43,49 @@ def test_yaml_dump_and_load
43
43
tempfile . unlink
44
44
end
45
45
46
+ def test_yaml_dump_and_load_with_gzip
47
+ # Create an empty cache.
48
+ cache = SchemaCache . new @connection
49
+
50
+ tempfile = Tempfile . new ( [ "schema_cache-" , ".yml.gz" ] )
51
+ # Dump it. It should get populated before dumping.
52
+ cache . dump_to ( tempfile . path )
53
+
54
+ # Unzip and load manually.
55
+ cache = Zlib ::GzipReader . open ( tempfile . path ) { |gz | YAML . load ( gz . read ) }
56
+
57
+ # Give it a connection. Usually the connection
58
+ # would get set on the cache when it's retrieved
59
+ # from the pool.
60
+ cache . connection = @connection
61
+
62
+ assert_no_queries do
63
+ assert_equal 12 , cache . columns ( "posts" ) . size
64
+ assert_equal 12 , cache . columns_hash ( "posts" ) . size
65
+ assert cache . data_sources ( "posts" )
66
+ assert_equal "id" , cache . primary_keys ( "posts" )
67
+ assert_equal 1 , cache . indexes ( "posts" ) . size
68
+ assert_equal @database_version . to_s , cache . database_version . to_s
69
+ end
70
+
71
+ # Load the cache the usual way.
72
+ cache = SchemaCache . load_from ( tempfile . path )
73
+
74
+ # Give it a connection.
75
+ cache . connection = @connection
76
+
77
+ assert_no_queries do
78
+ assert_equal 12 , cache . columns ( "posts" ) . size
79
+ assert_equal 12 , cache . columns_hash ( "posts" ) . size
80
+ assert cache . data_sources ( "posts" )
81
+ assert_equal "id" , cache . primary_keys ( "posts" )
82
+ assert_equal 1 , cache . indexes ( "posts" ) . size
83
+ assert_equal @database_version . to_s , cache . database_version . to_s
84
+ end
85
+ ensure
86
+ tempfile . unlink
87
+ end
88
+
46
89
def test_yaml_loads_5_1_dump
47
90
cache = SchemaCache . load_from ( schema_dump_path )
48
91
cache . connection = @connection
@@ -162,6 +205,43 @@ def test_marshal_dump_and_load_via_disk
162
205
tempfile . unlink
163
206
end
164
207
208
+ def test_marshal_dump_and_load_with_gzip
209
+ # Create an empty cache.
210
+ cache = SchemaCache . new @connection
211
+
212
+ tempfile = Tempfile . new ( [ "schema_cache-" , ".dump.gz" ] )
213
+ # Dump it. It should get populated before dumping.
214
+ cache . dump_to ( tempfile . path )
215
+
216
+ # Load a new cache manually.
217
+ cache = Zlib ::GzipReader . open ( tempfile . path ) { |gz | Marshal . load ( gz . read ) }
218
+ cache . connection = @connection
219
+
220
+ assert_no_queries do
221
+ assert_equal 12 , cache . columns ( "posts" ) . size
222
+ assert_equal 12 , cache . columns_hash ( "posts" ) . size
223
+ assert cache . data_sources ( "posts" )
224
+ assert_equal "id" , cache . primary_keys ( "posts" )
225
+ assert_equal 1 , cache . indexes ( "posts" ) . size
226
+ assert_equal @database_version . to_s , cache . database_version . to_s
227
+ end
228
+
229
+ # Load a new cache.
230
+ cache = SchemaCache . load_from ( tempfile . path )
231
+ cache . connection = @connection
232
+
233
+ assert_no_queries do
234
+ assert_equal 12 , cache . columns ( "posts" ) . size
235
+ assert_equal 12 , cache . columns_hash ( "posts" ) . size
236
+ assert cache . data_sources ( "posts" )
237
+ assert_equal "id" , cache . primary_keys ( "posts" )
238
+ assert_equal 1 , cache . indexes ( "posts" ) . size
239
+ assert_equal @database_version . to_s , cache . database_version . to_s
240
+ end
241
+ ensure
242
+ tempfile . unlink
243
+ end
244
+
165
245
def test_data_source_exist
166
246
assert @cache . data_source_exists? ( "posts" )
167
247
assert_not @cache . data_source_exists? ( "foo" )
0 commit comments