diff --git a/lib/kaminari/models/data_mapper_extension.rb b/lib/kaminari/models/data_mapper_extension.rb index 396dba8..409c307 100644 --- a/lib/kaminari/models/data_mapper_extension.rb +++ b/lib/kaminari/models/data_mapper_extension.rb @@ -28,9 +28,10 @@ module Kaminari module Collection extend ActiveSupport::Concern included do - include Kaminari::ConfigurationMethods::ClassMethods include Kaminari::DataMapperCollectionMethods include Paginatable + + delegate :default_per_page, :max_per_page, :max_pages, :to => :model end end diff --git a/lib/kaminari/models/plucky_criteria_methods.rb b/lib/kaminari/models/plucky_criteria_methods.rb index 3edc9a8..7845052 100644 --- a/lib/kaminari/models/plucky_criteria_methods.rb +++ b/lib/kaminari/models/plucky_criteria_methods.rb @@ -1,7 +1,8 @@ module Kaminari module PluckyCriteriaMethods include Kaminari::PageScopeMethods - include Kaminari::ConfigurationMethods::ClassMethods + + delegate :default_per_page, :max_per_page, :max_pages, :to => :model def limit_value #:nodoc: options[:limit] diff --git a/spec/models/active_record/default_per_page_spec.rb b/spec/models/active_record/default_per_page_spec.rb deleted file mode 100644 index 5e32708..0000000 --- a/spec/models/active_record/default_per_page_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'spec_helper' - -if defined? ActiveRecord - - describe 'default per_page' do - describe 'AR::Base' do - subject { ActiveRecord::Base } - it { should_not respond_to :paginates_per } - end - - subject { User.page 0 } - - context 'by default' do - its(:limit_value) { should == 25 } - end - - context 'when explicitly set via paginates_per' do - before { User.paginates_per 1326 } - its(:limit_value) { should == 1326 } - after { User.paginates_per nil } - end - - describe "default per_page value's independency per model" do - context "when User's default per_page was changed" do - before { User.paginates_per 1326 } - subject { Book.page 0 } - its(:limit_value) { should == 25 } - after { User.paginates_per nil } - end - end - end -end diff --git a/spec/models/active_record/max_pages_spec.rb b/spec/models/active_record/max_pages_spec.rb deleted file mode 100644 index 91d8c95..0000000 --- a/spec/models/active_record/max_pages_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'spec_helper' - -if defined? ActiveRecord - - describe 'max pages' do - describe 'AR::Base' do - subject { ActiveRecord::Base } - it { should_not respond_to :max_pages_per } - end - - subject { User.page 0 } - - context 'by default' do - its(:max_pages) { should == nil } - end - - context 'when explicitly set via max_pages_per' do - before { User.max_pages_per 3 } - its(:max_pages) { should == 3 } - after { User.max_pages_per nil } - end - end -end diff --git a/spec/models/active_record/max_per_page_spec.rb b/spec/models/active_record/max_per_page_spec.rb deleted file mode 100644 index 9e0fa42..0000000 --- a/spec/models/active_record/max_per_page_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'spec_helper' - -if defined? ActiveRecord - - describe 'max per_page' do - describe 'AR::Base' do - subject { ActiveRecord::Base } - it { should_not respond_to :max_paginates_per } - end - - subject { User.page(0).per(100) } - - context 'by default' do - its(:limit_value) { should == 100 } - end - - context 'when explicitly set via max_paginates_per' do - before { User.max_paginates_per 10 } - its(:limit_value) { should == 10 } - after { User.max_paginates_per nil } - end - - describe "max per_page value's independency per model" do - context "when User's max per_page was changed" do - before { User.max_paginates_per 10 } - subject { Book.page(0).per(100) } - its(:limit_value) { should == 100 } - after { User.max_paginates_per nil } - end - end - end -end diff --git a/spec/models/configuration_methods_spec.rb b/spec/models/configuration_methods_spec.rb new file mode 100644 index 0000000..78c69ac --- /dev/null +++ b/spec/models/configuration_methods_spec.rb @@ -0,0 +1,125 @@ +require 'spec_helper' + +describe "configuration methods" do + let(:model){ User } + + describe "#default_per_page" do + if defined? ActiveRecord + describe 'AR::Base' do + subject { ActiveRecord::Base } + it { should_not respond_to :paginates_per } + end + end + + subject { model.page(1) } + + context "by default" do + its(:limit_value){ should == 25 } + end + + context "when configuring both on global and model-level" do + before do + Kaminari.configure {|c| c.default_per_page = 50 } + model.paginates_per 100 + end + + its(:limit_value){ should == 100 } + end + + context "when configuring multiple times" do + before do + Kaminari.configure {|c| c.default_per_page = 10 } + Kaminari.configure {|c| c.default_per_page = 20 } + end + + its(:limit_value){ should == 20 } + end + + after do + Kaminari.configure {|c| c.default_per_page = 25 } + model.paginates_per nil + end + end + + describe "#max_per_page" do + if defined? ActiveRecord + describe 'AR::Base' do + subject { ActiveRecord::Base } + it { should_not respond_to :max_pages_per } + end + end + + subject { model.page(1).per(1000) } + + context "by default" do + its(:limit_value){ should == 1000 } + end + + context "when configuring both on global and model-level" do + before do + Kaminari.configure {|c| c.max_per_page = 50 } + model.max_paginates_per 100 + end + + its(:limit_value){ should == 100 } + end + + context "when configuring multiple times" do + before do + Kaminari.configure {|c| c.max_per_page = 10 } + Kaminari.configure {|c| c.max_per_page = 20 } + end + + its(:limit_value){ should == 20 } + end + + after do + Kaminari.configure {|c| c.max_per_page = nil } + model.max_paginates_per nil + end + end + + describe "#max_pages" do + if defined? ActiveRecord + describe 'AR::Base' do + subject { ActiveRecord::Base } + it { should_not respond_to :max_paginates_per } + end + end + + before do + 100.times do |count| + model.create!(:name => "User#{count}") + end + end + + subject { model.page(1).per(5) } + + context "by default" do + its(:total_pages){ should == 20 } + end + + context "when configuring both on global and model-level" do + before do + Kaminari.configure {|c| c.max_pages = 10 } + model.max_pages_per 15 + end + + its(:total_pages){ should == 15 } + end + + context "when configuring multiple times" do + before do + Kaminari.configure {|c| c.max_pages = 10 } + Kaminari.configure {|c| c.max_pages = 15 } + end + + its(:total_pages){ should == 15 } + end + + after do + Kaminari.configure {|c| c.max_pages = nil } + model.max_pages_per nil + end + end +end