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

Add tests for configuration methods

This commit also includes fix for configuration methods of DataMapper and MongoMapper collection. Closes #280.
This commit is contained in:
Yuki Nishijima 2013-11-18 10:48:21 +09:00
parent de1e8d5dbe
commit 408d26d7ff
6 changed files with 129 additions and 89 deletions

View file

@ -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

View file

@ -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]

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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