From d90b4e2615e8048fdeffc6dffe3246704adee01f Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Wed, 23 Feb 2011 00:17:01 +0000 Subject: Rewrote AssociationPreload. --- activerecord/test/cases/associations/eager_test.rb | 29 +++++++++++----------- .../test/cases/associations/join_model_test.rb | 2 +- activerecord/test/cases/inheritance_test.rb | 2 +- 3 files changed, 16 insertions(+), 17 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index ca71cd8ed3..26808ae931 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -120,30 +120,29 @@ class EagerAssociationTest < ActiveRecord::TestCase def test_load_associated_records_in_one_query_when_adapter_has_no_limit Post.connection.expects(:in_clause_length).at_least_once.returns(nil) - Post.expects(:i_was_called).with([1,2,3,4,5,6,7]).returns([1]) - associated_records = Post.send(:associated_records, [1,2,3,4,5,6,7]) do |some_ids| - Post.i_was_called(some_ids) + + post = posts(:welcome) + assert_queries(2) do + Post.includes(:comments).where(:id => post.id).to_a end - assert_equal [1], associated_records end def test_load_associated_records_in_several_queries_when_many_ids_passed - Post.connection.expects(:in_clause_length).at_least_once.returns(5) - Post.expects(:i_was_called).with([1,2,3,4,5]).returns([1]) - Post.expects(:i_was_called).with([6,7]).returns([6]) - associated_records = Post.send(:associated_records, [1,2,3,4,5,6,7]) do |some_ids| - Post.i_was_called(some_ids) + Post.connection.expects(:in_clause_length).at_least_once.returns(1) + + post1, post2 = posts(:welcome), posts(:thinking) + assert_queries(3) do + Post.includes(:comments).where(:id => [post1.id, post2.id]).to_a end - assert_equal [1,6], associated_records end def test_load_associated_records_in_one_query_when_a_few_ids_passed - Post.connection.expects(:in_clause_length).at_least_once.returns(5) - Post.expects(:i_was_called).with([1,2,3]).returns([1]) - associated_records = Post.send(:associated_records, [1,2,3]) do |some_ids| - Post.i_was_called(some_ids) + Post.connection.expects(:in_clause_length).at_least_once.returns(3) + + post = posts(:welcome) + assert_queries(2) do + Post.includes(:comments).where(:id => post.id).to_a end - assert_equal [1], associated_records end def test_including_duplicate_objects_from_belongs_to diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index 6d7f905dc5..19303fef9f 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -214,7 +214,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase end def test_has_many_with_piggyback - assert_equal "2", categories(:sti_test).authors.first.post_id.to_s + assert_equal "2", categories(:sti_test).authors_with_select.first.post_id.to_s end def test_include_has_many_through diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index 680d4ca5dd..b5d8314541 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -208,7 +208,7 @@ class InheritanceTest < ActiveRecord::TestCase def test_eager_load_belongs_to_primary_key_quoting con = Account.connection - assert_sql(/#{con.quote_table_name('companies')}.#{con.quote_column_name('id')} = 1/) do + assert_sql(/#{con.quote_table_name('companies')}.#{con.quote_column_name('id')} IN \(1\)/) do Account.find(1, :include => :firm) end end -- cgit v1.2.3