From 40cfcacca4c12a74556bfda3bded979df43434eb Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Thu, 24 May 2012 00:55:53 +0900 Subject: Cache metadata in advance to avoid extra sql statements while testing. Reason: If metadata is not cached extra sql statements will be executed, which causes failures tests with assert_queries(). --- activerecord/test/cases/associations/eager_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 08467900f9..470929881a 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -962,6 +962,10 @@ class EagerAssociationTest < ActiveRecord::TestCase end def test_eager_loading_with_conditions_on_joined_table_preloads + # cache metadata in advance to avoid extra sql statements executed while testing + Tagging.first + Tag.first + posts = assert_queries(2) do Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => [:comments], :where => "comments.body like 'Thank you%'", :order => 'posts.id').all end @@ -1011,6 +1015,9 @@ class EagerAssociationTest < ActiveRecord::TestCase def test_eager_loading_with_conditions_on_join_model_preloads Author.columns + + # cache metadata in advance to avoid extra sql statements executed while testing + AuthorAddress.first authors = assert_queries(2) do Author.scoped(:includes => :author_address, :joins => :comments, :where => "posts.title like 'Welcome%'").all -- cgit v1.2.3