Skip to content

Commit d17dfc7

Browse files
authored
Compare the missing-default sentinel by identity (#61)
1 parent c53ca37 commit d17dfc7

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/pstore.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def [](key)
439439
def fetch(key, default=PStore::Error)
440440
in_transaction
441441
unless @table.key? key
442-
if default == PStore::Error
442+
if PStore::Error.equal?(default)
443443
raise PStore::Error, format("undefined key '%s'", key)
444444
else
445445
return default

test/test_pstore.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,13 @@ def test_commit_targets_the_owning_store
235235
ensure
236236
File.unlink(second_file) rescue nil
237237
end
238+
239+
def test_fetch_compares_missing_default_by_identity
240+
default = Object.new
241+
def default.==(_other)
242+
true
243+
end
244+
245+
assert_same(default, @pstore.transaction(true) { @pstore.fetch(:missing, default) })
246+
end
238247
end

0 commit comments

Comments
 (0)