diff --git a/lib/kaminari/hooks.rb b/lib/kaminari/hooks.rb index 48d718a..0a8911c 100644 --- a/lib/kaminari/hooks.rb +++ b/lib/kaminari/hooks.rb @@ -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 diff --git a/lib/kaminari/models/mongoid_extension.rb b/lib/kaminari/models/mongoid_extension.rb index 8b2f8bc..eb50cd0 100644 --- a/lib/kaminari/models/mongoid_extension.rb +++ b/lib/kaminari/models/mongoid_extension.rb @@ -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 diff --git a/spec/models/mongoid/mongoid_spec.rb b/spec/models/mongoid/mongoid_spec.rb index cacc0d1..08c4e1f 100644 --- a/spec/models/mongoid/mongoid_spec.rb +++ b/spec/models/mongoid/mongoid_spec.rb @@ -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