Skip to content

Commit

Permalink
Cache metadata in advance to avoid extra sql statements while testing.
Browse files Browse the repository at this point in the history
Reason: If metadata is not cached extra sql statements
will be executed, which causes failures tests with assert_queries().
  • Loading branch information
yahonda authored and pmahoney committed May 25, 2012
1 parent 0777773 commit 40cfcac
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions activerecord/test/cases/associations/eager_test.rb
Expand Up @@ -962,6 +962,10 @@ def test_eager_loading_with_order_on_joined_table_preloads
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
Expand Down Expand Up @@ -1011,6 +1015,9 @@ def test_eager_loading_with_select_on_joined_table_preloads

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
Expand Down

0 comments on commit 40cfcac

Please sign in to comment.