File: test_database_uri.rb

package info (click to toggle)
ruby-sqlite3 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 680 kB
  • sloc: ruby: 4,827; ansic: 1,868; sh: 91; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 1,296 bytes parent folder | download
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
37
38
39
40
41
42
43
44
45
46
47
require "helper"
require "tempfile"
require "pathname"

module SQLite3
  class TestDatabaseURI < SQLite3::TestCase
    def test_open_absolute_file_uri
      skip("windows uri paths are hard") if windows?
      skip("system libraries may not allow URIs") unless SQLite3::SQLITE_PACKAGED_LIBRARIES

      Tempfile.open "test.db" do |file|
        db = SQLite3::Database.new("file:#{file.path}")
        assert db
        db.close
      end
    end

    def test_open_relative_file_uri
      skip("windows uri paths are hard") if windows?
      skip("system libraries may not allow URIs") unless SQLite3::SQLITE_PACKAGED_LIBRARIES

      Dir.mktmpdir do |dir|
        Dir.chdir dir do
          db = SQLite3::Database.new("file:test.db")
          assert db
          assert_path_exists "test.db"
          db.close
        end
      end
    end

    def test_open_file_uri_readonly
      skip("windows uri paths are hard") if windows?
      skip("system libraries may not allow URIs") unless SQLite3::SQLITE_PACKAGED_LIBRARIES

      Tempfile.open "test.db" do |file|
        db = SQLite3::Database.new("file:#{file.path}?mode=ro")

        assert_raise(SQLite3::ReadOnlyException) do
          db.execute("CREATE TABLE foos (id integer)")
        end

        db.close
      end
    end
  end
end