Skip to content

Commit 958f700

Browse files
committed
test: add tests for pragma optimize.
1 parent 79c943f commit 958f700

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/test_pragmas.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,46 @@ def test_set_boolean_pragma
3232
ensure
3333
@db.set_boolean_pragma("read_uncommitted", 0)
3434
end
35+
36+
def test_optimize_with_no_args
37+
class << @db
38+
attr_reader :statements
39+
40+
def execute sql, bind_vars = [], &block
41+
(@statements ||= []) << sql
42+
super
43+
end
44+
end
45+
46+
@db.optimize
47+
48+
assert_equal(["PRAGMA optimize"], @db.statements)
49+
end
50+
51+
def test_optimize_with_args
52+
class << @db
53+
attr_reader :statements
54+
55+
def execute sql, bind_vars = [], &block
56+
(@statements ||= []) << sql
57+
super
58+
end
59+
end
60+
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.statements
74+
)
75+
end
3576
end
3677
end

0 commit comments

Comments
 (0)