提交 4015819a 编写于 作者: E Emilio Tagua

Fix number of queries performed in tests.

上级 9fe0dbf8
...@@ -170,7 +170,7 @@ def test_finding_with_includes_on_has_one_assocation_with_same_include_includes_ ...@@ -170,7 +170,7 @@ def test_finding_with_includes_on_has_one_assocation_with_same_include_includes_
author = authors(:david) author = authors(:david)
post = author.post_about_thinking_with_last_comment post = author.post_about_thinking_with_last_comment
last_comment = post.last_comment last_comment = post.last_comment
author = assert_queries(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 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
assert_no_queries do assert_no_queries do
assert_equal post, author.post_about_thinking_with_last_comment assert_equal post, author.post_about_thinking_with_last_comment
assert_equal last_comment, author.post_about_thinking_with_last_comment.last_comment assert_equal last_comment, author.post_about_thinking_with_last_comment.last_comment
...@@ -181,7 +181,7 @@ def test_finding_with_includes_on_belongs_to_association_with_same_include_inclu ...@@ -181,7 +181,7 @@ def test_finding_with_includes_on_belongs_to_association_with_same_include_inclu
post = posts(:welcome) post = posts(:welcome)
author = post.author author = post.author
author_address = author.author_address author_address = author.author_address
post = assert_queries(3) { Post.find(post.id, :include => {:author_with_address => :author_address}) } # find the post, then find the author, then find the 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
assert_no_queries do assert_no_queries do
assert_equal author, post.author_with_address assert_equal author, post.author_with_address
assert_equal author_address, post.author_with_address.author_address assert_equal author_address, post.author_with_address.author_address
...@@ -789,18 +789,18 @@ def test_eager_loading_with_conditions_on_joined_table_preloads ...@@ -789,18 +789,18 @@ def test_eager_loading_with_conditions_on_joined_table_preloads
assert_equal [posts(:welcome)], posts assert_equal [posts(:welcome)], posts
assert_equal authors(:david), assert_no_queries { posts[0].author} assert_equal authors(:david), assert_no_queries { posts[0].author}
posts = assert_queries(2) do posts = assert_queries(1) do
Post.find(:all, :select => 'distinct posts.*', :include => :author, :joins => [:comments], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id') Post.find(:all, :select => 'distinct posts.*', :include => :author, :joins => [:comments], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id')
end end
assert_equal [posts(:welcome)], posts assert_equal [posts(:welcome)], posts
assert_equal authors(:david), assert_no_queries { posts[0].author} assert_equal authors(:david), assert_no_queries { posts[0].author}
posts = assert_queries(2) do posts = assert_queries(1) do
Post.find(:all, :include => :author, :joins => {:taggings => :tag}, :conditions => "tags.name = 'General'", :order => 'posts.id') Post.find(:all, :include => :author, :joins => {:taggings => :tag}, :conditions => "tags.name = 'General'", :order => 'posts.id')
end end
assert_equal posts(:welcome, :thinking), posts assert_equal posts(:welcome, :thinking), posts
posts = assert_queries(2) do posts = assert_queries(1) do
Post.find(:all, :include => :author, :joins => {:taggings => {:tag => :taggings}}, :conditions => "taggings_tags.super_tag_id=2", :order => 'posts.id') Post.find(:all, :include => :author, :joins => {:taggings => {:tag => :taggings}}, :conditions => "taggings_tags.super_tag_id=2", :order => 'posts.id')
end end
assert_equal posts(:welcome, :thinking), posts assert_equal posts(:welcome, :thinking), posts
...@@ -814,7 +814,7 @@ def test_eager_loading_with_conditions_on_string_joined_table_preloads ...@@ -814,7 +814,7 @@ def test_eager_loading_with_conditions_on_string_joined_table_preloads
assert_equal [posts(:welcome)], posts assert_equal [posts(:welcome)], posts
assert_equal authors(:david), assert_no_queries { posts[0].author} assert_equal authors(:david), assert_no_queries { posts[0].author}
posts = assert_queries(2) do posts = assert_queries(1) 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') 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 end
assert_equal [posts(:welcome)], posts assert_equal [posts(:welcome)], posts
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册