public
Rubygem
Description: Most awesome pagination solution for Rails
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/mislav/will_paginate.git
Search Repo:
added test for parent commit (removing :include from count in ActiveRecord 
2.1)
mislav (author)
Fri May 16 03:58:59 -0700 2008
commit  b3caa0a44bfd08596e218c306d6fc93a578bad34
tree    7c8d76620893e58937c1f123d7037e16c854bc0b
parent  24260c3363d938bb42c94522a28585ead63a0c51
...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
 
 
 
 
 
 
 
 
 
 
202
203
204
...
184
185
186
 
 
 
187
188
189
 
 
 
 
 
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
0
@@ -184,21 +184,23 @@ module WillPaginate
0
         unless options[:select] and options[:select] =~ /^\s*DISTINCT\b/i
0
           excludees << :select # only exclude the select param if it doesn't begin with DISTINCT
0
         end
0
-
0
- # we may be in a model or an association proxy!
0
- klass = (@owner and @reflection) ? @reflection.klass : self
0
 
0
         # count expects (almost) the same options as find
0
         count_options = options.except *excludees
0
-
0
- # remove :include option if it doesn't need
0
- if count_options[:include] and !klass.send :references_eager_loaded_tables?, count_options
0
- count_options.delete :include
0
- end
0
 
0
         # merge the hash found in :count
0
         # this allows you to specify :select, :order, or anything else just for the count query
0
         count_options.update options[:count] if options[:count]
0
+
0
+ # we may be in a model or an association proxy
0
+ klass = (@owner and @reflection) ? @reflection.klass : self
0
+
0
+ # forget about includes if they are irrelevant (Rails 2.1)
0
+ if count_options[:include] and
0
+ klass.private_methods.include?('references_eager_loaded_tables?') and
0
+ !klass.send(:references_eager_loaded_tables?, count_options)
0
+ count_options.delete :include
0
+ end
0
 
0
         # we may have to scope ...
0
         counter = Proc.new { count(count_options) }
...
412
413
414
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
416
...
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
0
@@ -412,5 +412,23 @@ class FinderTest < ActiveRecordTestCase
0
       
0
       assert_equal 14, Developer.paginated_each(:page => '2') { }
0
     end
0
+
0
+ # detect ActiveRecord 2.1
0
+ if ActiveRecord::Base.private_methods.include?('references_eager_loaded_tables?')
0
+ def test_removes_irrelevant_includes_in_count
0
+ Developer.expects(:find).returns([1])
0
+ Developer.expects(:count).with({}).returns(0)
0
+
0
+ Developer.paginate :page => 1, :per_page => 1, :include => :projects
0
+ end
0
+
0
+ def test_doesnt_remove_referenced_includes_in_count
0
+ Developer.expects(:find).returns([1])
0
+ Developer.expects(:count).with({ :include => :projects, :conditions => 'projects.id > 2' }).returns(0)
0
+
0
+ Developer.paginate :page => 1, :per_page => 1,
0
+ :include => :projects, :conditions => 'projects.id > 2'
0
+ end
0
+ end
0
   end
0
 end

Comments

    No one has commented yet.