1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

All test cases for exists? places in finder_test.rb to ease to find the test cases

This commit is contained in:
Ryuta Kamizono 2017-10-02 06:39:05 +09:00
parent 992572aecf
commit b1e7bb9ed7
2 changed files with 26 additions and 26 deletions

View file

@ -157,6 +157,32 @@ class FinderTest < ActiveRecord::TestCase
assert_raise(NoMethodError) { Topic.exists?([1, 2]) }
end
def test_exists_with_scope
davids = Author.where(name: "David")
assert_equal true, davids.exists?
assert_equal true, davids.exists?(authors(:david).id)
assert_equal false, davids.exists?(authors(:mary).id)
assert_equal false, davids.exists?("42")
assert_equal false, davids.exists?(42)
assert_equal false, davids.exists?(davids.new.id)
fake = Author.where(name: "fake author")
assert_equal false, fake.exists?
assert_equal false, fake.exists?(authors(:david).id)
end
def test_exists_uses_existing_scope
post = authors(:david).posts.first
authors = Author.includes(:posts).where(name: "David", posts: { id: post.id })
assert_equal true, authors.exists?(authors(:david).id)
end
def test_any_with_scope_on_hash_includes
post = authors(:david).posts.first
categories = Categorization.includes(author: :posts).where(posts: { id: post.id })
assert_equal true, categories.exists?
end
def test_exists_with_polymorphic_relation
post = Post.create!(title: "Post", body: "default", taggings: [Tagging.new(comment: "tagging comment")])
relation = Post.tagged_with_comment("tagging comment")

View file

@ -845,32 +845,6 @@ class RelationTest < ActiveRecord::TestCase
}
end
def test_exists
davids = Author.where(name: "David")
assert davids.exists?
assert davids.exists?(authors(:david).id)
assert ! davids.exists?(authors(:mary).id)
assert ! davids.exists?("42")
assert ! davids.exists?(42)
assert ! davids.exists?(davids.new.id)
fake = Author.where(name: "fake author")
assert ! fake.exists?
assert ! fake.exists?(authors(:david).id)
end
def test_exists_uses_existing_scope
post = authors(:david).posts.first
authors = Author.includes(:posts).where(name: "David", posts: { id: post.id })
assert authors.exists?(authors(:david).id)
end
def test_any_with_scope_on_hash_includes
post = authors(:david).posts.first
categories = Categorization.includes(author: :posts).where(posts: { id: post.id })
assert categories.exists?
end
def test_last
authors = Author.all
assert_equal authors(:bob), authors.last