aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2010-10-15 15:44:21 -0300
committerEmilio Tagua <miloops@gmail.com>2010-11-19 19:08:55 -0300
commit08c37b7ed8281bc3e3c1eca98a4859017c89157a (patch)
tree529919fbe6b60edf4498051728b79ed13656376a /activerecord
parent3a34ae04bdf5e0badc85daef5f204d02688f193d (diff)
downloadrails-08c37b7ed8281bc3e3c1eca98a4859017c89157a.tar.gz
rails-08c37b7ed8281bc3e3c1eca98a4859017c89157a.tar.bz2
rails-08c37b7ed8281bc3e3c1eca98a4859017c89157a.zip
Use block syntax in IdentityMap middleware.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/identity_map.rb11
-rw-r--r--activerecord/test/cases/identity_map_test.rb8
2 files changed, 16 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/identity_map.rb b/activerecord/lib/active_record/identity_map.rb
index cca4198c69..30a2a1eb0f 100644
--- a/activerecord/lib/active_record/identity_map.rb
+++ b/activerecord/lib/active_record/identity_map.rb
@@ -27,7 +27,12 @@ module ActiveRecord
end
def use
+ old, self.enabled = self.enabled, true
+
yield if block_given?
+ ensure
+ self.enabled = old
+ ActiveRecord::IdentityMap.clear
end
def without
@@ -93,9 +98,9 @@ module ActiveRecord
end
def call(env)
- @app.call(env)
- ensure
- ActiveRecord::IdentityMap.clear
+ ActiveRecord::IdentityMap.use do
+ @app.call(env)
+ end
end
end
end
diff --git a/activerecord/test/cases/identity_map_test.rb b/activerecord/test/cases/identity_map_test.rb
index 1588633e1d..df77bc5af2 100644
--- a/activerecord/test/cases/identity_map_test.rb
+++ b/activerecord/test/cases/identity_map_test.rb
@@ -39,6 +39,14 @@ class IdentityMapTest < ActiveRecord::TestCase
end
end
+ def test_find_id_use_identity_map
+ ActiveRecord::IdentityMap.enabled = false
+ ActiveRecord::IdentityMap.use do
+ assert_same(Client.find(3), Client.find(3))
+ end
+ ActiveRecord::IdentityMap.enabled = true
+ end
+
def test_find_pkey
assert_same(
Subscriber.find('swistak'),