-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathtest_database_readonly.rb
36 lines (31 loc) · 1.03 KB
/
test_database_readonly.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require "helper"
module SQLite3
class TestDatabaseReadonly < SQLite3::TestCase
def setup
File.unlink "test-readonly.db" if File.exist?("test-readonly.db")
@db = SQLite3::Database.new("test-readonly.db")
@db.execute("CREATE TABLE foos (id integer)")
@db.close
end
def teardown
@db.close unless @db.closed?
File.unlink "test-readonly.db" if File.exist?("test-readonly.db")
end
def test_open_readonly_database
@db = SQLite3::Database.new("test-readonly.db", readonly: true)
assert_predicate @db, :readonly?
end
def test_open_readonly_not_exists_database
File.unlink "test-readonly.db"
assert_raise(SQLite3::CantOpenException) do
@db = SQLite3::Database.new("test-readonly.db", readonly: true)
end
end
def test_insert_readonly_database
@db = SQLite3::Database.new("test-readonly.db", readonly: true)
assert_raise(SQLite3::ReadOnlyException) do
@db.execute("INSERT INTO foos (id) VALUES (12)")
end
end
end
end