aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-02-23 00:17:01 +0000
committerJon Leighton <j@jonathanleighton.com>2011-02-28 22:12:34 +0000
commitd90b4e2615e8048fdeffc6dffe3246704adee01f (patch)
treea17aeea81d5070a55de874fa6617f7212429ae1f /activerecord/test/cases/associations
parent7112cf5e021d8da7c4e073a4e2d2a4afb10671ec (diff)
downloadrails-d90b4e2615e8048fdeffc6dffe3246704adee01f.tar.gz
rails-d90b4e2615e8048fdeffc6dffe3246704adee01f.tar.bz2
rails-d90b4e2615e8048fdeffc6dffe3246704adee01f.zip
Rewrote AssociationPreload.
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb29
-rw-r--r--activerecord/test/cases/associations/join_model_test.rb2
2 files changed, 15 insertions, 16 deletions
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