aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/eager_test.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2012-08-28 12:48:59 -0700
committerPratik Naik <pratiknaik@gmail.com>2012-08-28 12:49:55 -0700
commit754173c5ff89bf3251dfcc6577e4b3c16de8aeef (patch)
tree38441a860b917c87422077235fb150f532e74944 /activerecord/test/cases/associations/eager_test.rb
parent810a50dacf9ddddc1d59c1cb350e8ce785c8bf85 (diff)
downloadrails-754173c5ff89bf3251dfcc6577e4b3c16de8aeef.tar.gz
rails-754173c5ff89bf3251dfcc6577e4b3c16de8aeef.tar.bz2
rails-754173c5ff89bf3251dfcc6577e4b3c16de8aeef.zip
Add a test to make sure preloading properly merges association and default scope conditions
Diffstat (limited to 'activerecord/test/cases/associations/eager_test.rb')
-rw-r--r--activerecord/test/cases/associations/eager_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index da4eeb3844..124bf65d3a 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -980,6 +980,18 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_equal posts(:welcome, :thinking), posts
end
+ def test_preload_has_many_with_association_condition_and_default_scope
+ post = Post.create!(:title => 'Beaches', :body => "I like beaches!")
+ Reader.create! :person => people(:david), :post => post
+ LazyReader.create! :person => people(:susan), :post => post
+
+ assert_equal 1, post.lazy_readers.to_a.size
+ assert_equal 2, post.lazy_readers_skimmers_or_not.to_a.size
+
+ post_with_readers = Post.includes(:lazy_readers_skimmers_or_not).find(post.id)
+ assert_equal 2, post_with_readers.lazy_readers_skimmers_or_not.to_a.size
+ end
+
def test_eager_loading_with_conditions_on_string_joined_table_preloads
posts = assert_queries(2) do
Post.all.merge!(:select => 'distinct posts.*', :includes => :author, :joins => "INNER JOIN comments on comments.post_id = posts.id", :where => "comments.body like 'Thank you%'", :order => 'posts.id').to_a