Skip to content

Commit

Permalink
fix vanishing mongoid criteria after calling #page
Browse files Browse the repository at this point in the history
  • Loading branch information
tyok committed Feb 23, 2011
1 parent 3cf08e5 commit f1641dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/kaminari/models/mongoid_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ module Criteria
extend ActiveSupport::Concern

included do
delegate :page, :per, :num_pages, :current_page, :limit_value, :offset_value, :pagination_count, :to => '@klass'
def page(*args)
self.klass.page(*args).criteria.merge(self)
end
end
end

Expand Down
20 changes: 20 additions & 0 deletions spec/models/mongoid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
before :all do
class Developer
include ::Mongoid::Document
field :value, :type => Integer
end
end
before do
Expand Down Expand Up @@ -39,6 +40,25 @@ class Developer
its(:num_pages) { should == 12 }
it { should skip 0 }
end

context 'with criteria before' do
subject { Developer.where(:value => 1).page 2 }
its(:selector) { should == {:value => 1} }
its(:current_page) { should == 2 }
its(:limit_value) { should == 25 }
its(:num_pages) { should == 12 }
it { should skip 25 }
end

context 'with criteria after' do
subject { Developer.page(2).where(:value => 1) }
its(:selector) { should == {:value => 1} }
its(:current_page) { should == 2 }
its(:limit_value) { should == 25 }
its(:num_pages) { should == 12 }
it { should skip 25 }
end

end

describe '#per' do
Expand Down

0 comments on commit f1641dc

Please sign in to comment.