diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-03 03:24:28 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-03 03:24:28 +0530 |
commit | 6f5f23aaa7c4673fe923c6ad1450baaeccb40c02 (patch) | |
tree | b1314b211da78667eb80a8b4c93f68c2acae35c7 /activerecord/test | |
parent | c51347152abc7d8a97fd8df3eecfdbfd07673b68 (diff) | |
download | rails-6f5f23aaa7c4673fe923c6ad1450baaeccb40c02.tar.gz rails-6f5f23aaa7c4673fe923c6ad1450baaeccb40c02.tar.bz2 rails-6f5f23aaa7c4673fe923c6ad1450baaeccb40c02.zip |
Add Relation#includes to be an equivalent of current finder option :include
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index bea2946130..18f6152cc0 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -178,7 +178,7 @@ class RelationTest < ActiveRecord::TestCase end end - def test_find_with_included_associations + def test_find_with_preloaded_associations assert_queries(2) do posts = Post.preload(:comments) assert posts.first.comments.first @@ -206,6 +206,29 @@ class RelationTest < ActiveRecord::TestCase end end + def test_find_with_included_associations + assert_queries(2) do + posts = Post.includes(:comments) + assert posts.first.comments.first + end + + assert_queries(2) do + posts = Post.scoped.includes(:comments) + assert posts.first.comments.first + end + + assert_queries(2) do + posts = Post.includes(:author) + assert posts.first.author + end + + assert_queries(3) do + posts = Post.includes(:author, :comments).to_a + assert posts.first.author + assert posts.first.comments.first + end + end + def test_default_scope_with_conditions_string assert_equal Developer.find_all_by_name('David').map(&:id).sort, DeveloperCalledDavid.scoped.map(&:id).sort assert_equal nil, DeveloperCalledDavid.create!.name |