From 7f6872e85bdc2364ed0f90fc9795c59c1deef103 Mon Sep 17 00:00:00 2001 From: Chris Geihsler Date: Sat, 12 Jan 2013 10:22:17 -0500 Subject: Added test case to prevent regression of chained, preloaded scopes. (#7490) --- activerecord/test/cases/relations_test.rb | 7 +++++++ activerecord/test/models/post.rb | 3 +++ 2 files changed, 10 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 3a499a2025..64f1c9f6cc 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -404,6 +404,13 @@ class RelationTest < ActiveRecord::TestCase end end + def test_preload_applies_to_all_chained_preloaded_scopes + assert_queries(3) do + post = Post.with_comments.with_tags.first + assert post + end + end + def test_find_with_included_associations assert_queries(2) do posts = Post.includes(:comments).order('posts.id') diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index c995f59a15..11ce345f7c 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -29,6 +29,9 @@ class Post < ActiveRecord::Base scope :with_very_special_comments, -> { joins(:comments).where(:comments => {:type => 'VerySpecialComment'}) } scope :with_post, ->(post_id) { joins(:comments).where(:comments => { :post_id => post_id }) } + scope :with_comments, -> { preload(:comments) } + scope :with_tags, -> { preload(:taggings) } + has_many :comments do def find_most_recent order("id DESC").first -- cgit v1.2.3