Class: SQLite3::TestDatabaseReadwrite

Inherits:
TestCase
  • Object
show all
Defined in:
lib/sqlite3-1.5.3-arm64-darwin/test/test_database_readwrite.rb,
lib/sqlite3-1.5.3-x86_64-darwin/test/test_database_readwrite.rb

Instance Method Summary collapse

Methods inherited from TestCase

#assert_nothing_raised

Instance Method Details

#setupObject



5
6
7
8
9
10
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_readwrite.rb', line 5

def setup
  File.unlink 'test-readwrite.db' if File.exist?('test-readwrite.db')
  @db = SQLite3::Database.new('test-readwrite.db')
  @db.execute("CREATE TABLE foos (id integer)")
  @db.close
end

#teardownObject



12
13
14
15
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_readwrite.rb', line 12

def teardown
  @db.close unless @db.closed?
  File.unlink 'test-readwrite.db' if File.exist?('test-readwrite.db')
end

#test_insert_readwrite_databaseObject



35
36
37
38
39
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_readwrite.rb', line 35

def test_insert_readwrite_database
  @db = SQLite3::Database.new('test-readwrite.db', :readwrite => true)
  @db.execute("INSERT INTO foos (id) VALUES (12)")
  assert @db.changes == 1
end

#test_open_readwrite_databaseObject



17
18
19
20
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_readwrite.rb', line 17

def test_open_readwrite_database
  @db = SQLite3::Database.new('test-readwrite.db', :readwrite => true)
  assert !@db.readonly?
end

#test_open_readwrite_not_exists_databaseObject



28
29
30
31
32
33
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_readwrite.rb', line 28

def test_open_readwrite_not_exists_database
  File.unlink 'test-readwrite.db'
  assert_raise(SQLite3::CantOpenException) do
    @db = SQLite3::Database.new('test-readwrite.db', :readonly => true)
  end
end

#test_open_readwrite_readonly_databaseObject



22
23
24
25
26
# File 'lib/sqlite3-1.5.3-arm64-darwin/test/test_database_readwrite.rb', line 22

def test_open_readwrite_readonly_database
  assert_raise(RuntimeError) do
    @db = SQLite3::Database.new('test-readwrite.db', :readwrite => true, :readonly => true)
  end
end