From a82f1e3f5d11c8dfba9f4c911745ec40a7965216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 18 Sep 2012 22:24:45 -0300 Subject: Cache columns metadata to avoid extra while testing --- activerecord/test/cases/associations/eager_test.rb | 6 ++++++ activerecord/test/cases/associations/has_many_associations_test.rb | 2 ++ activerecord/test/cases/dirty_test.rb | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index bf01b46852..544c01461d 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -929,6 +929,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.find(:all, :select => 'distinct posts.*', :include => :author, :joins => [:comments], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id') end @@ -977,7 +981,9 @@ class EagerAssociationTest < ActiveRecord::TestCase end def test_eager_loading_with_conditions_on_join_model_preloads + # cache metadata in advance to avoid extra sql statements executed while testing Author.columns + AuthorAddress.first authors = assert_queries(2) do Author.find(:all, :include => :author_address, :joins => :comments, :conditions => "posts.title like 'Welcome%'") diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 30cfcc53d2..618daa1b35 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1470,6 +1470,8 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_custom_primary_key_on_new_record_should_fetch_with_query + Essay.first # cache metadata in advance to avoid extra sql statements executed while testing + author = Author.new(:name => "David") assert !author.essays.loaded? diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index 3bd2e909d7..e1129704a6 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -325,6 +325,8 @@ class DirtyTest < ActiveRecord::TestCase end def test_partial_update_with_optimistic_locking + Person.first # cache metadata in advance to avoid extra sql statements executed while testing + person = Person.new(:first_name => 'foo') old_lock_version = 1 @@ -530,7 +532,7 @@ class DirtyTest < ActiveRecord::TestCase pirate = target.create(:created_on => created_on) pirate.reload # Here mysql truncate the usec value to 0 - + pirate.created_on = created_on assert !pirate.created_on_changed? end -- cgit v1.2.3