tests for AR group query

This commit is contained in:
Akira Matsuda 2011-02-23 00:20:44 +09:00
parent 062c60344b
commit d0b28fcc5f
2 changed files with 10 additions and 3 deletions

View File

@ -42,7 +42,7 @@ Object.const_set(:ApplicationHelper, Module.new)
#migrations
class CreateAllTables < ActiveRecord::Migration
def self.up
create_table(:users) {|t| t.string :name }
create_table(:books) {|t| t.string :title }
create_table(:users) {|t| t.string :name; t.integer :age}
create_table(:books) {|t| t.string :title}
end
end

View File

@ -3,7 +3,7 @@ require File.expand_path('../spec_helper', File.dirname(__FILE__))
describe Kaminari::ActiveRecordExtension do
before :all do
User.delete_all
1.upto(100) {|i| User.create! :name => "user#{'%03d' % i}" }
1.upto(100) {|i| User.create! :name => "user#{'%03d' % i}", :age => (i / 10)}
end
describe '#page' do
@ -94,4 +94,11 @@ describe Kaminari::ActiveRecordExtension do
its(:current_page) { should == 2 }
end
end
context 'chained with .group' do
subject { User.group('age').page(2).per 5 }
# 0..10
its(:total_count) { should == 11 }
its(:num_pages) { should == 3 }
end
end