diff --git a/lib/kaminari/models/data_mapper_extension.rb b/lib/kaminari/models/data_mapper_extension.rb index 4778da7..396dba8 100644 --- a/lib/kaminari/models/data_mapper_extension.rb +++ b/lib/kaminari/models/data_mapper_extension.rb @@ -5,8 +5,10 @@ module Kaminari module Paginatable class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{Kaminari.config.page_method_name}(num = 1) + model = self + model = self.model if self.is_a? DataMapper::Collection num = [num.to_i, 1].max - 1 - all(:limit => default_per_page, :offset => default_per_page * num).extend Paginating + all(:limit => model.default_per_page, :offset => model.default_per_page * num).extend Paginating end RUBY end diff --git a/spec/models/active_record/active_record_relation_methods_spec.rb b/spec/models/active_record/active_record_relation_methods_spec.rb index 548d7c9..fa45fcc 100644 --- a/spec/models/active_record/active_record_relation_methods_spec.rb +++ b/spec/models/active_record/active_record_relation_methods_spec.rb @@ -38,7 +38,7 @@ if defined? ActiveRecord end context "when total_count receives options" do - it "should return a distinct total count for rails ~> 4.0.0" do + it "should return a distinct total count for rails < 4.1" do if ActiveRecord::VERSION::STRING < "4.1.0" User.page(1).total_count(:name, :distinct => true).should == 4 end @@ -52,7 +52,7 @@ if defined? ActiveRecord end context "when count receives options" do - it "should return a distinct set by column for rails ~> 4.0.0" do + it "should return a distinct set by column for rails < 4.1" do if ActiveRecord::VERSION::STRING < "4.1.0" User.page(1).count(:name, :distinct => true).should == 4 end diff --git a/spec/models/data_mapper/data_mapper_spec.rb b/spec/models/data_mapper/data_mapper_spec.rb index aedcc68..f81b462 100644 --- a/spec/models/data_mapper/data_mapper_spec.rb +++ b/spec/models/data_mapper/data_mapper_spec.rb @@ -17,13 +17,13 @@ if defined? DataMapper describe 'Model' do subject { User } - its(:current_page) { should == 1 } it { User.all.count.should == 100 } it { User.page(1).length.should == 25 } it { User.paginates_per(5) User.page(1).length.should == 5 User.all.page(1).length.should == 5 + User.paginates_per(nil) # reset to default } end diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index c75f500..05a5c13 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -5,8 +5,6 @@ DatabaseCleaner[:mongo_mapper].strategy = :truncation if defined? MongoMapper RSpec.configure do |config| config.before :suite do - #DatabaseCleaner.clean_with :truncation - DatabaseCleaner.clean_with :truncation if defined? ActiveRecord DatabaseCleaner.clean_with :truncation if defined? DataMapper DatabaseCleaner.clean_with :truncation if defined? Mongoid