Permalink
Browse files

Added tests for without_identity_map finding by all, first, and last.

  • Loading branch information...
1 parent 8b41bd7 commit 58e57dd48ab81806522841b4f3e9a9692e95bc56 @jnunemaker jnunemaker committed Jan 23, 2010
Showing with 33 additions and 5 deletions.
  1. +5 −5 lib/mongo_mapper/plugins/identity_map.rb
  2. +28 −0 test/functional/test_identity_map.rb
@@ -4,7 +4,7 @@ module IdentityMap
def self.models
@models ||= Set.new
end
-
+
def self.clear
models.each { |m| m.identity_map.clear }
end
@@ -14,7 +14,7 @@ def inherited(descendant)
descendant.identity_map = identity_map
super
end
-
+
def identity_map
@identity_map ||= {}
end
@@ -72,14 +72,14 @@ def identity_map_on?
def identity_map_off?
!identity_map_on?
end
-
+
def without_identity_map(&block)
identity_map_off
yield
ensure
identity_map_on
end
-
+
private
def remove_documents_from_map(*documents)
documents.flatten.compact.each do |document|
@@ -90,7 +90,7 @@ def remove_documents_from_map(*documents)
def simple_find?(criteria)
criteria.keys == [:_id] || criteria.keys.to_set == [:_id, :_type].to_set
end
-
+
def selecting_fields?(options)
!options[:fields].nil?
end
@@ -465,7 +465,35 @@ class ::BlogPost < ::Item
context "all" do
should "not add to map" do
@post_class.without_identity_map do
+ post1 = @post_class.create(:title => 'Foo')
+ post2 = @post_class.create(:title => 'Bar')
+ @post_class.identity_map.clear
+ assert_not_in_map(@post_class.all)
+ end
+ end
+ end
+
+ context "first" do
+ should "not add to map" do
+ @post_class.without_identity_map do
+ post1 = @post_class.create(:title => 'Foo')
+ post2 = @post_class.create(:title => 'Bar')
+ @post_class.identity_map.clear
+
+ assert_not_in_map(@post_class.first)
+ end
+ end
+ end
+
+ context "last" do
+ should "not add to map" do
+ @post_class.without_identity_map do
+ post1 = @post_class.create(:title => 'Foo')
+ post2 = @post_class.create(:title => 'Bar')
+ @post_class.identity_map.clear
+
+ assert_not_in_map(@post_class.last(:order => 'title'))
end
end
end

0 comments on commit 58e57dd

Please sign in to comment.