Add Relation#all as an alias for to_a

This commit is contained in:
Pratik Naik
2009-12-26 12:39:44 +05:30
parent a73fa9356f
commit feb8b20eb5
2 changed files with 8 additions and 0 deletions

View File

@@ -51,6 +51,8 @@ module ActiveRecord
records
end
alias all to_a
def first
@relation = @relation.take(1)
to_a.first

View File

@@ -18,6 +18,12 @@ class RelationTest < ActiveRecord::TestCase
assert_equal 4, topics.size
end
def test_scoped_all
topics = Topic.scoped.all
assert_kind_of Array, topics
assert_no_queries { assert_equal 4, topics.size }
end
def test_finding_with_conditions
assert_equal ["David"], Author.where(:name => 'David').map(&:name)
assert_equal ['Mary'], Author.where(["name = ?", 'Mary']).map(&:name)