Permalink
Browse files

test, regression test for has_many with instance dependent scope.

  • Loading branch information...
1 parent 28232ce commit f4511690994f0c14c60320bbeecc66549332dbee @senny senny committed May 8, 2014
@@ -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) }

0 comments on commit f451169

Please sign in to comment.