Skip to content
This repository
Browse code

ActiveRecord::Base.all returns a Relation.

Previously it returned an Array.

If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This
is more explicit.

In most cases this should not break existing code, since
Relations use method_missing to delegate unknown methods to #to_a
anyway.
  • Loading branch information...
commit 6a81ccd69d96f36f4322ef927191ab5a35e68d68 1 parent f1afd77
Jon Leighton authored July 27, 2012

Showing 31 changed files with 329 additions and 324 deletions. Show diff stats Hide diff stats

  1. 2  activemodel/lib/active_model/observing.rb
  2. 14  activerecord/lib/active_record/querying.rb
  3. 19  activerecord/lib/active_record/scoping/named.rb
  4. 2  activerecord/test/cases/adapters/mysql/reserved_word_test.rb
  5. 2  activerecord/test/cases/adapters/mysql2/reserved_word_test.rb
  6. 2  activerecord/test/cases/associations/belongs_to_associations_test.rb
  7. 38  activerecord/test/cases/associations/cascaded_eager_loading_test.rb
  8. 2  activerecord/test/cases/associations/eager_load_nested_include_test.rb
  9. 14  activerecord/test/cases/associations/eager_singularization_test.rb
  10. 152  activerecord/test/cases/associations/eager_test.rb
  11. 14  activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
  12. 28  activerecord/test/cases/associations/has_many_associations_test.rb
  13. 4  activerecord/test/cases/associations/has_many_through_associations_test.rb
  14. 2  activerecord/test/cases/associations/has_one_associations_test.rb
  15. 14  activerecord/test/cases/associations/has_one_through_associations_test.rb
  16. 34  activerecord/test/cases/associations/join_model_test.rb
  17. 58  activerecord/test/cases/base_test.rb
  18. 2  activerecord/test/cases/batches_test.rb
  19. 2  activerecord/test/cases/calculations_test.rb
  20. 20  activerecord/test/cases/deprecated_dynamic_methods_test.rb
  21. 8  activerecord/test/cases/explain_test.rb
  22. 34  activerecord/test/cases/finder_test.rb
  23. 12  activerecord/test/cases/inheritance_test.rb
  24. 12  activerecord/test/cases/log_subscriber_test.rb
  25. 4  activerecord/test/cases/migration/rename_column_test.rb
  26. 56  activerecord/test/cases/named_scope_test.rb
  27. 2  activerecord/test/cases/persistence_test.rb
  28. 4  activerecord/test/cases/readonly_test.rb
  29. 46  activerecord/test/cases/relation_scoping_test.rb
  30. 48  activerecord/test/cases/relations_test.rb
  31. 2  activerecord/test/cases/xml_serialization_test.rb
2  activemodel/lib/active_model/observing.rb
@@ -215,7 +215,7 @@ def observe(*models)
215 215
       #     end
216 216
       #   end
217 217
       def observed_classes
218  
-        Array(observed_class)
  218
+        [observed_class].compact.flatten
219 219
       end
220 220
 
221 221
       # The class observed by default is inferred from the observer's class name:
14  activerecord/lib/active_record/querying.rb
@@ -3,15 +3,15 @@
3 3
 
4 4
 module ActiveRecord
5 5
   module Querying
6  
-    delegate :find, :take, :take!, :first, :first!, :last, :last!, :all, :exists?, :any?, :many?, :to => :scoped
7  
-    delegate :first_or_create, :first_or_create!, :first_or_initialize, :to => :scoped
8  
-    delegate :find_by, :find_by!, :to => :scoped
9  
-    delegate :destroy, :destroy_all, :delete, :delete_all, :update, :update_all, :to => :scoped
10  
-    delegate :find_each, :find_in_batches, :to => :scoped
  6
+    delegate :find, :take, :take!, :first, :first!, :last, :last!, :to_a, :exists?, :any?, :many?, :to => :all
  7
+    delegate :first_or_create, :first_or_create!, :first_or_initialize, :to => :all
  8
+    delegate :find_by, :find_by!, :to => :all
  9
+    delegate :destroy, :destroy_all, :delete, :delete_all, :update, :update_all, :to => :all
  10
+    delegate :find_each, :find_in_batches, :to => :all
11 11
     delegate :select, :group, :order, :except, :reorder, :limit, :offset, :joins,
12 12
              :where, :preload, :eager_load, :includes, :from, :lock, :readonly,
13  
-             :having, :create_with, :uniq, :references, :none, :to => :scoped
14  
-    delegate :count, :average, :minimum, :maximum, :sum, :calculate, :pluck, :ids, :to => :scoped
  13
+             :having, :create_with, :uniq, :references, :none, :to => :all
  14
+    delegate :count, :average, :minimum, :maximum, :sum, :calculate, :pluck, :ids, :to => :all
15 15
 
16 16
     # Executes a custom SQL query against your database and returns all the results. The results will
17 17
     # be returned as an array with columns requested encapsulated as attributes of the model you call
19  activerecord/lib/active_record/scoping/named.rb
@@ -12,33 +12,30 @@ module Named
12 12
       extend ActiveSupport::Concern
13 13
 
14 14
       module ClassMethods
15  
-        # Returns an anonymous \scope.
  15
+        # Returns an <tt>ActiveRecord::Relation</tt> scope object.
16 16
         #
17  
-        #   posts = Post.scoped
  17
+        #   posts = Post.all
18 18
         #   posts.size # Fires "select count(*) from  posts" and returns the count
19 19
         #   posts.each {|p| puts p.name } # Fires "select * from posts" and loads post objects
20 20
         #
21  
-        #   fruits = Fruit.scoped
  21
+        #   fruits = Fruit.all
22 22
         #   fruits = fruits.where(:color => 'red') if options[:red_only]
23 23
         #   fruits = fruits.limit(10) if limited?
24 24
         #
25  
-        # Anonymous \scopes tend to be useful when procedurally generating complex
26  
-        # queries, where passing intermediate values (\scopes) around as first-class
27  
-        # objects is convenient.
28  
-        #
29 25
         # You can define a \scope that applies to all finders using
30 26
         # ActiveRecord::Base.default_scope.
31  
-        def scoped(options = nil)
  27
+        def all
32 28
           if current_scope
33  
-            scope = current_scope.clone
  29
+            current_scope.clone
34 30
           else
35 31
             scope = relation
36 32
             scope.default_scoped = true
37 33
             scope
38 34
           end
  35
+        end
39 36
 
40  
-          scope.merge!(options) if options
41  
-          scope
  37
+        def scoped(options = nil)
  38
+          options ? all.merge!(options) : all
42 39
         end
43 40
 
44 41
         ##
2  activerecord/test/cases/adapters/mysql/reserved_word_test.rb
@@ -130,7 +130,7 @@ def test_calculations_work_with_reserved_words
130 130
   end
131 131
 
132 132
   def test_associations_work_with_reserved_words
133  
-    assert_nothing_raised { Select.scoped(:includes => [:groups]).all }
  133
+    assert_nothing_raised { Select.scoped(:includes => [:groups]).to_a }
134 134
   end
135 135
 
136 136
   #the following functions were added to DRY test cases
2  activerecord/test/cases/adapters/mysql2/reserved_word_test.rb
@@ -130,7 +130,7 @@ def test_calculations_work_with_reserved_words
130 130
   end
131 131
 
132 132
   def test_associations_work_with_reserved_words
133  
-    assert_nothing_raised { Select.scoped(:includes => [:groups]).all }
  133
+    assert_nothing_raised { Select.scoped(:includes => [:groups]).to_a }
134 134
   end
135 135
 
136 136
   #the following functions were added to DRY test cases
2  activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -396,7 +396,7 @@ def test_custom_counter_cache
396 396
   def test_association_assignment_sticks
397 397
     post = Post.first
398 398
 
399  
-    author1, author2 = Author.scoped(:limit => 2).all
  399
+    author1, author2 = Author.scoped(:limit => 2).to_a
400 400
     assert_not_nil author1
401 401
     assert_not_nil author2
402 402
 
38  activerecord/test/cases/associations/cascaded_eager_loading_test.rb
@@ -16,7 +16,7 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
16 16
            :categorizations, :people, :categories, :edges, :vertices
17 17
 
18 18
   def test_eager_association_loading_with_cascaded_two_levels
19  
-    authors = Author.scoped(:includes=>{:posts=>:comments}, :order=>"authors.id").all
  19
+    authors = Author.scoped(:includes=>{:posts=>:comments}, :order=>"authors.id").to_a
20 20
     assert_equal 3, authors.size
21 21
     assert_equal 5, authors[0].posts.size
22 22
     assert_equal 3, authors[1].posts.size
@@ -24,7 +24,7 @@ def test_eager_association_loading_with_cascaded_two_levels
24 24
   end
25 25
 
26 26
   def test_eager_association_loading_with_cascaded_two_levels_and_one_level
27  
-    authors = Author.scoped(:includes=>[{:posts=>:comments}, :categorizations], :order=>"authors.id").all
  27
+    authors = Author.scoped(:includes=>[{:posts=>:comments}, :categorizations], :order=>"authors.id").to_a
28 28
     assert_equal 3, authors.size
29 29
     assert_equal 5, authors[0].posts.size
30 30
     assert_equal 3, authors[1].posts.size
@@ -35,16 +35,16 @@ def test_eager_association_loading_with_cascaded_two_levels_and_one_level
35 35
 
36 36
   def test_eager_association_loading_with_hmt_does_not_table_name_collide_when_joining_associations
37 37
     assert_nothing_raised do
38  
-      Author.joins(:posts).eager_load(:comments).where(:posts => {:taggings_count => 1}).all
  38
+      Author.joins(:posts).eager_load(:comments).where(:posts => {:taggings_count => 1}).to_a
39 39
     end
40  
-    authors = Author.joins(:posts).eager_load(:comments).where(:posts => {:taggings_count => 1}).all
  40
+    authors = Author.joins(:posts).eager_load(:comments).where(:posts => {:taggings_count => 1}).to_a
41 41
     assert_equal 1, assert_no_queries { authors.size }
42 42
     assert_equal 10, assert_no_queries { authors[0].comments.size }
43 43
   end
44 44
 
45 45
   def test_eager_association_loading_grafts_stashed_associations_to_correct_parent
46 46
     assert_nothing_raised do
47  
-      Person.eager_load(:primary_contact => :primary_contact).where('primary_contacts_people_2.first_name = ?', 'Susan').order('people.id').all
  47
+      Person.eager_load(:primary_contact => :primary_contact).where('primary_contacts_people_2.first_name = ?', 'Susan').order('people.id').to_a
48 48
     end
49 49
     assert_equal people(:michael), Person.eager_load(:primary_contact => :primary_contact).where('primary_contacts_people_2.first_name = ?', 'Susan').order('people.id').first
50 50
   end
@@ -54,9 +54,9 @@ def test_cascaded_eager_association_loading_with_join_for_count
54 54
 
55 55
     assert_nothing_raised do
56 56
       assert_equal 4, categories.count
57  
-      assert_equal 4, categories.all.count
  57
+      assert_equal 4, categories.to_a.count
58 58
       assert_equal 3, categories.count(:distinct => true)
59  
-      assert_equal 3, categories.all.uniq.size # Must uniq since instantiating with inner joins will get dupes
  59
+      assert_equal 3, categories.to_a.uniq.size # Must uniq since instantiating with inner joins will get dupes
60 60
     end
61 61
   end
62 62
 
@@ -64,7 +64,7 @@ def test_cascaded_eager_association_loading_with_duplicated_includes
64 64
     categories = Category.includes(:categorizations).includes(:categorizations => :author).where("categorizations.id is not null").references(:categorizations)
65 65
     assert_nothing_raised do
66 66
       assert_equal 3, categories.count
67  
-      assert_equal 3, categories.all.size
  67
+      assert_equal 3, categories.to_a.size
68 68
     end
69 69
   end
70 70
 
@@ -72,7 +72,7 @@ def test_cascaded_eager_association_loading_with_twice_includes_edge_cases
72 72
     categories = Category.includes(:categorizations => :author).includes(:categorizations => :post).where("posts.id is not null").references(:posts)
73 73
     assert_nothing_raised do
74 74
       assert_equal 3, categories.count
75  
-      assert_equal 3, categories.all.size
  75
+      assert_equal 3, categories.to_a.size
76 76
     end
77 77
   end
78 78
 
@@ -80,11 +80,11 @@ def test_eager_association_loading_with_join_for_count
80 80
     authors = Author.joins(:special_posts).includes([:posts, :categorizations])
81 81
 
82 82
     assert_nothing_raised { authors.count }
83  
-    assert_queries(3) { authors.all }
  83
+    assert_queries(3) { authors.to_a }
84 84
   end
85 85
 
86 86
   def test_eager_association_loading_with_cascaded_two_levels_with_two_has_many_associations
87  
-    authors = Author.scoped(:includes=>{:posts=>[:comments, :categorizations]}, :order=>"authors.id").all
  87
+    authors = Author.scoped(:includes=>{:posts=>[:comments, :categorizations]}, :order=>"authors.id").to_a
88 88
     assert_equal 3, authors.size
89 89
     assert_equal 5, authors[0].posts.size
90 90
     assert_equal 3, authors[1].posts.size
@@ -92,7 +92,7 @@ def test_eager_association_loading_with_cascaded_two_levels_with_two_has_many_as
92 92
   end
93 93
 
94 94
   def test_eager_association_loading_with_cascaded_two_levels_and_self_table_reference
95  
-    authors = Author.scoped(:includes=>{:posts=>[:comments, :author]}, :order=>"authors.id").all
  95
+    authors = Author.scoped(:includes=>{:posts=>[:comments, :author]}, :order=>"authors.id").to_a
96 96
     assert_equal 3, authors.size
97 97
     assert_equal 5, authors[0].posts.size
98 98
     assert_equal authors(:david).name, authors[0].name
@@ -100,13 +100,13 @@ def test_eager_association_loading_with_cascaded_two_levels_and_self_table_refer
100 100
   end
101 101
 
102 102
   def test_eager_association_loading_with_cascaded_two_levels_with_condition
103  
-    authors = Author.scoped(:includes=>{:posts=>:comments}, :where=>"authors.id=1", :order=>"authors.id").all
  103
+    authors = Author.scoped(:includes=>{:posts=>:comments}, :where=>"authors.id=1", :order=>"authors.id").to_a
104 104
     assert_equal 1, authors.size
105 105
     assert_equal 5, authors[0].posts.size
106 106
   end
107 107
 
108 108
   def test_eager_association_loading_with_cascaded_three_levels_by_ping_pong
109  
-    firms = Firm.scoped(:includes=>{:account=>{:firm=>:account}}, :order=>"companies.id").all
  109
+    firms = Firm.scoped(:includes=>{:account=>{:firm=>:account}}, :order=>"companies.id").to_a
110 110
     assert_equal 2, firms.size
111 111
     assert_equal firms.first.account, firms.first.account.firm.account
112 112
     assert_equal companies(:first_firm).account, assert_no_queries { firms.first.account.firm.account }
@@ -114,7 +114,7 @@ def test_eager_association_loading_with_cascaded_three_levels_by_ping_pong
114 114
   end
115 115
 
116 116
   def test_eager_association_loading_with_has_many_sti
117  
-    topics = Topic.scoped(:includes => :replies, :order => 'topics.id').all
  117
+    topics = Topic.scoped(:includes => :replies, :order => 'topics.id').to_a
118 118
     first, second, = topics(:first).replies.size, topics(:second).replies.size
119 119
     assert_no_queries do
120 120
       assert_equal first, topics[0].replies.size
@@ -127,7 +127,7 @@ def test_eager_association_loading_with_has_many_sti_and_subclasses
127 127
     silly.parent_id = 1
128 128
     assert silly.save
129 129
 
130  
-    topics = Topic.scoped(:includes => :replies, :order => ['topics.id', 'replies_topics.id']).all
  130
+    topics = Topic.scoped(:includes => :replies, :order => ['topics.id', 'replies_topics.id']).to_a
131 131
     assert_no_queries do
132 132
       assert_equal 2, topics[0].replies.size
133 133
       assert_equal 0, topics[1].replies.size
@@ -135,7 +135,7 @@ def test_eager_association_loading_with_has_many_sti_and_subclasses
135 135
   end
136 136
 
137 137
   def test_eager_association_loading_with_belongs_to_sti
138  
-    replies = Reply.scoped(:includes => :topic, :order => 'topics.id').all
  138
+    replies = Reply.scoped(:includes => :topic, :order => 'topics.id').to_a
139 139
     assert replies.include?(topics(:second))
140 140
     assert !replies.include?(topics(:first))
141 141
     assert_equal topics(:first), assert_no_queries { replies.first.topic }
@@ -151,7 +151,7 @@ def test_eager_association_loading_with_multiple_stis_and_order
151 151
   end
152 152
 
153 153
   def test_eager_association_loading_of_stis_with_multiple_references
154  
-    authors = Author.scoped(:includes => { :posts => { :special_comments => { :post => [ :special_comments, :very_special_comment ] } } }, :order => 'comments.body, very_special_comments_posts.body', :where => 'posts.id = 4').all
  154
+    authors = Author.scoped(:includes => { :posts => { :special_comments => { :post => [ :special_comments, :very_special_comment ] } } }, :order => 'comments.body, very_special_comments_posts.body', :where => 'posts.id = 4').to_a
155 155
     assert_equal [authors(:david)], authors
156 156
     assert_no_queries do
157 157
       authors.first.posts.first.special_comments.first.post.special_comments
@@ -160,7 +160,7 @@ def test_eager_association_loading_of_stis_with_multiple_references
160 160
   end
161 161
 
162 162
   def test_eager_association_loading_where_first_level_returns_nil
163  
-    authors = Author.scoped(:includes => {:post_about_thinking => :comments}, :order => 'authors.id DESC').all
  163
+    authors = Author.scoped(:includes => {:post_about_thinking => :comments}, :order => 'authors.id DESC').to_a
164 164
     assert_equal [authors(:bob), authors(:mary), authors(:david)], authors
165 165
     assert_no_queries do
166 166
       authors[2].post_about_thinking.comments.first
2  activerecord/test/cases/associations/eager_load_nested_include_test.rb
@@ -92,7 +92,7 @@ def generate_test_object_graphs
92 92
   end
93 93
 
94 94
   def test_include_query
95  
-    res = ShapeExpression.scoped(:includes => [ :shape, { :paint => :non_poly } ]).all
  95
+    res = ShapeExpression.scoped(:includes => [ :shape, { :paint => :non_poly } ]).to_a
96 96
     assert_equal NUM_SHAPE_EXPRESSIONS, res.size
97 97
     assert_queries(0) do
98 98
       res.each do |se|
14  activerecord/test/cases/associations/eager_singularization_test.rb
@@ -103,43 +103,43 @@ def teardown
103 103
   def test_eager_no_extra_singularization_belongs_to
104 104
     return unless @have_tables
105 105
     assert_nothing_raised do
106  
-      Virus.scoped(:includes => :octopus).all
  106
+      Virus.scoped(:includes => :octopus).to_a
107 107
     end
108 108
   end
109 109
 
110 110
   def test_eager_no_extra_singularization_has_one
111 111
     return unless @have_tables
112 112
     assert_nothing_raised do
113  
-      Octopus.scoped(:includes => :virus).all
  113
+      Octopus.scoped(:includes => :virus).to_a
114 114
     end
115 115
   end
116 116
 
117 117
   def test_eager_no_extra_singularization_has_many
118 118
     return unless @have_tables
119 119
     assert_nothing_raised do
120  
-      Bus.scoped(:includes => :passes).all
  120
+      Bus.scoped(:includes => :passes).to_a
121 121
     end
122 122
   end
123 123
 
124 124
   def test_eager_no_extra_singularization_has_and_belongs_to_many
125 125
     return unless @have_tables
126 126
     assert_nothing_raised do
127  
-      Crisis.scoped(:includes => :messes).all
128  
-      Mess.scoped(:includes => :crises).all
  127
+      Crisis.scoped(:includes => :messes).to_a
  128
+      Mess.scoped(:includes => :crises).to_a
129 129
     end
130 130
   end
131 131
 
132 132
   def test_eager_no_extra_singularization_has_many_through_belongs_to
133 133
     return unless @have_tables
134 134
     assert_nothing_raised do
135  
-      Crisis.scoped(:includes => :successes).all
  135
+      Crisis.scoped(:includes => :successes).to_a
136 136
     end
137 137
   end
138 138
 
139 139
   def test_eager_no_extra_singularization_has_many_through_has_many
140 140
     return unless @have_tables
141 141
     assert_nothing_raised do
142  
-      Crisis.scoped(:includes => :compresses).all
  142
+      Crisis.scoped(:includes => :compresses).to_a
143 143
     end
144 144
   end
145 145
 end
152  activerecord/test/cases/associations/eager_test.rb
@@ -35,7 +35,7 @@ def test_eager_with_has_one_through_join_model_with_conditions_on_the_through
35 35
   end
36 36
 
37 37
   def test_loading_with_one_association
38  
-    posts = Post.scoped(:includes => :comments).all
  38
+    posts = Post.scoped(:includes => :comments).to_a
39 39
     post = posts.find { |p| p.id == 1 }
40 40
     assert_equal 2, post.comments.size
41 41
     assert post.comments.include?(comments(:greetings))
@@ -44,13 +44,13 @@ def test_loading_with_one_association
44 44
     assert_equal 2, post.comments.size
45 45
     assert post.comments.include?(comments(:greetings))
46 46
 
47  
-    posts = Post.scoped(:includes => :last_comment).all
  47
+    posts = Post.scoped(:includes => :last_comment).to_a
48 48
     post = posts.find { |p| p.id == 1 }
49 49
     assert_equal Post.find(1).last_comment, post.last_comment
50 50
   end
51 51
 
52 52
   def test_loading_with_one_association_with_non_preload
53  
-    posts = Post.scoped(:includes => :last_comment, :order => 'comments.id DESC').all
  53
+    posts = Post.scoped(:includes => :last_comment, :order => 'comments.id DESC').to_a
54 54
     post = posts.find { |p| p.id == 1 }
55 55
     assert_equal Post.find(1).last_comment, post.last_comment
56 56
   end
@@ -59,13 +59,13 @@ def test_loading_conditions_with_or
59 59
     posts = authors(:david).posts.references(:comments).scoped(
60 60
       :includes => :comments,
61 61
       :where => "comments.body like 'Normal%' OR comments.#{QUOTED_TYPE} = 'SpecialComment'"
62  
-    ).all
  62
+    ).to_a
63 63
     assert_nil posts.detect { |p| p.author_id != authors(:david).id },
64 64
       "expected to find only david's posts"
65 65
   end
66 66
 
67 67
   def test_with_ordering
68  
-    list = Post.scoped(:includes => :comments, :order => "posts.id DESC").all
  68
+    list = Post.scoped(:includes => :comments, :order => "posts.id DESC").to_a
69 69
     [:other_by_mary, :other_by_bob, :misc_by_mary, :misc_by_bob, :eager_other,
70 70
      :sti_habtm, :sti_post_and_comments, :sti_comments, :authorless, :thinking, :welcome
71 71
     ].each_with_index do |post, index|
@@ -79,14 +79,14 @@ def test_with_two_tables_in_from_without_getting_double_quoted
79 79
   end
80 80
 
81 81
   def test_loading_with_multiple_associations
82  
-    posts = Post.scoped(:includes => [ :comments, :author, :categories ], :order => "posts.id").all
  82
+    posts = Post.scoped(:includes => [ :comments, :author, :categories ], :order => "posts.id").to_a
83 83
     assert_equal 2, posts.first.comments.size
84 84
     assert_equal 2, posts.first.categories.size
85 85
     assert posts.first.comments.include?(comments(:greetings))
86 86
   end
87 87
 
88 88
   def test_duplicate_middle_objects
89  
-    comments = Comment.scoped(:where => 'post_id = 1', :includes => [:post => :author]).all
  89
+    comments = Comment.scoped(:where => 'post_id = 1', :includes => [:post => :author]).to_a
90 90
     assert_no_queries do
91 91
       comments.each {|comment| comment.post.author.name}
92 92
     end
@@ -94,25 +94,25 @@ def test_duplicate_middle_objects
94 94
 
95 95
   def test_preloading_has_many_in_multiple_queries_with_more_ids_than_database_can_handle
96 96
     Post.connection.expects(:in_clause_length).at_least_once.returns(5)
97  
-    posts = Post.scoped(:includes=>:comments).all
  97
+    posts = Post.scoped(:includes=>:comments).to_a
98 98
     assert_equal 11, posts.size
99 99
   end
100 100
 
101 101
   def test_preloading_has_many_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle
102 102
     Post.connection.expects(:in_clause_length).at_least_once.returns(nil)
103  
-    posts = Post.scoped(:includes=>:comments).all
  103
+    posts = Post.scoped(:includes=>:comments).to_a
104 104
     assert_equal 11, posts.size
105 105
   end
106 106
 
107 107
   def test_preloading_habtm_in_multiple_queries_with_more_ids_than_database_can_handle
108 108
     Post.connection.expects(:in_clause_length).at_least_once.returns(5)
109  
-    posts = Post.scoped(:includes=>:categories).all
  109
+    posts = Post.scoped(:includes=>:categories).to_a
110 110
     assert_equal 11, posts.size
111 111
   end
112 112
 
113 113
   def test_preloading_habtm_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle
114 114
     Post.connection.expects(:in_clause_length).at_least_once.returns(nil)
115  
-    posts = Post.scoped(:includes=>:categories).all
  115
+    posts = Post.scoped(:includes=>:categories).to_a
116 116
     assert_equal 11, posts.size
117 117
   end
118 118
 
@@ -150,7 +150,7 @@ def test_including_duplicate_objects_from_belongs_to
150 150
     popular_post.readers.create!(:person => people(:david))
151 151
 
152 152
     readers = Reader.scoped(:where => ["post_id = ?", popular_post.id],
153  
-                                :includes => {:post => :comments}).all
  153
+                                :includes => {:post => :comments}).to_a
154 154
     readers.each do |reader|
155 155
       assert_equal [comment], reader.post.comments
156 156
     end
@@ -163,7 +163,7 @@ def test_including_duplicate_objects_from_has_many
163 163
 
164 164
     comment = car_post.comments.create!(:body => "hmm")
165 165
     categories = Category.scoped(:where => { 'posts.id' => car_post.id },
166  
-                                 :includes => {:posts => :comments}).all
  166
+                                 :includes => {:posts => :comments}).to_a
167 167
     categories.each do |category|
168 168
       assert_equal [comment], category.posts[0].comments
169 169
     end
@@ -229,13 +229,13 @@ def test_finding_with_includes_on_null_belongs_to_polymorphic_association
229 229
   end
230 230
 
231 231
   def test_loading_from_an_association
232  
-    posts = authors(:david).posts.scoped(:includes => :comments, :order => "posts.id").all
  232
+    posts = authors(:david).posts.scoped(:includes => :comments, :order => "posts.id").to_a
233 233
     assert_equal 2, posts.first.comments.size
234 234
   end
235 235
 
236 236
   def test_loading_from_an_association_that_has_a_hash_of_conditions
237 237
     assert_nothing_raised do
238  
-      Author.scoped(:includes => :hello_posts_with_hash_conditions).all
  238
+      Author.scoped(:includes => :hello_posts_with_hash_conditions).to_a
239 239
     end
240 240
     assert !Author.scoped(:includes => :hello_posts_with_hash_conditions).find(authors(:david).id).hello_posts.empty?
241 241
   end
@@ -295,12 +295,12 @@ def test_nested_loading_through_has_one_association_with_conditions_on_nested_as
295 295
   end
296 296
 
297 297
   def test_eager_association_loading_with_belongs_to_and_foreign_keys
298  
-    pets = Pet.scoped(:includes => :owner).all
  298
+    pets = Pet.scoped(:includes => :owner).to_a
299 299
     assert_equal 3, pets.length
300 300
   end
301 301
 
302 302
   def test_eager_association_loading_with_belongs_to
303  
-    comments = Comment.scoped(:includes => :post).all
  303
+    comments = Comment.scoped(:includes => :post).to_a
304 304
     assert_equal 11, comments.length
305 305
     titles = comments.map { |c| c.post.title }
306 306
     assert titles.include?(posts(:welcome).title)
@@ -308,31 +308,31 @@ def test_eager_association_loading_with_belongs_to
308 308
   end
309 309
 
310 310
   def test_eager_association_loading_with_belongs_to_and_limit
311  
-    comments = Comment.scoped(:includes => :post, :limit => 5, :order => 'comments.id').all
  311
+    comments = Comment.scoped(:includes => :post, :limit => 5, :order => 'comments.id').to_a
312 312
     assert_equal 5, comments.length
313 313
     assert_equal [1,2,3,5,6], comments.collect { |c| c.id }
314 314
   end
315 315
 
316 316
   def test_eager_association_loading_with_belongs_to_and_limit_and_conditions
317  
-    comments = Comment.scoped(:includes => :post, :where => 'post_id = 4', :limit => 3, :order => 'comments.id').all
  317
+    comments = Comment.scoped(:includes => :post, :where => 'post_id = 4', :limit => 3, :order => 'comments.id').to_a
318 318
     assert_equal 3, comments.length
319 319
     assert_equal [5,6,7], comments.collect { |c| c.id }
320 320
   end
321 321
 
322 322
   def test_eager_association_loading_with_belongs_to_and_limit_and_offset
323  
-    comments = Comment.scoped(:includes => :post, :limit => 3, :offset => 2, :order => 'comments.id').all
  323
+    comments = Comment.scoped(:includes => :post, :limit => 3, :offset => 2, :order => 'comments.id').to_a
324 324
     assert_equal 3, comments.length
325 325
     assert_equal [3,5,6], comments.collect { |c| c.id }
326 326
   end
327 327
 
328 328
   def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_conditions
329  
-    comments = Comment.scoped(:includes => :post, :where => 'post_id = 4', :limit => 3, :offset => 1, :order => 'comments.id').all
  329
+    comments = Comment.scoped(:includes => :post, :where => 'post_id = 4', :limit => 3, :offset => 1, :order => 'comments.id').to_a
330 330
     assert_equal 3, comments.length
331 331
     assert_equal [6,7,8], comments.collect { |c| c.id }
332 332
   end
333 333
 
334 334
   def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_conditions_array
335  
-    comments = Comment.scoped(:includes => :post, :where => ['post_id = ?',4], :limit => 3, :offset => 1, :order => 'comments.id').all
  335
+    comments = Comment.scoped(:includes => :post, :where => ['post_id = ?',4], :limit => 3, :offset => 1, :order => 'comments.id').to_a
336 336
     assert_equal 3, comments.length
337 337
     assert_equal [6,7,8], comments.collect { |c| c.id }
338 338
   end
@@ -340,7 +340,7 @@ def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_cond
340 340
   def test_eager_association_loading_with_belongs_to_and_conditions_string_with_unquoted_table_name
341 341
     assert_nothing_raised do
342 342
       ActiveSupport::Deprecation.silence do
343  
-        Comment.scoped(:includes => :post, :where => ['posts.id = ?',4]).all
  343
+        Comment.scoped(:includes => :post, :where => ['posts.id = ?',4]).to_a
344 344
       end
345 345
     end
346 346
   end
@@ -348,7 +348,7 @@ def test_eager_association_loading_with_belongs_to_and_conditions_string_with_un
348 348
   def test_eager_association_loading_with_belongs_to_and_conditions_hash
349 349
     comments = []
350 350
     assert_nothing_raised do
351  
-      comments = Comment.scoped(:includes => :post, :where => {:posts => {:id => 4}}, :limit => 3, :order => 'comments.id').all
  351
+      comments = Comment.scoped(:includes => :post, :where => {:posts => {:id => 4}}, :limit => 3, :order => 'comments.id').to_a
352 352
     end
353 353
     assert_equal 3, comments.length
354 354
     assert_equal [5,6,7], comments.collect { |c| c.id }
@@ -361,14 +361,14 @@ def test_eager_association_loading_with_belongs_to_and_conditions_string_with_qu
361 361
     quoted_posts_id= Comment.connection.quote_table_name('posts') + '.' + Comment.connection.quote_column_name('id')
362 362
     assert_nothing_raised do
363 363
       ActiveSupport::Deprecation.silence do
364  
-        Comment.scoped(:includes => :post, :where => ["#{quoted_posts_id} = ?",4]).all
  364
+        Comment.scoped(:includes => :post, :where => ["#{quoted_posts_id} = ?",4]).to_a
365 365
       end
366 366
     end
367 367
   end
368 368
 
369 369
   def test_eager_association_loading_with_belongs_to_and_order_string_with_unquoted_table_name
370 370
     assert_nothing_raised do
371  
-      Comment.scoped(:includes => :post, :order => 'posts.id').all
  371
+      Comment.scoped(:includes => :post, :order => 'posts.id').to_a
372 372
     end
373 373
   end
374 374
 
@@ -376,19 +376,19 @@ def test_eager_association_loading_with_belongs_to_and_order_string_with_quoted_
376 376
     quoted_posts_id= Comment.connection.quote_table_name('posts') + '.' + Comment.connection.quote_column_name('id')
377 377
     assert_nothing_raised do
378 378
       ActiveSupport::Deprecation.silence do
379  
-        Comment.scoped(:includes => :post, :order => quoted_posts_id).all
  379
+        Comment.scoped(:includes => :post, :order => quoted_posts_id).to_a
380 380
       end
381 381
     end
382 382
   end
383 383
 
384 384
   def test_eager_association_loading_with_belongs_to_and_limit_and_multiple_associations
385  
-    posts = Post.scoped(:includes => [:author, :very_special_comment], :limit => 1, :order => 'posts.id').all
  385
+    posts = Post.scoped(:includes => [:author, :very_special_comment], :limit => 1, :order => 'posts.id').to_a
386 386
     assert_equal 1, posts.length
387 387
     assert_equal [1], posts.collect { |p| p.id }
388 388
   end
389 389
 
390 390
   def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_multiple_associations
391  
-    posts = Post.scoped(:includes => [:author, :very_special_comment], :limit => 1, :offset => 1, :order => 'posts.id').all
  391
+    posts = Post.scoped(:includes => [:author, :very_special_comment], :limit => 1, :offset => 1, :order => 'posts.id').to_a
392 392
     assert_equal 1, posts.length
393 393
     assert_equal [2], posts.collect { |p| p.id }
394 394
   end
@@ -453,14 +453,14 @@ def test_eager_load_belongs_to_with_string_keys
453 453
   end
454 454
 
455 455
   def test_eager_association_loading_with_explicit_join
456  
-    posts = Post.scoped(:includes => :comments, :joins => "INNER JOIN authors ON posts.author_id = authors.id AND authors.name = 'Mary'", :limit => 1, :order => 'author_id').all
  456
+    posts = Post.scoped(:includes => :comments, :joins => "INNER JOIN authors ON posts.author_id = authors.id AND authors.name = 'Mary'", :limit => 1, :order => 'author_id').to_a
457 457
     assert_equal 1, posts.length
458 458
   end
459 459
 
460 460
   def test_eager_with_has_many_through
461  
-    posts_with_comments = people(:michael).posts.scoped(:includes => :comments, :order => 'posts.id').all
462  
-    posts_with_author = people(:michael).posts.scoped(:includes => :author, :order => 'posts.id').all
463  
-    posts_with_comments_and_author = people(:michael).posts.scoped(:includes => [ :comments, :author ], :order => 'posts.id').all
  461
+    posts_with_comments = people(:michael).posts.scoped(:includes => :comments, :order => 'posts.id').to_a
  462
+    posts_with_author = people(:michael).posts.scoped(:includes => :author, :order => 'posts.id').to_a
  463
+    posts_with_comments_and_author = people(:michael).posts.scoped(:includes => [ :comments, :author ], :order => 'posts.id').to_a
464 464
     assert_equal 2, posts_with_comments.inject(0) { |sum, post| sum += post.comments.size }
465 465
     assert_equal authors(:david), assert_no_queries { posts_with_author.first.author }
466 466
     assert_equal authors(:david), assert_no_queries { posts_with_comments_and_author.first.author }
@@ -471,7 +471,7 @@ def test_eager_with_has_many_through_a_belongs_to_association
471 471
     Post.create!(:author => author, :title => "TITLE", :body => "BODY")
472 472
     author.author_favorites.create(:favorite_author_id => 1)
473 473
     author.author_favorites.create(:favorite_author_id => 2)
474  
-    posts_with_author_favorites = author.posts.scoped(:includes => :author_favorites).all
  474
+    posts_with_author_favorites = author.posts.scoped(:includes => :author_favorites).to_a
475 475
     assert_no_queries { posts_with_author_favorites.first.author_favorites.first.author_id }
476 476
   end
477 477
 
@@ -515,16 +515,16 @@ def test_eager_with_has_many_through_join_model_ignores_default_includes
515 515
   end
516 516
 
517 517
   def test_eager_with_has_many_and_limit
518  
-    posts = Post.scoped(:order => 'posts.id asc', :includes => [ :author, :comments ], :limit => 2).all
  518
+    posts = Post.scoped(:order => 'posts.id asc', :includes => [ :author, :comments ], :limit => 2).to_a
519 519
     assert_equal 2, posts.size
520 520
     assert_equal 3, posts.inject(0) { |sum, post| sum += post.comments.size }
521 521
   end
522 522
 
523 523
   def test_eager_with_has_many_and_limit_and_conditions
524 524
     if current_adapter?(:OpenBaseAdapter)
525  
-      posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => "FETCHBLOB(posts.body) = 'hello'", :order => "posts.id").all
  525
+      posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => "FETCHBLOB(posts.body) = 'hello'", :order => "posts.id").to_a
526 526
     else
527  
-      posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => "posts.body = 'hello'", :order => "posts.id").all
  527
+      posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => "posts.body = 'hello'", :order => "posts.id").to_a
528 528
     end
529 529
     assert_equal 2, posts.size
530 530
     assert_equal [4,5], posts.collect { |p| p.id }
@@ -532,9 +532,9 @@ def test_eager_with_has_many_and_limit_and_conditions
532 532
 
533 533
   def test_eager_with_has_many_and_limit_and_conditions_array
534 534
     if current_adapter?(:OpenBaseAdapter)
535  
-      posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => [ "FETCHBLOB(posts.body) = ?", 'hello' ], :order => "posts.id").all
  535
+      posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => [ "FETCHBLOB(posts.body) = ?", 'hello' ], :order => "posts.id").to_a
536 536
     else
537  
-      posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => [ "posts.body = ?", 'hello' ], :order => "posts.id").all
  537
+      posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => [ "posts.body = ?", 'hello' ], :order => "posts.id").to_a
538 538
     end
539 539
     assert_equal 2, posts.size
540 540
     assert_equal [4,5], posts.collect { |p| p.id }
@@ -542,7 +542,7 @@ def test_eager_with_has_many_and_limit_and_conditions_array
542 542
 
543 543
   def test_eager_with_has_many_and_limit_and_conditions_array_on_the_eagers
544 544
     posts = ActiveSupport::Deprecation.silence do
545  
-      Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => [ "authors.name = ?", 'David' ]).all
  545
+      Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => [ "authors.name = ?", 'David' ]).to_a
546 546
     end
547 547
     assert_equal 2, posts.size
548 548
 
@@ -553,7 +553,7 @@ def test_eager_with_has_many_and_limit_and_conditions_array_on_the_eagers
553 553
   end
554 554
 
555 555
   def test_eager_with_has_many_and_limit_and_high_offset
556  
-    posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :offset => 10, :where => { 'authors.name' => 'David' }).all
  556
+    posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :offset => 10, :where => { 'authors.name' => 'David' }).to_a
557 557
     assert_equal 0, posts.size
558 558
   end
559 559
 
@@ -561,7 +561,7 @@ def test_eager_with_has_many_and_limit_and_high_offset_and_multiple_array_condit
561 561
     assert_queries(1) do
562 562
       posts = Post.references(:authors, :comments).
563 563
         scoped(:includes => [ :author, :comments ], :limit => 2, :offset => 10,
564  
-          :where => [ "authors.name = ? and comments.body = ?", 'David', 'go crazy' ]).all
  564
+          :where => [ "authors.name = ? and comments.body = ?", 'David', 'go crazy' ]).to_a
565 565
       assert_equal 0, posts.size
566 566
     end
567 567
   end
@@ -569,7 +569,7 @@ def test_eager_with_has_many_and_limit_and_high_offset_and_multiple_array_condit
569 569
   def test_eager_with_has_many_and_limit_and_high_offset_and_multiple_hash_conditions
570 570
     assert_queries(1) do
571 571
       posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :offset => 10,
572  
-        :where => { 'authors.name' => 'David', 'comments.body' => 'go crazy' }).all
  572
+        :where => { 'authors.name' => 'David', 'comments.body' => 'go crazy' }).to_a
573 573
       assert_equal 0, posts.size
574 574
     end
575 575
   end
@@ -580,7 +580,7 @@ def test_count_eager_with_has_many_and_limit_and_high_offset
580 580
   end
581 581
 
582 582
   def test_eager_with_has_many_and_limit_with_no_results
583  
-    posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => "posts.title = 'magic forest'").all
  583
+    posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => "posts.title = 'magic forest'").to_a
584 584
     assert_equal 0, posts.size
585 585
   end
586 586
 
@@ -597,7 +597,7 @@ def test_eager_count_performed_on_a_has_many_through_association_with_multi_tabl
597 597
   end
598 598
 
599 599
   def test_eager_with_has_and_belongs_to_many_and_limit
600  
-    posts = Post.scoped(:includes => :categories, :order => "posts.id", :limit => 3).all
  600
+    posts = Post.scoped(:includes => :categories, :order => "posts.id", :limit => 3).to_a
601 601
     assert_equal 3, posts.size
602 602
     assert_equal 2, posts[0].categories.size
603 603
     assert_equal 1, posts[1].categories.size
@@ -663,7 +663,7 @@ def test_eager_with_has_many_and_limit_and_scoped_conditions_on_the_eagers
663 663
   end
664 664
 
665 665
   def test_eager_association_loading_with_habtm
666  
-    posts = Post.scoped(:includes => :categories, :order => "posts.id").all
  666
+    posts = Post.scoped(:includes => :categories, :order => "posts.id").to_a
667 667
     assert_equal 2, posts[0].categories.size
668 668
     assert_equal 1, posts[1].categories.size
669 669
     assert_equal 0, posts[2].categories.size
@@ -672,7 +672,7 @@ def test_eager_association_loading_with_habtm
672 672
   end
673 673
 
674 674
   def test_eager_with_inheritance
675  
-    SpecialPost.scoped(:includes => [ :comments ]).all
  675
+    SpecialPost.scoped(:includes => [ :comments ]).to_a
676 676
   end
677 677
 
678 678
   def test_eager_has_one_with_association_inheritance
@@ -727,7 +727,7 @@ def test_eager_with_invalid_association_reference
727 727
 
728 728
   def test_eager_with_default_scope
729 729
     developer = EagerDeveloperWithDefaultScope.where(:name => 'David').first
730  
-    projects = Project.order(:id).all
  730
+    projects = Project.order(:id).to_a
731 731
     assert_no_queries do
732 732
       assert_equal(projects, developer.projects)
733 733
     end
@@ -735,7 +735,7 @@ def test_eager_with_default_scope
735 735
 
736 736
   def test_eager_with_default_scope_as_class_method
737 737
     developer = EagerDeveloperWithClassMethodDefaultScope.where(:name => 'David').first
738  
-    projects = Project.order(:id).all
  738
+    projects = Project.order(:id).to_a
739 739
     assert_no_queries do
740 740
       assert_equal(projects, developer.projects)
741 741
     end
@@ -743,7 +743,7 @@ def test_eager_with_default_scope_as_class_method
743 743
 
744 744
   def test_eager_with_default_scope_as_lambda
745 745
     developer = EagerDeveloperWithLambdaDefaultScope.where(:name => 'David').first
746  
-    projects = Project.order(:id).all
  746
+    projects = Project.order(:id).to_a
747 747
     assert_no_queries do
748 748
       assert_equal(projects, developer.projects)
749 749
     end
@@ -751,7 +751,7 @@ def test_eager_with_default_scope_as_lambda
751 751
 
752 752
   def test_eager_with_default_scope_as_block
753 753
     developer = EagerDeveloperWithBlockDefaultScope.where(:name => 'David').first
754  
-    projects = Project.order(:id).all
  754
+    projects = Project.order(:id).to_a
755 755
     assert_no_queries do
756 756
       assert_equal(projects, developer.projects)
757 757
     end
@@ -759,14 +759,14 @@ def test_eager_with_default_scope_as_block
759 759
 
760 760
   def test_eager_with_default_scope_as_callable
761 761
     developer = EagerDeveloperWithCallableDefaultScope.where(:name => 'David').first
762  
-    projects = Project.order(:id).all
  762
+    projects = Project.order(:id).to_a
763 763
     assert_no_queries do
764 764
       assert_equal(projects, developer.projects)
765 765
     end
766 766
   end
767 767
 
768 768
   def find_all_ordered(className, include=nil)
769  
-    className.scoped(:order=>"#{className.table_name}.#{className.primary_key}", :includes=>include).all
  769
+    className.scoped(:order=>"#{className.table_name}.#{className.primary_key}", :includes=>include).to_a
770 770
   end
771 771
 
772 772
   def test_limited_eager_with_order
@@ -775,14 +775,14 @@ def test_limited_eager_with_order
775 775
       Post.scoped(
776 776
         :includes => [:author, :comments], :where => { 'authors.name' => 'David' },
777 777
         :order => 'UPPER(posts.title)', :limit => 2, :offset => 1
778  
-      ).all
  778
+      ).to_a
779 779
     )
780 780
     assert_equal(
781 781
       posts(:sti_post_and_comments, :sti_comments),
782 782
       Post.scoped(
783 783
         :includes => [:author, :comments], :where => { 'authors.name' => 'David' },
784 784
         :order => 'UPPER(posts.title) DESC', :limit => 2, :offset => 1
785  
-      ).all
  785
+      ).to_a
786 786
     )
787 787
   end
788 788
 
@@ -792,14 +792,14 @@ def test_limited_eager_with_multiple_order_columns
792 792
       Post.scoped(
793 793
         :includes => [:author, :comments], :where => { 'authors.name' => 'David' },
794 794
         :order => ['UPPER(posts.title)', 'posts.id'], :limit => 2, :offset => 1
795  
-      ).all
  795
+      ).to_a
796 796
     )
797 797
     assert_equal(
798 798
       posts(:sti_post_and_comments, :sti_comments),
799 799
       Post.scoped(
800 800
         :includes => [:author, :comments], :where => { 'authors.name' => 'David' },
801 801
         :order => ['UPPER(posts.title) DESC', 'posts.id'], :limit => 2, :offset => 1
802  
-      ).all
  802
+      ).to_a
803 803
     )
804 804
   end
805 805
 
@@ -810,7 +810,7 @@ def test_limited_eager_with_numeric_in_association
810 810
         :includes => [:readers, :primary_contact, :number1_fan],
811 811
         :where => "number1_fans_people.first_name like 'M%'",
812 812
         :order => 'people.id', :limit => 2, :offset => 0
813  
-      ).all
  813
+      ).to_a
814 814
     )
815 815
   end
816 816
 
@@ -876,13 +876,13 @@ def test_eager_with_multiple_associations_with_same_table_belongs_to
876 876
     end
877 877
   end
878 878
   def test_eager_with_valid_association_as_string_not_symbol
879  
-    assert_nothing_raised { Post.scoped(:includes => 'comments').all }
  879
+    assert_nothing_raised { Post.scoped(:includes => 'comments').to_a }
880 880
   end
881 881
 
882 882
   def test_eager_with_floating_point_numbers
883 883
     assert_queries(2) do
884 884
       # Before changes, the floating point numbers will be interpreted as table names and will cause this to run in one query
885  
-      Comment.scoped(:where => "123.456 = 123.456", :includes => :post).all
  885
+      Comment.scoped(:where => "123.456 = 123.456", :includes => :post).to_a
886 886
     end
887 887
   end
888 888
 
@@ -936,21 +936,21 @@ def test_count_with_include
936 936
 
937 937
   def test_load_with_sti_sharing_association
938 938
     assert_queries(2) do #should not do 1 query per subclass
939  
-      Comment.includes(:post).all
  939
+      Comment.includes(:post).to_a
940 940
     end
941 941
   end
942 942
 
943 943
   def test_conditions_on_join_table_with_include_and_limit
944  
-    assert_equal 3, Developer.scoped(:includes => 'projects', :where => { 'developers_projects.access_level' => 1 }, :limit => 5).all.size
  944
+    assert_equal 3, Developer.scoped(:includes => 'projects', :where => { 'developers_projects.access_level' => 1 }, :limit => 5).to_a.size
945 945
   end
946 946
 
947 947
   def test_order_on_join_table_with_include_and_limit
948  
-    assert_equal 5, Developer.scoped(:includes => 'projects', :order => 'developers_projects.joined_on DESC', :limit => 5).all.size
  948
+    assert_equal 5, Developer.scoped(:includes => 'projects', :order => 'developers_projects.joined_on DESC', :limit => 5).to_a.size
949 949
   end
950 950
 
951 951
   def test_eager_loading_with_order_on_joined_table_preloads
952 952
     posts = assert_queries(2) do
953  
-      Post.scoped(:joins => :comments, :includes => :author, :order => 'comments.id DESC').all
  953
+      Post.scoped(:joins => :comments, :includes => :author, :order => 'comments.id DESC').to_a
954 954
     end
955 955
     assert_equal posts(:eager_other), posts[1]
956 956
     assert_equal authors(:mary), assert_no_queries { posts[1].author}
@@ -958,37 +958,37 @@ def test_eager_loading_with_order_on_joined_table_preloads
958 958
 
959 959
   def test_eager_loading_with_conditions_on_joined_table_preloads
960 960
     posts = assert_queries(2) do
961  
-      Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => [:comments], :where => "comments.body like 'Thank you%'", :order => 'posts.id').all
  961
+      Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => [:comments], :where => "comments.body like 'Thank you%'", :order => 'posts.id').to_a
962 962
     end
963 963
     assert_equal [posts(:welcome)], posts
964 964
     assert_equal authors(:david), assert_no_queries { posts[0].author}
965 965
 
966 966
     posts = assert_queries(2) do
967  
-      Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => [:comments], :where => "comments.body like 'Thank you%'", :order => 'posts.id').all
  967
+      Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => [:comments], :where => "comments.body like 'Thank you%'", :order => 'posts.id').to_a
968 968
     end
969 969
     assert_equal [posts(:welcome)], posts
970 970
     assert_equal authors(:david), assert_no_queries { posts[0].author}
971 971
 
972 972
     posts = assert_queries(2) do
973  
-      Post.scoped(:includes => :author, :joins => {:taggings => :tag}, :where => "tags.name = 'General'", :order => 'posts.id').all
  973
+      Post.scoped(:includes => :author, :joins => {:taggings => :tag}, :where => "tags.name = 'General'", :order => 'posts.id').to_a
974 974
     end
975 975
     assert_equal posts(:welcome, :thinking), posts
976 976
 
977 977
     posts = assert_queries(2) do
978  
-      Post.scoped(:includes => :author, :joins => {:taggings => {:tag => :taggings}}, :where => "taggings_tags.super_tag_id=2", :order => 'posts.id').all
  978
+      Post.scoped(:includes => :author, :joins => {:taggings => {:tag => :taggings}}, :where => "taggings_tags.super_tag_id=2", :order => 'posts.id').to_a
979 979
     end
980 980
     assert_equal posts(:welcome, :thinking), posts
981 981
   end
982 982
 
983 983
   def test_eager_loading_with_conditions_on_string_joined_table_preloads
984 984
     posts = assert_queries(2) do
985  
-      Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => "INNER JOIN comments on comments.post_id = posts.id", :where => "comments.body like 'Thank you%'", :order => 'posts.id').all
  985
+      Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => "INNER JOIN comments on comments.post_id = posts.id", :where => "comments.body like 'Thank you%'", :order => 'posts.id').to_a
986 986
     end
987 987
     assert_equal [posts(:welcome)], posts
988 988
     assert_equal authors(:david), assert_no_queries { posts[0].author}
989 989
 
990 990
     posts = assert_queries(2) do
991  
-      Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => ["INNER JOIN comments on comments.post_id = posts.id"], :where => "comments.body like 'Thank you%'", :order => 'posts.id').all
  991
+      Post.scoped(:select => 'distinct posts.*', :includes => :author, :joins => ["INNER JOIN comments on comments.post_id = posts.id"], :where => "comments.body like 'Thank you%'", :order => 'posts.id').to_a
992 992
     end
993 993
     assert_equal [posts(:welcome)], posts
994 994
     assert_equal authors(:david), assert_no_queries { posts[0].author}
@@ -996,7 +996,7 @@ def test_eager_loading_with_conditions_on_string_joined_table_preloads
996 996
 
997 997
   def test_eager_loading_with_select_on_joined_table_preloads
998 998
     posts = assert_queries(2) do
999  
-      Post.scoped(:select => 'posts.*, authors.name as author_name', :includes => :comments, :joins => :author, :order => 'posts.id').all
  999
+      Post.scoped(:select => 'posts.*, authors.name as author_name', :includes => :comments, :joins => :author, :order => 'posts.id').to_a
1000 1000
     end
1001 1001
     assert_equal 'David', posts[0].author_name
1002 1002
     assert_equal posts(:welcome).comments, assert_no_queries { posts[0].comments}
@@ -1004,14 +1004,14 @@ def test_eager_loading_with_select_on_joined_table_preloads
1004 1004
 
1005 1005
   def test_eager_loading_with_conditions_on_join_model_preloads
1006 1006
     authors = assert_queries(2) do
1007  
-      Author.scoped(:includes => :author_address, :joins => :comments, :where => "posts.title like 'Welcome%'").all
  1007
+      Author.scoped(:includes => :author_address, :joins => :comments, :where => "posts.title like 'Welcome%'").to_a
1008 1008
     end
1009 1009
     assert_equal authors(:david), authors[0]
1010 1010
     assert_equal author_addresses(:david_address), authors[0].author_address
1011 1011
   end
1012 1012
 
1013 1013
   def test_preload_belongs_to_uses_exclusive_scope
1014  
-    people = Person.males.scoped(:includes => :primary_contact).all
  1014
+    people = Person.males.scoped(:includes => :primary_contact).to_a
1015 1015
     assert_not_equal people.length, 0
1016 1016
     people.each do |person|
1017 1017
       assert_no_queries {assert_not_nil person.primary_contact}
@@ -1020,7 +1020,7 @@ def test_preload_belongs_to_uses_exclusive_scope
1020 1020
   end
1021 1021
 
1022 1022
   def test_preload_has_many_uses_exclusive_scope
1023  
-    people = Person.males.includes(:agents).all
  1023
+    people = Person.males.includes(:agents).to_a
1024 1024
     people.each do |person|
1025 1025
       assert_equal Person.find(person.id).agents, person.agents
1026 1026
     end
@@ -1057,7 +1057,7 @@ def test_preload_has_one_using_primary_key
1057 1057
 
1058 1058
   def test_include_has_one_using_primary_key
1059 1059
     expected = accounts(:signals37)
1060  
-    firm = Firm.scoped(:includes => :account_using_primary_key, :order => 'accounts.id').all.detect {|f| f.id == 1}
  1060
+    firm = Firm.scoped(:includes => :account_using_primary_key, :order => 'accounts.id').to_a.detect {|f| f.id == 1}
1061 1061
     assert_no_queries do
1062 1062
       assert_equal expected, firm.account_using_primary_key
1063 1063
     end
@@ -1121,7 +1121,7 @@ def test_join_eager_with_nil_order_should_generate_valid_sql
1121 1121
   end
1122 1122
 
1123 1123
   def test_deep_including_through_habtm
1124  
-    posts = Post.scoped(:includes => {:categories => :categorizations}, :order => "posts.id").all
  1124
+    posts = Post.scoped(:includes => {:categories => :categorizations}, :order => "posts.id").to_a
1125 1125
     assert_no_queries { assert_equal 2, posts[0].categories[0].categorizations.length }
1126 1126
     assert_no_queries { assert_equal 1, posts[0].categories[1].categorizations.length }
1127 1127
     assert_no_queries { assert_equal 2, posts[1].categories[0].categorizations.length }
14  activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -346,7 +346,7 @@ def test_deleting
346 346
   def test_deleting_array
347 347
     david = Developer.find(1)
348 348
     david.projects.reload
349  
-    david.projects.delete(Project.all)
  349
+    david.projects.delete(Project.to_a)
350 350
     assert_equal 0, david.projects.size
351 351
     assert_equal 0, david.projects(true).size
352 352
   end
@@ -388,7 +388,7 @@ def test_destroying
388 388
   def test_destroying_many
389 389
     david = Developer.find(1)
390 390
     david.projects.reload
391  
-    projects = Project.all
  391
+    projects = Project.to_a
392 392
 
393 393
     assert_no_difference "Project.count" do
394 394
       david.projects.destroy(*projects)
@@ -501,8 +501,8 @@ def test_include_returns_false_for_non_matching_record_to_verify_scoping
501 501
 
502 502
   def test_find_with_merged_options
503 503
     assert_equal 1, projects(:active_record).limited_developers.size
504  
-    assert_equal 1, projects(:active_record).limited_developers.all.size
505  
-    assert_equal 3, projects(:active_record).limited_developers.limit(nil).all.size
  504
+    assert_equal 1, projects(:active_record).limited_developers.to_a.size
  505
+    assert_equal 3, projects(:active_record).limited_developers.limit(nil).to_a.size
506 506
   end
507 507
 
508 508
   def test_dynamic_find_should_respect_association_order
@@ -536,7 +536,7 @@ def test_new_with_values_in_collection
536 536
   end
537 537
 
538 538
   def test_find_in_association_with_options
539  
-    developers = projects(:active_record).developers.all
  539
+    developers = projects(:active_record).developers.to_a
540 540
     assert_equal 3, developers.size
541 541
 
542 542
     assert_equal developers(:poor_jamis), projects(:active_record).developers.where("salary < 10000").first
@@ -638,8 +638,8 @@ def test_join_with_group
638 638
   end
639 639
 
640 640
   def test_find_grouped
641  
-    all_posts_from_category1 = Post.scoped(:where => "category_id = 1", :joins => :categories).all
642  
-    grouped_posts_of_category1 = Post.scoped(:where => "category_id = 1", :group => "author_id", :select => 'count(posts.id) as posts_count', :joins => :categories).all
  641
+    all_posts_from_category1 = Post.scoped(:where => "category_id = 1", :joins => :categories).to_a
  642
+    grouped_posts_of_category1 = Post.scoped(:where => "category_id = 1", :group => "author_id", :select => 'count(posts.id) as posts_count', :joins => :categories).to_a
643 643
     assert_equal 5, all_posts_from_category1.size
644 644
     assert_equal 2, grouped_posts_of_category1.size
645 645
   end
28  activerecord/test/cases/associations/has_many_associations_test.rb
@@ -221,14 +221,14 @@ def test_finding_array_compatibility
221 221
 
222 222
   def test_find_with_blank_conditions
223 223
     [[], {}, nil, ""].each do |blank|
224  
-      assert_equal 2, Firm.scoped(:order => "id").first.clients.where(blank).all.size
  224
+      assert_equal 2, Firm.scoped(:order => "id").first.clients.where(blank).to_a.size
225 225
     end
226 226
   end
227 227
 
228 228
   def test_find_many_with_merged_options
229 229
     assert_equal 1, companies(:first_firm).limited_clients.size
230  
-    assert_equal 1, companies(:first_firm).limited_clients.all.size
231  
-    assert_equal 2, companies(:first_firm).limited_clients.limit(nil).all.size
  230
+    assert_equal 1, companies(:first_firm).limited_clients.to_a.size
  231
+    assert_equal 2, companies(:first_firm).limited_clients.limit(nil).to_a.size
232 232
   end
233 233
 
234 234
   def test_find_should_append_to_association_order
@@ -299,8 +299,8 @@ def test_find_ids
299 299
 
300 300
   def test_find_all
301 301
     firm = Firm.scoped(:order => "id").first
302  
-    assert_equal 2, firm.clients.scoped(:where => "#{QUOTED_TYPE} = 'Client'").all.length
303  
-    assert_equal 1, firm.clients.scoped(:where => "name = 'Summit'").all.length
  302
+    assert_equal 2, firm.clients.scoped(:where => "#{QUOTED_TYPE} = 'Client'").to_a.length
  303
+    assert_equal 1, firm.clients.scoped(:where => "name = 'Summit'").to_a.length