提交 f4511690 编写于 作者: Y Yves Senn

test, regression test for has_many with instance dependent scope.

上级 28232ce9
......@@ -1894,4 +1894,14 @@ def test_collection_association_with_private_kernel_method
assert_not pirate.valid?(:conference)
assert_equal "can't be blank", ship.errors[:name].first
end
test 'association with instance dependent scope' do
bob = authors(:bob)
Post.create!(title: "signed post by bob", body: "stuff", author: authors(:bob))
Post.create!(title: "anonymous post", body: "more stuff", author: authors(:bob))
assert_equal ["misc post by bob", "other post by bob",
"signed post by bob"], bob.posts_with_signature.map(&:title).sort
assert_equal [], authors(:david).posts_with_signature.map(&:title)
end
end
......@@ -140,6 +140,8 @@ def ratings
has_many :posts_with_default_include, :class_name => 'PostWithDefaultInclude'
has_many :comments_on_posts_with_default_include, :through => :posts_with_default_include, :source => :comments
has_many :posts_with_signature, -> (record) { where("posts.title LIKE ?", "%by #{record.name.downcase}%") }, class_name: "Post"
scope :relation_include_posts, -> { includes(:posts) }
scope :relation_include_tags, -> { includes(:tags) }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册