mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #8913 from seejee/regression_test_for_chained_preloaded_scopes
Added test case to prevent regression of chained, preloaded scopes.
This commit is contained in:
commit
2e8b3d5c9a
2 changed files with 10 additions and 0 deletions
|
@ -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')
|
||||
|
|
|
@ -35,6 +35,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
|
||||
|
|
Loading…
Reference in a new issue