public
Rubygem
Description: Most awesome pagination solution for Ruby
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/mislav/will_paginate.git
convert all remaining ActiveRecord tests to specs
mislav (author)
Sun Jun 08 16:28:07 -0700 2008
commit  172ef85ada50ceec42bc8c7016194d00de0dfea6
tree    2f3c284e78926a0b623b3b574d9e62924f3ba96d
parent  16452f58394c697d68c3d6fe96b59a07f430d11e
...
181
182
183
184
 
185
186
187
...
309
310
311
 
312
313
314
315
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
317
318
 
 
 
 
 
319
320
321
322
323
 
324
325
326
...
181
182
183
 
184
185
186
187
...
309
310
311
312
313
314
315
 
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
 
427
428
429
430
0
@@ -181,7 +181,7 @@ describe WillPaginate::Finders::ActiveRecord do
0
         result.current_page.should == 1
0
         result.total_pages.should == 1
0
         result.size.should == 4
0
- }.should run_queries
0
+ }.should run_queries(1)
0
     end
0
     
0
     it "should get second (inexistent) page of Topics, requiring 2 queries" do
0
@@ -309,18 +309,122 @@ describe WillPaginate::Finders::ActiveRecord do
0
 
0
       it "should paginate through association extension" do
0
         project = Project.find(:first)
0
+ expected = [replies(:brave)]
0
 
0
         lambda {
0
           result = project.replies.paginate_recent :page => 1
0
- result.should == [replies(:brave)]
0
+ result.should == expected
0
+ }.should run_queries(1)
0
+ end
0
+ end
0
+
0
+ it "should paginate with joins" do
0
+ result = nil
0
+ join_sql = 'LEFT JOIN developers_projects ON users.id = developers_projects.developer_id'
0
+
0
+ lambda {
0
+ result = Developer.paginate :page => 1, :joins => join_sql, :conditions => 'project_id = 1'
0
+ result.size.should == 2
0
+ developer_names = result.map(&:name)
0
+ developer_names.should include('David')
0
+ developer_names.should include('Jamis')
0
+ }.should run_queries(1)
0
+
0
+ lambda {
0
+ expected = result.to_a
0
+ result = Developer.paginate :page => 1, :joins => join_sql,
0
+ :conditions => 'project_id = 1', :count => { :select => "users.id" }
0
+ result.should == expected
0
+ result.total_entries.should == 2
0
+ }.should run_queries(1)
0
+ end
0
+
0
+ it "should paginate with group" do
0
+ result = nil
0
+ lambda {
0
+ result = Developer.paginate :page => 1, :per_page => 10,
0
+ :group => 'salary', :select => 'salary', :order => 'salary'
0
+ }.should run_queries(1)
0
+
0
+ expected = users(:david, :jamis, :dev_10, :poor_jamis).map(&:salary).sort
0
+ result.map(&:salary).should == expected
0
+ end
0
+
0
+ it "should paginate with dynamic finder" do
0
+ expected = replies(:witty_retort, :spam)
0
+ Reply.paginate_by_topic_id(1, :page => 1).should == expected
0
+
0
+ result = Developer.paginate :conditions => { :salary => 100000 }, :page => 1, :per_page => 5
0
+ result.total_entries.should == 8
0
+ Developer.paginate_by_salary(100000, :page => 1, :per_page => 5).should == result
0
+ end
0
+
0
+ it "should paginate with dynamic finder and conditions" do
0
+ result = Developer.paginate_by_salary(100000, :page => 1, :conditions => ['id > ?', 6])
0
+ result.total_entries.should == 4
0
+ result.map(&:id).should == (7..10).to_a
0
+ end
0
+
0
+ it "should raise error when dynamic finder is not recognized" do
0
+ lambda {
0
+ Developer.paginate_by_inexistent_attribute 100000, :page => 1
0
+ }.should raise_error(NoMethodError)
0
+ end
0
+
0
+ it "should paginate with_scope" do
0
+ result = Developer.with_poor_ones { Developer.paginate :page => 1 }
0
+ result.size.should == 2
0
+ result.total_entries.should == 2
0
+ end
0
+
0
+ describe "named_scope" do
0
+ it "should paginate" do
0
+ result = Developer.poor.paginate :page => 1, :per_page => 1
0
+ result.size.should == 1
0
+ result.total_entries.should == 2
0
+ end
0
+
0
+ it "should paginate on habtm association" do
0
+ project = projects(:active_record)
0
+ lambda {
0
+ result = project.developers.poor.paginate :page => 1, :per_page => 1
0
+ result.size.should == 1
0
+ result.total_entries.should == 1
0
+ }.should run_queries(2)
0
+ end
0
+
0
+ it "should paginate on hmt association" do
0
+ project = projects(:active_record)
0
+ expected = [replies(:brave)]
0
+
0
+ lambda {
0
+ result = project.replies.recent.paginate :page => 1, :per_page => 1
0
+ result.should == expected
0
+ result.total_entries.should == 1
0
+ }.should run_queries(2)
0
+ end
0
+
0
+ it "should paginate on has_many association" do
0
+ project = projects(:active_record)
0
+ expected = [topics(:ar)]
0
+
0
+ lambda {
0
+ result = project.topics.mentions_activerecord.paginate :page => 1, :per_page => 1
0
+ result.should == expected
0
+ result.total_entries.should == 1
0
         }.should run_queries(2)
0
       end
0
     end
0
+
0
+ it "should paginate with :readonly option" do
0
+ lambda { Developer.paginate :readonly => true, :page => 1 }.should_not raise_error
0
+ end
0
+
0
   end
0
   
0
   protected
0
   
0
- def run_queries(num = 1)
0
+ def run_queries(num)
0
       QueryCountMatcher.new(num)
0
     end
0
 

Comments

    No one has commented yet.