Skip to content
Browse files

reduce number of test Users

loading 300 records in every before :each is so slow
  • Loading branch information...
1 parent 94dbed0 commit 480b78aa4626b82254b6bef356c5869dffecb557 @amatsuda committed
Showing with 35 additions and 35 deletions.
  1. +35 −35 spec/models/data_mapper/data_mapper_spec.rb
View
70 spec/models/data_mapper/data_mapper_spec.rb
@@ -3,7 +3,7 @@
if defined? DataMapper
describe Kaminari::DataMapperExtension do
before do
- 300.times do |i|
+ 100.times do |i|
User.create(:name => "User#{i}", :age => i)
end
@@ -29,13 +29,13 @@
describe '#page' do
context 'page 0' do
- subject { User.all(:age.gte => 200).page 0 }
+ subject { User.all(:age.gte => 60).page 0 }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 1 }
its('query.limit') { should == 25 }
its('query.offset') { should == 0 }
- its(:total_count) { should == User.count(:age.gte => 200) }
- its(:num_pages) { should == 4 }
+ its(:total_count) { should == User.count(:age.gte => 60) }
+ its(:num_pages) { should == 2 }
end
context 'page 1' do
@@ -44,8 +44,8 @@
its(:current_page) { should == 1 }
its('query.limit') { should == 25 }
its('query.offset') { should == 0 }
- its(:total_count) { should == 300 }
- its(:num_pages) { should == 12 }
+ its(:total_count) { should == 100 }
+ its(:num_pages) { should == 4 }
end
context 'page 2' do
@@ -55,8 +55,8 @@
its(:limit_value) { should == 25 }
its('query.limit') { should == 25 }
its('query.offset') { should == 25 }
- its(:total_count) { should == 300 }
- its(:num_pages) { should == 12 }
+ its(:total_count) { should == 100 }
+ its(:num_pages) { should == 4 }
end
context 'page "foobar"' do
@@ -65,72 +65,72 @@
its(:current_page) { should == 1 }
its('query.limit') { should == 25 }
its('query.offset') { should == 0 }
- its(:total_count) { should == 300 }
- its(:num_pages) { should == 12 }
+ its(:total_count) { should == 100 }
+ its(:num_pages) { should == 4 }
end
context 'with criteria before' do
- subject { User.all(:age.gt => 100).page 2 }
+ subject { User.all(:age.gt => 60).page 2 }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 2 }
its('query.limit') { should == 25 }
its('query.offset') { should == 25 }
- its(:total_count) { should == User.count(:age.gt => 100) }
- its(:num_pages) { should == 8 }
+ its(:total_count) { should == User.count(:age.gt => 60) }
+ its(:num_pages) { should == 2 }
end
context 'with criteria after' do
- subject { User.page(2).all(:age.gt => 100) }
+ subject { User.page(2).all(:age.gt => 60) }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 2 }
its('query.limit') { should == 25 }
its('query.offset') { should == 25 }
- its(:total_count) { should == User.count(:age.gt => 100) }
- its(:num_pages) { should == 8 }
+ its(:total_count) { should == User.count(:age.gt => 60) }
+ its(:num_pages) { should == 2 }
end
end
describe '#per' do
context 'on simple query' do
- subject { User.page(2).per(10) }
+ subject { User.page(2).per(20) }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 2 }
- its('query.limit') { should == 10 }
- its(:limit_value) { should == 10 }
- its('query.offset') { should == 10 }
- its(:total_count) { should == 300 }
- its(:num_pages) { should == 30 }
+ its('query.limit') { should == 20 }
+ its(:limit_value) { should == 20 }
+ its('query.offset') { should == 20 }
+ its(:total_count) { should == 100 }
+ its(:num_pages) { should == 5 }
end
context 'on query with condition' do
- subject { User.page(5).all(:age.lte => 100).per(13) }
+ subject { User.page(5).all(:age.lte => 80).per(13) }
its(:current_page) { should == 5 }
its('query.limit') { should == 13 }
its('query.offset') { should == 52 }
- its(:total_count) { should == 101 }
- its(:num_pages) { should == 8 }
+ its(:total_count) { should == 81 }
+ its(:num_pages) { should == 7 }
end
context 'on query with order' do
- subject { User.page(5).all(:age.lte => 100, :order => [:age.asc]).per(13) }
- it('includes worker with age 52') { should include(User.first(:age => 52)) }
- it('does not include worker with age 51') { should_not include(User.first(:age => 51)) }
- it('includes worker with age 52') { should include(User.first(:age => 64)) }
- it('does not include worker with age 51') { should_not include(User.first(:age => 65)) }
+ subject { User.page(5).all(:age.lte => 80, :order => [:age.asc]).per(13) }
+ it('includes user with age 52') { should include(User.first(:age => 52)) }
+ it('does not include user with age 51') { should_not include(User.first(:age => 51)) }
+ it('includes user with age 52') { should include(User.first(:age => 64)) }
+ it('does not include user with age 51') { should_not include(User.first(:age => 65)) }
its(:current_page) { should == 5 }
its('query.limit') { should == 13 }
its('query.offset') { should == 52 }
- its(:total_count) { should == 101 }
- its(:num_pages) { should == 8 }
+ its(:total_count) { should == 81 }
+ its(:num_pages) { should == 7 }
end
context 'on chained queries' do
- subject { User.all(:age.gte => 50).page(3).all(:age.lte => 100).per(13) }
+ subject { User.all(:age.gte => 50).page(3).all(:age.lte => 80).per(13) }
its(:current_page) { should == 3 }
its('query.limit') { should == 13 }
its('query.offset') { should == 26 }
- its(:total_count) { should == 51 }
- its(:num_pages) { should == 4 }
+ its(:total_count) { should == 31 }
+ its(:num_pages) { should == 3 }
end
context 'on query on association' do

0 comments on commit 480b78a

Please sign in to comment.
Something went wrong with that request. Please try again.