@@ -16,15 +16,15 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
1616 :categorizations , :people , :categories , :edges , :vertices
1717
1818 def test_eager_association_loading_with_cascaded_two_levels
19- authors = Author . scoped ( :includes => { :posts => :comments } , :order => "authors.id" ) . to_a
19+ authors = Author . all . merge! ( :includes => { :posts => :comments } , :order => "authors.id" ) . to_a
2020 assert_equal 3 , authors . size
2121 assert_equal 5 , authors [ 0 ] . posts . size
2222 assert_equal 3 , authors [ 1 ] . posts . size
2323 assert_equal 10 , authors [ 0 ] . posts . collect { |post | post . comments . size } . inject ( 0 ) { |sum , i | sum +i }
2424 end
2525
2626 def test_eager_association_loading_with_cascaded_two_levels_and_one_level
27- authors = Author . scoped ( :includes => [ { :posts => :comments } , :categorizations ] , :order => "authors.id" ) . to_a
27+ authors = Author . all . merge! ( :includes => [ { :posts => :comments } , :categorizations ] , :order => "authors.id" ) . to_a
2828 assert_equal 3 , authors . size
2929 assert_equal 5 , authors [ 0 ] . posts . size
3030 assert_equal 3 , authors [ 1 ] . posts . size
@@ -84,37 +84,37 @@ def test_eager_association_loading_with_join_for_count
8484 end
8585
8686 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" ) . to_a
87+ authors = Author . all . merge! ( :includes => { :posts => [ :comments , :categorizations ] } , :order => "authors.id" ) . to_a
8888 assert_equal 3 , authors . size
8989 assert_equal 5 , authors [ 0 ] . posts . size
9090 assert_equal 3 , authors [ 1 ] . posts . size
9191 assert_equal 10 , authors [ 0 ] . posts . collect { |post | post . comments . size } . inject ( 0 ) { |sum , i | sum +i }
9292 end
9393
9494 def test_eager_association_loading_with_cascaded_two_levels_and_self_table_reference
95- authors = Author . scoped ( :includes => { :posts => [ :comments , :author ] } , :order => "authors.id" ) . to_a
95+ authors = Author . all . merge! ( :includes => { :posts => [ :comments , :author ] } , :order => "authors.id" ) . to_a
9696 assert_equal 3 , authors . size
9797 assert_equal 5 , authors [ 0 ] . posts . size
9898 assert_equal authors ( :david ) . name , authors [ 0 ] . name
9999 assert_equal [ authors ( :david ) . name ] , authors [ 0 ] . posts . collect { |post | post . author . name } . uniq
100100 end
101101
102102 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" ) . to_a
103+ authors = Author . all . merge! ( :includes => { :posts => :comments } , :where => "authors.id=1" , :order => "authors.id" ) . to_a
104104 assert_equal 1 , authors . size
105105 assert_equal 5 , authors [ 0 ] . posts . size
106106 end
107107
108108 def test_eager_association_loading_with_cascaded_three_levels_by_ping_pong
109- firms = Firm . scoped ( :includes => { :account => { :firm => :account } } , :order => "companies.id" ) . to_a
109+ firms = Firm . all . merge! ( :includes => { :account => { :firm => :account } } , :order => "companies.id" ) . to_a
110110 assert_equal 2 , firms . size
111111 assert_equal firms . first . account , firms . first . account . firm . account
112112 assert_equal companies ( :first_firm ) . account , assert_no_queries { firms . first . account . firm . account }
113113 assert_equal companies ( :first_firm ) . account . firm . account , assert_no_queries { firms . first . account . firm . account }
114114 end
115115
116116 def test_eager_association_loading_with_has_many_sti
117- topics = Topic . scoped ( :includes => :replies , :order => 'topics.id' ) . to_a
117+ topics = Topic . all . merge! ( :includes => :replies , :order => 'topics.id' ) . to_a
118118 first , second , = topics ( :first ) . replies . size , topics ( :second ) . replies . size
119119 assert_no_queries do
120120 assert_equal first , topics [ 0 ] . replies . size
@@ -127,22 +127,22 @@ def test_eager_association_loading_with_has_many_sti_and_subclasses
127127 silly . parent_id = 1
128128 assert silly . save
129129
130- topics = Topic . scoped ( :includes => :replies , :order => [ 'topics.id' , 'replies_topics.id' ] ) . to_a
130+ topics = Topic . all . merge! ( :includes => :replies , :order => [ 'topics.id' , 'replies_topics.id' ] ) . to_a
131131 assert_no_queries do
132132 assert_equal 2 , topics [ 0 ] . replies . size
133133 assert_equal 0 , topics [ 1 ] . replies . size
134134 end
135135 end
136136
137137 def test_eager_association_loading_with_belongs_to_sti
138- replies = Reply . scoped ( :includes => :topic , :order => 'topics.id' ) . to_a
138+ replies = Reply . all . merge! ( :includes => :topic , :order => 'topics.id' ) . to_a
139139 assert replies . include? ( topics ( :second ) )
140140 assert !replies . include? ( topics ( :first ) )
141141 assert_equal topics ( :first ) , assert_no_queries { replies . first . topic }
142142 end
143143
144144 def test_eager_association_loading_with_multiple_stis_and_order
145- author = Author . scoped ( :includes => { :posts => [ :special_comments , :very_special_comment ] } , :order => [ 'authors.name' , 'comments.body' , 'very_special_comments_posts.body' ] , :where => 'posts.id = 4' ) . first
145+ author = Author . all . merge! ( :includes => { :posts => [ :special_comments , :very_special_comment ] } , :order => [ 'authors.name' , 'comments.body' , 'very_special_comments_posts.body' ] , :where => 'posts.id = 4' ) . first
146146 assert_equal authors ( :david ) , author
147147 assert_no_queries do
148148 author . posts . first . special_comments
@@ -151,7 +151,7 @@ def test_eager_association_loading_with_multiple_stis_and_order
151151 end
152152
153153 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' ) . to_a
154+ authors = Author . all . merge! ( :includes => { :posts => { :special_comments => { :post => [ :special_comments , :very_special_comment ] } } } , :order => 'comments.body, very_special_comments_posts.body' , :where => 'posts.id = 4' ) . to_a
155155 assert_equal [ authors ( :david ) ] , authors
156156 assert_no_queries do
157157 authors . first . posts . first . special_comments . first . post . special_comments
@@ -160,20 +160,20 @@ def test_eager_association_loading_of_stis_with_multiple_references
160160 end
161161
162162 def test_eager_association_loading_where_first_level_returns_nil
163- authors = Author . scoped ( :includes => { :post_about_thinking => :comments } , :order => 'authors.id DESC' ) . to_a
163+ authors = Author . all . merge! ( :includes => { :post_about_thinking => :comments } , :order => 'authors.id DESC' ) . to_a
164164 assert_equal [ authors ( :bob ) , authors ( :mary ) , authors ( :david ) ] , authors
165165 assert_no_queries do
166166 authors [ 2 ] . post_about_thinking . comments . first
167167 end
168168 end
169169
170170 def test_eager_association_loading_with_recursive_cascading_four_levels_has_many_through
171- source = Vertex . scoped ( :includes => { :sinks => { :sinks => { :sinks => :sinks } } } , :order => 'vertices.id' ) . first
171+ source = Vertex . all . merge! ( :includes => { :sinks => { :sinks => { :sinks => :sinks } } } , :order => 'vertices.id' ) . first
172172 assert_equal vertices ( :vertex_4 ) , assert_no_queries { source . sinks . first . sinks . first . sinks . first }
173173 end
174174
175175 def test_eager_association_loading_with_recursive_cascading_four_levels_has_and_belongs_to_many
176- sink = Vertex . scoped ( :includes => { :sources => { :sources => { :sources => :sources } } } , :order => 'vertices.id DESC' ) . first
176+ sink = Vertex . all . merge! ( :includes => { :sources => { :sources => { :sources => :sources } } } , :order => 'vertices.id DESC' ) . first
177177 assert_equal vertices ( :vertex_1 ) , assert_no_queries { sink . sources . first . sources . first . sources . first . sources . first }
178178 end
179179end
0 commit comments