diff --git a/lib/pstore.rb b/lib/pstore.rb index 7ff328b..3928c48 100644 --- a/lib/pstore.rb +++ b/lib/pstore.rb @@ -380,7 +380,7 @@ def initialize(file, thread_safe = false) if File::exist? file and not File::readable? file raise PStore::Error, format("file %s not readable", file) end - @filename = file + @filename = File.path(file) @abort = false @ultra_safe = false @thread_safe = thread_safe diff --git a/test/test_pstore.rb b/test/test_pstore.rb index b20ce99..ec922fa 100644 --- a/test/test_pstore.rb +++ b/test/test_pstore.rb @@ -2,6 +2,7 @@ require 'test/unit' require 'pstore' require 'tmpdir' +require 'pathname' class PStoreTest < Test::Unit::TestCase def setup @@ -296,4 +297,14 @@ def test_interrupted_atomic_save_removes_temporary_file File.define_singleton_method(:new, original_new) if original_new Dir.glob("#{@pstore_file}.tmp.*").each { |path| File.unlink(path) rescue nil } end + + def test_path_like_filename_is_normalized + store = PStore.new(Pathname(@pstore_file)) + store.ultra_safe = true + store.transaction { store[:foo] = "bar" } + + assert_instance_of(String, store.path) + assert_equal(@pstore_file, store.path) + assert_equal("bar", store.transaction(true) { store[:foo] }) + end end