mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add tests for Relation#only.
This commit is contained in:
parent
33412b6e16
commit
e3246ef5b5
1 changed files with 11 additions and 0 deletions
|
@ -647,6 +647,17 @@ class RelationTest < ActiveRecord::TestCase
|
|||
assert_equal Post.all, all_posts.all
|
||||
end
|
||||
|
||||
def test_only
|
||||
relation = Post.where(:author_id => 1).order('id ASC').limit(1)
|
||||
assert_equal [posts(:welcome)], relation.all
|
||||
|
||||
author_posts = relation.only(:where)
|
||||
assert_equal Post.where(:author_id => 1).all, author_posts.all
|
||||
|
||||
all_posts = relation.only(:limit)
|
||||
assert_equal Post.limit(1).all.first, all_posts.first
|
||||
end
|
||||
|
||||
def test_anonymous_extension
|
||||
relation = Post.where(:author_id => 1).order('id ASC').extending do
|
||||
def author
|
||||
|
|
Loading…
Reference in a new issue