File tree Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
module SQLite3
4
4
class TestPragmas < SQLite3 ::TestCase
5
+ class DatabaseTracker < SQLite3 ::Database
6
+ attr_reader :test_statements
7
+
8
+ def initialize ( ...)
9
+ @test_statements = [ ]
10
+ super
11
+ end
12
+
13
+ def execute ( sql , bind_vars = [ ] , &block )
14
+ @test_statements << sql
15
+ super
16
+ end
17
+ end
18
+
5
19
def setup
6
20
super
7
- @db = SQLite3 ::Database . new ( ":memory:" )
21
+ @db = DatabaseTracker . new ( ":memory:" )
22
+ end
23
+
24
+ def teardown
25
+ @db . close
8
26
end
9
27
10
28
def test_pragma_errors
@@ -32,5 +50,28 @@ def test_set_boolean_pragma
32
50
ensure
33
51
@db . set_boolean_pragma ( "read_uncommitted" , 0 )
34
52
end
53
+
54
+ def test_optimize_with_no_args
55
+ @db . optimize
56
+
57
+ assert_equal ( [ "PRAGMA optimize" ] , @db . test_statements )
58
+ end
59
+
60
+ def test_optimize_with_args
61
+ @db . optimize ( Constants ::Optimize ::DEFAULT )
62
+ @db . optimize ( Constants ::Optimize ::ANALYZE_TABLES | Constants ::Optimize ::LIMIT_ANALYZE )
63
+ @db . optimize ( Constants ::Optimize ::ANALYZE_TABLES | Constants ::Optimize ::DEBUG )
64
+ @db . optimize ( Constants ::Optimize ::DEFAULT | Constants ::Optimize ::CHECK_ALL_TABLES )
65
+
66
+ assert_equal (
67
+ [
68
+ "PRAGMA optimize=18" ,
69
+ "PRAGMA optimize=18" ,
70
+ "PRAGMA optimize=3" ,
71
+ "PRAGMA optimize=65554"
72
+ ] ,
73
+ @db . test_statements
74
+ )
75
+ end
35
76
end
36
77
end
You can’t perform that action at this time.
0 commit comments