1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

Do not override Mongoid::Criteria#page defined by scope

so we don't have to worry about runtime persistence. closes #326
This commit is contained in:
Yuki Nishijima 2014-03-08 21:34:51 -08:00
parent d4a7ca2123
commit 2769f32ec1
3 changed files with 17 additions and 13 deletions

View file

@ -18,7 +18,6 @@ module Kaminari
begin; require 'mongoid'; rescue LoadError; end
if defined? ::Mongoid
require 'kaminari/models/mongoid_extension'
::Mongoid::Criteria.send :include, Kaminari::MongoidExtension::Criteria
::Mongoid::Document.send :include, Kaminari::MongoidExtension::Document
end

View file

@ -2,18 +2,6 @@ require 'kaminari/models/mongoid_criteria_methods'
module Kaminari
module MongoidExtension
module Criteria
extend ActiveSupport::Concern
included do
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{Kaminari.config.page_method_name}(*args)
super(*args).criteria.merge(self)
end
RUBY
end
end
module Document
extend ActiveSupport::Concern
include Kaminari::ConfigurationMethods

View file

@ -120,6 +120,23 @@ if defined? Mongoid
subject { User.page(2).where(:salary => 1) }
it_should_behave_like 'complete valid pagination'
end
context "with database:", :if => Mongoid::VERSION >= '3' do
before :all do
15.times { User.with(database: "default_db").create!(:salary => 1) }
10.times { User.with(database: "other_db").create!(:salary => 1) }
end
context "default_db" do
subject { User.with(database: "default_db").order_by(:artist.asc).page(1) }
its(:total_count) { should == 15 }
end
context "other_db" do
subject { User.with(database: "other_db").order_by(:artist.asc).page(1) }
its(:total_count) { should == 10 }
end
end
end
describe '#per' do