Run tests without IdentityMap when IM=false is given.

This commit is contained in:
Emilio Tagua 2011-02-15 12:40:41 -03:00
parent ca75091fc7
commit f1778eb44a
6 changed files with 23 additions and 15 deletions

@ -185,7 +185,7 @@ def test_finding_with_includes_on_has_one_assocation_with_same_include_includes_
author = authors(:david)
post = author.post_about_thinking_with_last_comment
last_comment = post.last_comment
author = assert_queries(2) { Author.find(author.id, :include => {:post_about_thinking_with_last_comment => :last_comment})} # find the author, then find the posts, then find the comments
author = assert_queries(ActiveRecord::IdentityMap.enabled? ? 2 : 3) { Author.find(author.id, :include => {:post_about_thinking_with_last_comment => :last_comment})} # find the author, then find the posts, then find the comments
assert_no_queries do
assert_equal post, author.post_about_thinking_with_last_comment
assert_equal last_comment, author.post_about_thinking_with_last_comment.last_comment
@ -196,7 +196,7 @@ def test_finding_with_includes_on_belongs_to_association_with_same_include_inclu
post = posts(:welcome)
author = post.author
author_address = author.author_address
post = assert_queries(2) { Post.find(post.id, :include => {:author_with_address => :author_address}) } # find the post, then find the author, then find the address
post = assert_queries(ActiveRecord::IdentityMap.enabled? ? 2 : 3) { Post.find(post.id, :include => {:author_with_address => :author_address}) } # find the post, then find the author, then find the address
assert_no_queries do
assert_equal author, post.author_with_address
assert_equal author_address, post.author_with_address.author_address
@ -817,18 +817,18 @@ def test_eager_loading_with_conditions_on_joined_table_preloads
assert_equal [posts(:welcome)], posts
assert_equal authors(:david), assert_no_queries { posts[0].author}
posts = assert_queries(1) do
posts = assert_queries(ActiveRecord::IdentityMap.enabled? ? 1 : 2) do
Post.find(:all, :select => 'distinct posts.*', :include => :author, :joins => [:comments], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id')
end
assert_equal [posts(:welcome)], posts
assert_equal authors(:david), assert_no_queries { posts[0].author}
posts = assert_queries(1) do
posts = assert_queries(ActiveRecord::IdentityMap.enabled? ? 1 : 2) do
Post.find(:all, :include => :author, :joins => {:taggings => :tag}, :conditions => "tags.name = 'General'", :order => 'posts.id')
end
assert_equal posts(:welcome, :thinking), posts
posts = assert_queries(1) do
posts = assert_queries(ActiveRecord::IdentityMap.enabled? ? 1 : 2) do
Post.find(:all, :include => :author, :joins => {:taggings => {:tag => :taggings}}, :conditions => "taggings_tags.super_tag_id=2", :order => 'posts.id')
end
assert_equal posts(:welcome, :thinking), posts
@ -842,7 +842,7 @@ def test_eager_loading_with_conditions_on_string_joined_table_preloads
assert_equal [posts(:welcome)], posts
assert_equal authors(:david), assert_no_queries { posts[0].author}
posts = assert_queries(1) do
posts = assert_queries(ActiveRecord::IdentityMap.enabled? ? 1 : 2) do
Post.find(:all, :select => 'distinct posts.*', :include => :author, :joins => ["INNER JOIN comments on comments.post_id = posts.id"], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id')
end
assert_equal [posts(:welcome)], posts
@ -931,7 +931,7 @@ def test_preloading_empty_belongs_to
def test_preloading_empty_belongs_to_polymorphic
t = Tagging.create!(:taggable_type => 'Post', :taggable_id => Post.maximum(:id) + 1, :tag => tags(:general))
tagging = assert_queries(1) { Tagging.preload(:taggable).find(t.id) }
tagging = assert_queries(ActiveRecord::IdentityMap.enabled? ? 1 : 2) { Tagging.preload(:taggable).find(t.id) }
assert_no_queries { assert_nil tagging.taggable }
end

@ -88,12 +88,12 @@ def test_has_one_through_with_conditions_eager_loading
# conditions on the through table
assert_equal clubs(:moustache_club), Member.find(@member.id, :include => :favourite_club).favourite_club
memberships(:membership_of_favourite_club).update_attribute(:favourite, false)
assert_equal nil, Member.find(@member.id, :include => :favourite_club).favourite_club.reload
assert_equal nil, Member.find(@member.id, :include => :favourite_club).reload.favourite_club
# conditions on the source table
assert_equal clubs(:moustache_club), Member.find(@member.id, :include => :hairy_club).hairy_club
clubs(:moustache_club).update_attribute(:name, "Association of Clean-Shaven Persons")
assert_equal nil, Member.find(@member.id, :include => :hairy_club).hairy_club.reload
assert_equal nil, Member.find(@member.id, :include => :hairy_club).reload.hairy_club
end
def test_has_one_through_polymorphic_with_source_type

@ -5,6 +5,10 @@
class InverseHasManyIdentityMapTest < ActiveRecord::TestCase
fixtures :authors, :posts
def setup
skip unless ActiveRecord::IdentityMap.enabled?
end
def test_parent_instance_should_be_shared_with_every_child_on_find
m = Author.first
is = m.posts

@ -27,7 +27,7 @@
QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type')
# Enable Identity Map for testing
ActiveRecord::IdentityMap.enabled = true
ActiveRecord::IdentityMap.enabled = (ENV['IM'] == "false" ? false : true)
def current_adapter?(*types)
types.any? do |type|

@ -25,6 +25,10 @@ class IdentityMapTest < ActiveRecord::TestCase
:developers_projects, :computers, :authors, :author_addresses,
:posts, :tags, :taggings, :comments, :subscribers
def setup
skip unless ActiveRecord::IdentityMap.enabled?
end
##############################################################################
# Basic tests checking if IM is functioning properly on basic find operations#
##############################################################################

@ -285,7 +285,7 @@ def test_find_with_preloaded_associations
assert posts.first.comments.first
end
assert_queries(1) do
assert_queries(ActiveRecord::IdentityMap.enabled? ? 1 : 2) do
posts = Post.preload(:comments).to_a
assert posts.first.comments.first
end
@ -295,12 +295,12 @@ def test_find_with_preloaded_associations
assert posts.first.author
end
assert_queries(1) do
assert_queries(ActiveRecord::IdentityMap.enabled? ? 1 : 2) do
posts = Post.preload(:author).to_a
assert posts.first.author
end
assert_queries(1) do
assert_queries(ActiveRecord::IdentityMap.enabled? ? 2 : 3) do
posts = Post.preload(:author, :comments).to_a
assert posts.first.author
assert posts.first.comments.first
@ -313,7 +313,7 @@ def test_find_with_included_associations
assert posts.first.comments.first
end
assert_queries(1) do
assert_queries(ActiveRecord::IdentityMap.enabled? ? 1 : 2) do
posts = Post.scoped.includes(:comments)
assert posts.first.comments.first
end
@ -323,7 +323,7 @@ def test_find_with_included_associations
assert posts.first.author
end
assert_queries(1) do
assert_queries(ActiveRecord::IdentityMap.enabled? ? 2 : 3) do
posts = Post.includes(:author, :comments).to_a
assert posts.first.author
assert posts.first.comments.first