aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorYasuo Honda <yasuo.honda@gmail.com>2012-05-24 00:55:53 +0900
committerPatrick Mahoney <pat@polycrystal.org>2012-05-25 13:17:47 -0500
commit40cfcacca4c12a74556bfda3bded979df43434eb (patch)
tree0cc58cefce729fc5b0db7ab90cf71d8aa950e923 /activerecord/test
parent0777773389955cd4c42759d66ce531fd2af7cf63 (diff)
downloadrails-40cfcacca4c12a74556bfda3bded979df43434eb.tar.gz
rails-40cfcacca4c12a74556bfda3bded979df43434eb.tar.bz2
rails-40cfcacca4c12a74556bfda3bded979df43434eb.zip
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().
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb7
1 files changed, 7 insertions, 0 deletions
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