diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-26 12:39:44 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-26 12:39:44 +0530 |
commit | feb8b20eb552eee678448233672733c6e7ca9571 (patch) | |
tree | 9d211e4219c1107b4c74f0dac1f286a79be2900d | |
parent | a73fa9356feb82b739dd734b2b305f1f08f24337 (diff) | |
download | rails-feb8b20eb552eee678448233672733c6e7ca9571.tar.gz rails-feb8b20eb552eee678448233672733c6e7ca9571.tar.bz2 rails-feb8b20eb552eee678448233672733c6e7ca9571.zip |
Add Relation#all as an alias for to_a
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 5c0b8c6f83..9aa45fb294 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -51,6 +51,8 @@ module ActiveRecord records end + alias all to_a + def first @relation = @relation.take(1) to_a.first diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 06e040cd6d..529de4a6cf 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -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) |