aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorHongli Lai (Phusion) <hongli@phusion.nl>2009-03-23 15:00:17 +0100
committerHongli Lai (Phusion) <hongli@phusion.nl>2009-03-23 15:00:17 +0100
commit1bd3d255eb43562a44fd1f907d82ec80db2872d3 (patch)
treeaac96ecae0bb1e521a0310f6bac1410112ddb964 /test
parenta42dba642e86f3f27d8b2e67b632d2e377b6074c (diff)
Make sure that without_locking reverts AR::Base.lock_optimistically to its old value even if the given block raises an exception.rails_2
Diffstat (limited to 'test')
-rw-r--r--test/versioned_test.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/versioned_test.rb b/test/versioned_test.rb
index c0c8e514d..9c4f2c91f 100644
--- a/test/versioned_test.rb
+++ b/test/versioned_test.rb
@@ -342,4 +342,29 @@ class VersionedTest < Test::Unit::TestCase
assert landmarks(:washington).changed?
assert !landmarks(:washington).altered?
end
+
+ def test_without_locking_temporarily_disables_optimistic_locking
+ enabled1 = false
+ block_called = false
+
+ ActiveRecord::Base.lock_optimistically = true
+ LockedPage.without_locking do
+ enabled1 = ActiveRecord::Base.lock_optimistically
+ block_called = true
+ end
+ enabled2 = ActiveRecord::Base.lock_optimistically
+
+ assert block_called
+ assert !enabled1
+ assert enabled2
+ end
+
+ def test_without_locking_reverts_optimistic_locking_settings_if_block_raises_exception
+ assert_raises(RuntimeError) do
+ LockedPage.without_locking do
+ raise RuntimeError, "oh noes"
+ end
+ end
+ assert ActiveRecord::Base.lock_optimistically
+ end
end \ No newline at end of file