Skip to content

Commit d94c42b

Browse files
authored
Merge pull request #283 from yb66/patch-1
Handle the file argument properly
2 parents b98034d + efc0103 commit d94c42b

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

lib/sqlite3/database.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def quote( string )
6565
def initialize file, options = {}, zvfs = nil
6666
mode = Constants::Open::READWRITE | Constants::Open::CREATE
6767

68+
file = file.to_path if file.respond_to? :to_path
6869
if file.encoding == ::Encoding::UTF_16LE || file.encoding == ::Encoding::UTF_16BE || options[:utf16]
6970
open16 file
7071
else

test/test_database.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ def test_filename_with_attachment
4545
tf.unlink if tf
4646
end
4747

48+
49+
def test_filename_to_path
50+
tf = Tempfile.new 'thing'
51+
pn = Pathname tf.path
52+
db = SQLite3::Database.new pn
53+
assert_equal pn.expand_path.to_s, File.expand_path(db.filename)
54+
ensure
55+
tf.close! if tf
56+
end
57+
58+
4859
def test_error_code
4960
begin
5061
db.execute 'SELECT'

0 commit comments

Comments
 (0)