<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -471,9 +471,11 @@ module ActiveRecord #:nodoc:
           def without_locking(&amp;block)
             current = ActiveRecord::Base.lock_optimistically
             ActiveRecord::Base.lock_optimistically = false if current
-            result = block.call
-            ActiveRecord::Base.lock_optimistically = true if current
-            result
+            begin
+              block.call
+            ensure
+              ActiveRecord::Base.lock_optimistically = true if current
+            end
           end
         end
       end</diff>
      <filename>lib/acts_as_versioned.rb</filename>
    </modified>
    <modified>
      <diff>@@ -342,4 +342,29 @@ class VersionedTest &lt; 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, &quot;oh noes&quot;
+      end
+    end
+    assert ActiveRecord::Base.lock_optimistically
+  end
 end
\ No newline at end of file</diff>
      <filename>test/versioned_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a42dba642e86f3f27d8b2e67b632d2e377b6074c</id>
    </parent>
  </parents>
  <author>
    <name>Hongli Lai (Phusion)</name>
    <email>hongli@phusion.nl</email>
  </author>
  <url>http://github.com/technoweenie/acts_as_versioned/commit/1bd3d255eb43562a44fd1f907d82ec80db2872d3</url>
  <id>1bd3d255eb43562a44fd1f907d82ec80db2872d3</id>
  <committed-date>2009-03-23T07:00:17-07:00</committed-date>
  <authored-date>2009-03-23T07:00:17-07:00</authored-date>
  <message>Make sure that without_locking reverts AR::Base.lock_optimistically to its old value even if the given block raises an exception.</message>
  <tree>aac96ecae0bb1e521a0310f6bac1410112ddb964</tree>
  <committer>
    <name>Hongli Lai (Phusion)</name>
    <email>hongli@phusion.nl</email>
  </committer>
</commit>
