Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/pstore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def path
def commit
in_transaction
@abort = false
throw :pstore_abort_transaction
throw self
end

# Exits the current transaction block, discarding any changes
Expand All @@ -538,7 +538,7 @@ def commit
def abort
in_transaction
@abort = true
throw :pstore_abort_transaction
throw self
end

# Opens a transaction block for the store.
Expand Down Expand Up @@ -570,7 +570,7 @@ def transaction(read_only = false) # :yields: pstore
begin
@table, checksum, original_data_size = load_data(file, read_only)

catch(:pstore_abort_transaction) do
catch(self) do
value = yield(self)
end

Expand All @@ -583,7 +583,7 @@ def transaction(read_only = false) # :yields: pstore
else
# This can only occur if read_only == true.
@table = {}
catch(:pstore_abort_transaction) do
catch(self) do
value = yield(self)
end
end
Expand Down
17 changes: 17 additions & 0 deletions test/test_pstore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,21 @@ def test_store_operations_require_transaction_owner
owner.join if owner
end

def test_commit_targets_the_owning_store
inner = PStore.new(second_file)
@pstore.transaction do
@pstore[:outer] = true
inner.transaction do
inner[:inner] = true
@pstore.commit
flunk("outer commit should exit its own transaction")
end
flunk("outer commit should exit its own transaction")
end

assert_equal(true, @pstore.transaction(true) { @pstore[:outer] })
assert_nil(inner.transaction(true) { inner[:inner] })
ensure
File.unlink(second_file) rescue nil
end
end