diff --git a/lib/pstore.rb b/lib/pstore.rb index be9d6a1..0d89e75 100644 --- a/lib/pstore.rb +++ b/lib/pstore.rb @@ -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 @@ -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. @@ -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 @@ -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 diff --git a/test/test_pstore.rb b/test/test_pstore.rb index 3159b2f..33801e1 100644 --- a/test/test_pstore.rb +++ b/test/test_pstore.rb @@ -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