for the container tag
== 0.7.0
* Ajaxified paginator templates
== 0.6.0
* Hamlized paginator templates
== 0.5.0
* reset content_for :kaminari_paginator_tags before rendering #1 [hsbt]
== 0.4.0
* partialize the outer div
== 0.3.0
* suppress logging when rendering each partial
== 0.2.0
* default PER_PAGE to 25 [hsbt]
== 0.1.0
* First release
kaminari-0.16.3/MIT-LICENSE 0000644 0000041 0000041 00000002041 12477441644 015072 0 ustar www-data www-data Copyright (c) 2011 Akira Matsuda
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kaminari-0.16.3/spec/ 0000755 0000041 0000041 00000000000 12477441644 014373 5 ustar www-data www-data kaminari-0.16.3/spec/spec_helper.rb 0000644 0000041 0000041 00000001505 12477441644 017212 0 ustar www-data www-data $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
begin
require 'rails'
rescue LoadError
end
require 'bundler/setup'
Bundler.require
require 'capybara/rspec'
require 'database_cleaner'
# Simulate a gem providing a subclass of ActiveRecord::Base before the Railtie is loaded.
require 'fake_gem' if defined? ActiveRecord
if defined? Rails
require 'fake_app/rails_app'
require 'rspec/rails'
end
if defined? Sinatra
require 'spec_helper_for_sinatra'
end
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rr
config.filter_run_excluding :generator_spec => true if !ENV['GENERATOR_SPEC']
end
kaminari-0.16.3/spec/requests/ 0000755 0000041 0000041 00000000000 12477441644 016246 5 ustar www-data www-data kaminari-0.16.3/spec/requests/users_spec.rb 0000644 0000041 0000041 00000002126 12477441644 020747 0 ustar www-data www-data # encoding: UTF-8
require 'spec_helper'
feature 'Users' do
background do
1.upto(100) {|i| User.create! :name => "user#{'%03d' % i}" }
end
scenario 'navigating by pagination links' do
visit '/users'
within 'nav.pagination' do
within 'span.page.current' do
page.should have_content '1'
end
within 'span.next' do
click_link 'Next ›'
end
end
within 'nav.pagination' do
within 'span.page.current' do
page.should have_content '2'
end
within 'span.last' do
click_link 'Last »'
end
end
within 'nav.pagination' do
within 'span.page.current' do
page.should have_content '4'
end
within 'span.prev' do
click_link '‹ Prev'
end
end
within 'nav.pagination' do
within 'span.page.current' do
page.should have_content '3'
end
within 'span.first' do
click_link '« First'
end
end
within 'nav.pagination' do
within 'span.page.current' do
page.should have_content '1'
end
end
end
end
kaminari-0.16.3/spec/config/ 0000755 0000041 0000041 00000000000 12477441644 015640 5 ustar www-data www-data kaminari-0.16.3/spec/config/config_spec.rb 0000644 0000041 0000041 00000003707 12477441644 020453 0 ustar www-data www-data require 'spec_helper'
describe Kaminari::Configuration do
subject { Kaminari.config }
describe 'default_per_page' do
context 'by default' do
its(:default_per_page) { should == 25 }
end
context 'configured via config block' do
before do
Kaminari.configure {|c| c.default_per_page = 17}
end
its(:default_per_page) { should == 17 }
after do
Kaminari.configure {|c| c.default_per_page = 25}
end
end
end
describe 'max_per_page' do
context 'by default' do
its(:max_per_page) { should == nil }
end
context 'configure via config block' do
before do
Kaminari.configure {|c| c.max_per_page = 100}
end
its(:max_per_page) { should == 100 }
after do
Kaminari.configure {|c| c.max_per_page = nil}
end
end
end
describe 'window' do
context 'by default' do
its(:window) { should == 4 }
end
end
describe 'outer_window' do
context 'by default' do
its(:outer_window) { should == 0 }
end
end
describe 'left' do
context 'by default' do
its(:left) { should == 0 }
end
end
describe 'right' do
context 'by default' do
its(:right) { should == 0 }
end
end
describe 'param_name' do
context 'by default' do
its(:param_name) { should == :page }
end
context 'configured via config block' do
before do
Kaminari.configure {|c| c.param_name = lambda { :test } }
end
its(:param_name) { should == :test }
after do
Kaminari.configure {|c| c.param_name = :page }
end
end
end
describe 'max_pages' do
context 'by default' do
its(:max_pages) { should == nil }
end
context 'configure via config block' do
before do
Kaminari.configure {|c| c.max_pages = 5}
end
its(:max_pages) { should == 5 }
after do
Kaminari.configure {|c| c.max_pages = nil}
end
end
end
end
kaminari-0.16.3/spec/generators/ 0000755 0000041 0000041 00000000000 12477441644 016544 5 ustar www-data www-data kaminari-0.16.3/spec/generators/views_generator_spec.rb 0000644 0000041 0000041 00000001066 12477441644 023311 0 ustar www-data www-data require 'spec_helper'
if defined?(Rails)
require 'rails/generators'
require 'generators/kaminari/views_generator'
describe Kaminari::Generators::GitHubApiHelper, :generator_spec => true do
describe '.get_files_in_master' do
subject { Kaminari::Generators::GitHubApiHelper.get_files_in_master }
it { should include(["README", "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"]) }
end
describe '.get_content_for' do
subject { Kaminari::Generators::GitHubApiHelper.get_content_for("README") }
it { should == "" }
end
end
end
kaminari-0.16.3/spec/models/ 0000755 0000041 0000041 00000000000 12477441644 015656 5 ustar www-data www-data kaminari-0.16.3/spec/models/mongoid/ 0000755 0000041 0000041 00000000000 12477441644 017312 5 ustar www-data www-data kaminari-0.16.3/spec/models/mongoid/mongoid_spec.rb 0000644 0000041 0000041 00000017053 12477441644 022313 0 ustar www-data www-data require 'spec_helper'
if defined? Mongoid
describe Kaminari::MongoidCriteriaMethods do
describe "#total_count" do
before do
2.times {|i| User.create!(:salary => i) }
end
context "when the scope is cloned" do
it "should reset total_coount momoization" do
User.page.tap(&:total_count).where(:salary => 1).total_count.should == 1
end
end
end
end
describe Kaminari::MongoidExtension do
before(:each) do
41.times do
User.create!({:salary => 1})
end
end
describe 'max_scan', :if => Mongoid::VERSION >= '3' do
context 'less than total' do
context 'page 1' do
subject { User.max_scan(20).page 1 }
it { should be_a Mongoid::Criteria }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should be_nil }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 1 }
its(:total_count) { should == 20 }
it { should skip(0) }
end
context 'page 2' do
subject { User.max_scan(30).page 2 }
it { should be_a Mongoid::Criteria }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should be_nil }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 2 }
its(:total_count) { should == 30 }
it { should skip 25 }
end
end
context 'more than total' do
context 'page 1' do
subject { User.max_scan(60).page 1 }
it { should be_a Mongoid::Criteria }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 2 }
its(:total_count) { should == 41 }
it { should skip(0) }
end
context 'page 2' do
subject { User.max_scan(60).page 2 }
it { should be_a Mongoid::Criteria }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should be_nil }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 2 }
its(:total_count) { should == 41 }
it { should skip 25 }
end
end
end
describe '#page' do
context 'page 1' do
subject { User.page 1 }
it { should be_a Mongoid::Criteria }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 2 }
it { should skip(0) }
end
context 'page 2' do
subject { User.page 2 }
it { should be_a Mongoid::Criteria }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should be_nil }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 2 }
it { should skip 25 }
end
context 'page "foobar"' do
subject { User.page 'foobar' }
it { should be_a Mongoid::Criteria }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 2 }
it { should skip 0 }
end
shared_examples 'complete valid pagination' do
if Mongoid::VERSION > '3.0.0'
its(:selector) { should == {'salary' => 1} }
else
its(:selector) { should == {:salary => 1} }
end
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should be_nil }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 2 }
it { should skip 25 }
end
context 'with criteria before' do
subject { User.where(:salary => 1).page 2 }
it_should_behave_like 'complete valid pagination'
end
context 'with criteria after' do
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
subject { User.page(2).per(10) }
it { should be_a Mongoid::Criteria }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should == 3 }
its(:limit_value) { should == 10 }
its(:total_pages) { should == 5 }
it { should skip 10 }
end
describe '#page in embedded documents' do
before do
@mongo_developer = MongoMongoidExtensionDeveloper.new
@mongo_developer.frameworks.new(:name => "rails", :language => "ruby")
@mongo_developer.frameworks.new(:name => "merb", :language => "ruby")
@mongo_developer.frameworks.new(:name => "sinatra", :language => "ruby")
@mongo_developer.frameworks.new(:name => "cakephp", :language => "php")
@mongo_developer.frameworks.new(:name => "tornado", :language => "python")
end
context 'page 1' do
subject { @mongo_developer.frameworks.page(1).per(1) }
it { should be_a Mongoid::Criteria }
its(:total_count) { should == 5 }
its(:limit_value) { should == 1 }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its(:total_pages) { should == 5 }
end
context 'with criteria after' do
subject { @mongo_developer.frameworks.page(1).per(2).where(:language => "ruby") }
it { should be_a Mongoid::Criteria }
its(:total_count) { should == 3 }
its(:limit_value) { should == 2 }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its(:total_pages) { should == 2 }
end
context 'with criteria before' do
subject { @mongo_developer.frameworks.where(:language => "ruby").page(1).per(2) }
it { should be_a Mongoid::Criteria }
its(:total_count) { should == 3 }
its(:limit_value) { should == 2 }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its(:total_pages) { should == 2 }
end
end
describe '#paginates_per' do
context 'when paginates_per is not defined in superclass' do
subject { Product.all.page 1 }
its(:limit_value) { should == 25 }
end
context 'when paginates_per is defined in subclass' do
subject { Device.all.page 1 }
its(:limit_value) { should == 100 }
end
context 'when paginates_per is defined in subclass of subclass' do
subject { Android.all.page 1 }
its(:limit_value) { should == 200 }
end
end
end
end
kaminari-0.16.3/spec/models/active_record/ 0000755 0000041 0000041 00000000000 12477441644 020467 5 ustar www-data www-data kaminari-0.16.3/spec/models/active_record/scopes_spec.rb 0000644 0000041 0000041 00000017172 12477441644 023332 0 ustar www-data www-data require 'spec_helper'
if defined? ActiveRecord
describe Kaminari::ActiveRecordModelExtension do
before do
Kaminari.configure do |config|
config.page_method_name = :per_page_kaminari
end
class Comment < ActiveRecord::Base; end
end
subject { Comment }
it { should respond_to(:per_page_kaminari) }
it { should_not respond_to(:page) }
after do
Kaminari.configure do |config|
config.page_method_name = :page
end
end
end
shared_examples_for 'the first page' do
it { should have(25).users }
its('first.name') { should == 'user001' }
end
shared_examples_for 'blank page' do
it { should have(0).users }
end
describe Kaminari::ActiveRecordExtension do
before :all do
[User, GemDefinedModel, Device].each do |m|
1.upto(100) {|i| m.create! :name => "user#{'%03d' % i}", :age => (i / 10)}
end
end
after :all do
[User, GemDefinedModel, Device].each {|m| m.delete_all }
end
[User, Admin, GemDefinedModel, Device].each do |model_class|
context "for #{model_class}" do
describe '#page' do
context 'page 1' do
subject { model_class.page 1 }
it_should_behave_like 'the first page'
end
context 'page 2' do
subject { model_class.page 2 }
it { should have(25).users }
its('first.name') { should == 'user026' }
end
context 'page without an argument' do
subject { model_class.page }
it_should_behave_like 'the first page'
end
context 'page < 1' do
subject { model_class.page 0 }
it_should_behave_like 'the first page'
end
context 'page > max page' do
subject { model_class.page 5 }
it_should_behave_like 'blank page'
end
describe 'ensure #order_values is preserved' do
subject { model_class.order('id').page 1 }
its('order_values.uniq') { should == ['id'] }
end
end
describe '#per' do
context 'page 1 per 5' do
subject { model_class.page(1).per(5) }
it { should have(5).users }
its('first.name') { should == 'user001' }
end
context "page 1 per nil (using default)" do
subject { model_class.page(1).per(nil) }
it { should have(model_class.default_per_page).users }
end
end
describe '#padding' do
context 'page 1 per 5 padding 1' do
subject { model_class.page(1).per(5).padding(1) }
it { should have(5).users }
its('first.name') { should == 'user002' }
end
context 'page 19 per 5 padding 5' do
subject { model_class.page(19).per(5).padding(5) }
its(:current_page) { should == 19 }
its(:total_pages) { should == 19 }
end
end
describe '#total_pages' do
context 'per 25 (default)' do
subject { model_class.page }
its(:total_pages) { should == 4 }
end
context 'per 7' do
subject { model_class.page(2).per(7) }
its(:total_pages) { should == 15 }
end
context 'per 65536' do
subject { model_class.page(50).per(65536) }
its(:total_pages) { should == 1 }
end
context 'per 0 (using default)' do
subject { model_class.page(50).per(0) }
its(:total_pages) { should == 4 }
end
context 'per -1 (using default)' do
subject { model_class.page(5).per(-1) }
its(:total_pages) { should == 4 }
end
context 'per "String value that can not be converted into Number" (using default)' do
subject { model_class.page(5).per('aho') }
its(:total_pages) { should == 4 }
end
context 'with max_pages < total pages count from database' do
before { model_class.max_pages_per 3 }
subject { model_class.page }
its(:total_pages) { should == 3 }
after { model_class.max_pages_per nil }
end
context 'with max_pages > total pages count from database' do
before { model_class.max_pages_per 11 }
subject { model_class.page }
its(:total_pages) { should == 4 }
after { model_class.max_pages_per nil }
end
context 'with max_pages is nil' do
before { model_class.max_pages_per nil }
subject { model_class.page }
its(:total_pages) { should == 4 }
end
context "with per(nil) using default" do
subject { model_class.page.per(nil) }
its(:total_pages) { should == 4 }
end
end
describe '#current_page' do
context 'page 1' do
subject { model_class.page }
its(:current_page) { should == 1 }
end
context 'page 2' do
subject { model_class.page(2).per 3 }
its(:current_page) { should == 2 }
end
end
describe '#next_page' do
context 'page 1' do
subject { model_class.page }
its(:next_page) { should == 2 }
end
context 'page 5' do
subject { model_class.page(5) }
its(:next_page) { should be_nil }
end
end
describe '#prev_page' do
context 'page 1' do
subject { model_class.page }
its(:prev_page) { should be_nil }
end
context 'page 5' do
subject { model_class.page(5) }
its(:prev_page) { should == 4 }
end
end
describe '#first_page?' do
context 'on first page' do
subject { model_class.page(1).per(10) }
its(:first_page?) { should == true }
end
context 'not on first page' do
subject { model_class.page(5).per(10) }
its(:first_page?) { should == false }
end
end
describe '#last_page?' do
context 'on last page' do
subject { model_class.page(10).per(10) }
its(:last_page?) { should == true }
end
context 'not on last page' do
subject { model_class.page(1).per(10) }
its(:last_page?) { should == false }
end
end
describe '#out_of_range?' do
context 'on last page' do
subject { model_class.page(10).per(10) }
its(:out_of_range?) { should == false }
end
context 'within range' do
subject { model_class.page(1).per(10) }
its(:out_of_range?) { should == false }
end
context 'out of range' do
subject { model_class.page(11).per(10) }
its(:out_of_range?) { should == true }
end
end
describe '#count' do
context 'page 1' do
subject { model_class.page }
its(:count) { should == 25 }
end
context 'page 2' do
subject { model_class.page 2 }
its(:count) { should == 25 }
end
end
context 'chained with .group' do
subject { model_class.group('age').page(2).per 5 }
# 0..10
its(:total_count) { should == 11 }
its(:total_pages) { should == 3 }
end
context 'activerecord descendants' do
subject { ActiveRecord::Base.descendants }
its(:length) { should_not == 0 }
end
end
end
end
end
kaminari-0.16.3/spec/models/active_record/active_record_relation_methods_spec.rb 0000644 0000041 0000041 00000005745 12477441644 030272 0 ustar www-data www-data require 'spec_helper'
if defined? ActiveRecord
describe Kaminari::ActiveRecordRelationMethods do
describe '#total_count' do
before do
@author = User.create! :name => 'author'
@author2 = User.create! :name => 'author2'
@author3 = User.create! :name => 'author3'
@books = 2.times.map {|i| @author.books_authored.create!(:title => "title%03d" % i) }
@books2 = 3.times.map {|i| @author2.books_authored.create!(:title => "title%03d" % i) }
@books3 = 4.times.map {|i| @author3.books_authored.create!(:title => "subject%03d" % i) }
@readers = 4.times.map { User.create! :name => 'reader' }
@books.each {|book| book.readers << @readers }
end
context "when the scope is cloned" do
it "should reset total_coount momoization" do
User.page.tap(&:total_count).where(:name => 'author').total_count.should == 1
end
end
context "when the scope includes an order which references a generated column" do
it "should successfully count the results" do
@author.readers.by_read_count.page(1).total_count.should == @readers.size
end
end
context "when the scope use conditions on includes" do
it "should keep includes and successfully count the results" do
# Only @author and @author2 have books titled with the title00x partern
if ActiveRecord::VERSION::STRING >= "4.1.0"
User.includes(:books_authored).references(:books).where("books.title LIKE 'title00%'").page(1).total_count.should == 2
else
User.includes(:books_authored).where("books.title LIKE 'title00%'").page(1).total_count.should == 2
end
end
end
context 'when the Relation has custom select clause' do
specify do
lambda { User.select('*, 1 as one').page(1).total_count }.should_not raise_exception
end
end
context "when total_count receives options" 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
end
it "should ignore the options for rails 4.1+" do
if ActiveRecord::VERSION::STRING >= "4.1.0"
User.page(1).total_count(:name, :distinct => true).should == 7
end
end
end
if ActiveRecord::VERSION::STRING < '4.1.0'
context 'when count receives options' do
it 'should return a distinct set by column for rails < 4.1' do
User.page(1).count(:name, :distinct => true).should == 4
end
end
end
context "when the scope returns an ActiveSupport::OrderedHash" do
it "should not throw exception by passing options to count" do
lambda {
@author.readers.by_read_count.page(1).total_count(:name, :distinct => true)
}.should_not raise_exception
end
end
end
end
end
kaminari-0.16.3/spec/models/active_record/inherited_spec.rb 0000644 0000041 0000041 00000000364 12477441644 024004 0 ustar www-data www-data require 'spec_helper'
if defined? ActiveRecord
describe Kaminari::ActiveRecordModelExtension do
subject { Class.new(ActiveRecord::Base) }
it { should respond_to :page }
it { should respond_to :fake_gem_defined_method }
end
end
kaminari-0.16.3/spec/models/configuration_methods_spec.rb 0000644 0000041 0000041 00000005453 12477441644 023616 0 ustar www-data www-data 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
kaminari-0.16.3/spec/models/data_mapper/ 0000755 0000041 0000041 00000000000 12477441644 020133 5 ustar www-data www-data kaminari-0.16.3/spec/models/data_mapper/data_mapper_spec.rb 0000644 0000041 0000041 00000015652 12477441644 023760 0 ustar www-data www-data require 'spec_helper'
if defined? DataMapper
# tests for issue #203
describe Kaminari::DataMapperCollectionMethods do
before do
30.times do |i|
User.create(:name => "User#{i}", :age => i)
end
end
describe 'Model' do
subject { User }
it { User.all.count.should == 30 }
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
end
describe Kaminari::DataMapperExtension do
before do
90.times do |i|
User.create(:name => "User#{i}", :age => i)
end
end
describe 'Collection' do
subject{ User.all }
it { should respond_to(:page) }
it { should_not respond_to(:per) }
end
describe 'Model' do
subject{ User }
it { should respond_to(:page) }
it { should respond_to(:default_per_page) }
it { should_not respond_to(:per) }
end
describe '#page' do
context 'page 0' do
subject { User.all(:age.gte => 60).page 0 }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its('query.limit') { should == 25 }
its('query.offset') { should == 0 }
its(:total_count) { should == User.count(:age.gte => 60) }
its(:total_pages) { should == 2 }
end
context 'page 1' do
subject { User.all(:age.gte => 0).page 1 }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its('query.limit') { should == 25 }
its('query.offset') { should == 0 }
its(:total_count) { should == 90 }
its(:total_pages) { should == 4 }
end
context 'page 2' do
subject { User.page 2 }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should == 3 }
its(:limit_value) { should == 25 }
its('query.limit') { should == 25 }
its('query.offset') { should == 25 }
its(:total_count) { should == 90 }
its(:total_pages) { should == 4 }
end
context 'page "foobar"' do
subject { User.page 'foobar' }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its('query.limit') { should == 25 }
its('query.offset') { should == 0 }
its(:total_count) { should == 90 }
its(:total_pages) { should == 4 }
end
context 'with criteria before' do
subject { User.all(:age.gt => 60).page 2 }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should be_nil }
its('query.limit') { should == 25 }
its('query.offset') { should == 25 }
its(:total_count) { should == User.count(:age.gt => 60) }
its(:total_pages) { should == 2 }
end
context 'with criteria after' do
subject { User.page(2).all(:age.gt => 60) }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should be_nil }
its('query.limit') { should == 25 }
its('query.offset') { should == 25 }
its(:total_count) { should == User.count(:age.gt => 60) }
its(:total_pages) { should == 2 }
end
end
describe '#per' do
context 'on simple query' do
subject { User.page(2).per(20) }
it { should be_a DataMapper::Collection }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should == 3 }
its('query.limit') { should == 20 }
its(:limit_value) { should == 20 }
its('query.offset') { should == 20 }
its(:total_count) { should == 90 }
its(:total_pages) { should == 5 }
end
context 'on query with condition' do
subject { User.page(5).all(:age.lte => 80).per(13) }
its(:current_page) { should == 5 }
its(:prev_page) { should == 4 }
its(:next_page) { should == 6 }
its('query.limit') { should == 13 }
its('query.offset') { should == 52 }
its(:total_count) { should == 81 }
its(:total_pages) { should == 7 }
end
context 'on query with order' do
subject { User.page(5).all(:age.lte => 80, :order => [:age.asc]).per(13) }
it('includes user with age 52') { should include(User.first(:age => 52)) }
it('does not include user with age 51') { should_not include(User.first(:age => 51)) }
it('includes user with age 52') { should include(User.first(:age => 64)) }
it('does not include user with age 51') { should_not include(User.first(:age => 65)) }
its(:current_page) { should == 5 }
its(:prev_page) { should == 4 }
its(:next_page) { should == 6 }
its('query.limit') { should == 13 }
its('query.offset') { should == 52 }
its(:total_count) { should == 81 }
its(:total_pages) { should == 7 }
end
context 'on chained queries' do
subject { User.all(:age.gte => 50).page(3).all(:age.lte => 80).per(13) }
its(:current_page) { should == 3 }
its(:prev_page) { should == 2 }
its(:next_page) { should be_nil }
its('query.limit') { should == 13 }
its('query.offset') { should == 26 }
its(:total_count) { should == 31 }
its(:total_pages) { should == 3 }
end
context 'for association' do
before do
worker0 = User[0]
30.times do |i|
worker0.projects << Project.create(:name => "Project#{i}")
end
worker0.projects.save
end
context 'on query' do
subject { User[0].projects.page(3).all(:name.like => 'Project%').per(5) }
its(:current_page) { should == 3 }
its(:prev_page) { should == 2 }
its(:next_page) { should == 4 }
its('query.limit') { should == 5 }
its('query.offset') { should == 10 }
its(:total_count) { should == 30 }
its(:total_pages) { should == 6 }
end
context 'after association conditions' do
subject { User.page(3).all(:projects => Project.all).per(5) }
its(:current_page) { should == 3 }
its(:prev_page) { should == 2 }
its(:next_page) { should == 4 }
its('query.limit') { should == 5 }
its('query.offset') { should == 10 }
its(:total_count) { should == 30 }
its(:total_pages) { should == 6 }
end
end
end
end
end
kaminari-0.16.3/spec/models/mongo_mapper/ 0000755 0000041 0000041 00000000000 12477441644 020341 5 ustar www-data www-data kaminari-0.16.3/spec/models/mongo_mapper/mongo_mapper_spec.rb 0000644 0000041 0000041 00000005100 12477441644 024357 0 ustar www-data www-data require 'spec_helper'
if defined? MongoMapper
describe Kaminari::MongoMapperExtension do
before(:each) do
User.destroy_all
41.times { User.create!({:salary => 1}) }
end
describe '#page' do
context 'page 1' do
subject { User.page(1) }
it { should be_a Plucky::Query }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 2 }
it { should skip(0) }
end
context 'page 2' do
subject { User.page 2 }
it { should be_a Plucky::Query }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should be_nil }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 2 }
it { should skip 25 }
end
context 'page "foobar"' do
subject { User.page 'foobar' }
it { should be_a Plucky::Query }
its(:current_page) { should == 1 }
its(:prev_page) { should be_nil }
its(:next_page) { should == 2 }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 2 }
it { should skip 0 }
end
context 'with criteria before' do
it "should have the proper criteria source" do
User.where(:salary => 1).page(2).criteria.source.should == {:salary => 1}
end
subject { User.where(:salary => 1).page 2 }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should be_nil }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 2 }
it { should skip 25 }
end
context 'with criteria after' do
it "should have the proper criteria source" do
User.where(:salary => 1).page(2).criteria.source.should == {:salary => 1}
end
subject { User.page(2).where(:salary => 1) }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should be_nil }
its(:limit_value) { should == 25 }
its(:total_pages) { should == 2 }
it { should skip 25 }
end
end
describe '#per' do
subject { User.page(2).per(10) }
it { should be_a Plucky::Query }
its(:current_page) { should == 2 }
its(:prev_page) { should == 1 }
its(:next_page) { should == 3 }
its(:limit_value) { should == 10 }
its(:total_pages) { should == 5 }
it { should skip 10 }
end
end
end
kaminari-0.16.3/spec/models/array_spec.rb 0000644 0000041 0000041 00000010454 12477441644 020337 0 ustar www-data www-data require 'spec_helper'
describe Kaminari::PaginatableArray do
it { should have(0).items }
context 'specifying limit and offset when initializing' do
subject { Kaminari::PaginatableArray.new((1..100).to_a, :limit => 10, :offset => 20) }
its(:current_page) { should == 3 }
end
let(:array) { Kaminari::PaginatableArray.new((1..100).to_a) }
describe '#page' do
shared_examples_for 'the first page of array' do
it { should have(25).users }
its(:current_page) { should == 1 }
its(:first) { should == 1 }
end
shared_examples_for 'blank array page' do
it { should have(0).items }
end
context 'page 1' do
subject { array.page 1 }
it_should_behave_like 'the first page of array'
end
context 'page 2' do
subject { array.page 2 }
it { should have(25).users }
its(:current_page) { should == 2 }
its(:first) { should == 26 }
end
context 'page without an argument' do
subject { array.page }
it_should_behave_like 'the first page of array'
end
context 'page < 1' do
subject { array.page 0 }
it_should_behave_like 'the first page of array'
end
context 'page > max page' do
subject { array.page 5 }
it_should_behave_like 'blank array page'
end
end
describe '#per' do
context 'page 1 per 5' do
subject { array.page(1).per(5) }
it { should have(5).users }
its(:first) { should == 1 }
end
end
describe '#total_pages' do
context 'per 25 (default)' do
subject { array.page }
its(:total_pages) { should == 4 }
end
context 'per 7' do
subject { array.page(2).per(7) }
its(:total_pages) { should == 15 }
end
context 'per 65536' do
subject { array.page(50).per(65536) }
its(:total_pages) { should == 1 }
end
context 'per 0 (using default)' do
subject { array.page(50).per(0) }
its(:total_pages) { should == 4 }
end
context 'per -1 (using default)' do
subject { array.page(5).per(-1) }
its(:total_pages) { should == 4 }
end
context 'per "String value that can not be converted into Number" (using default)' do
subject { array.page(5).per('aho') }
its(:total_pages) { should == 4 }
end
context 'per 25, padding 25' do
subject { array.page(1).padding(25) }
its(:total_pages) { should == 3 }
end
end
describe '#current_page' do
context 'page 1' do
subject { array.page }
its(:current_page) { should == 1 }
end
context 'page 2' do
subject { array.page(2).per 3 }
its(:current_page) { should == 2 }
end
end
describe '#next_page' do
context 'page 1' do
subject { array.page }
its(:next_page) { should == 2 }
end
context 'page 5' do
subject { array.page 5 }
its(:next_page) { should be_nil }
end
end
describe '#prev_page' do
context 'page 1' do
subject { array.page }
its(:prev_page) { should be_nil }
end
context 'page 5' do
subject { array.page 5 }
its(:prev_page) { should == 4 }
end
end
describe '#count' do
context 'page 1' do
subject { array.page }
its(:count) { should == 25 }
end
context 'page 2' do
subject { array.page 2 }
its(:count) { should == 25 }
end
end
context 'when setting total count explicitly' do
context "array 1..10, page 5, per 10, total_count 9999" do
subject { Kaminari::PaginatableArray.new((1..10).to_a, :total_count => 9999).page(5).per(10) }
it { should have(10).items }
its(:first) { should == 1 }
its(:current_page) { should == 5 }
its(:total_count) { should == 9999 }
end
context "array 1..15, page 1, per 10, total_count 15" do
subject { Kaminari.paginate_array((1..15).to_a, :total_count => 15).page(1).per(10) }
it { should have(10).items }
its(:first) { should == 1 }
its(:current_page) { should == 1 }
its(:total_count) { should == 15 }
end
context "array 1..25, page 2, per 10, total_count 15" do
subject { Kaminari.paginate_array((1..25).to_a, :total_count => 15).page(2).per(10) }
it { should have(5).items }
its(:first) { should == 11 }
its(:current_page) { should == 2 }
its(:total_count) { should == 15 }
end
end
end
kaminari-0.16.3/spec/helpers/ 0000755 0000041 0000041 00000000000 12477441644 016035 5 ustar www-data www-data kaminari-0.16.3/spec/helpers/tags_spec.rb 0000644 0000041 0000041 00000012276 12477441644 020342 0 ustar www-data www-data require 'spec_helper'
include Kaminari::Helpers
describe 'Kaminari::Helpers' do
describe 'Paginator' do
describe 'Paginator::PageProxy' do
describe '#current?' do
context 'current_page == page' do
subject { Paginator::PageProxy.new({:current_page => 26}, 26, nil) }
its(:current?) { should be_true }
end
context 'current_page != page' do
subject { Paginator::PageProxy.new({:current_page => 13}, 26, nil) }
its(:current?) { should_not be_true }
end
end
describe '#first?' do
context 'page == 1' do
subject { Paginator::PageProxy.new({:current_page => 26}, 1, nil) }
its(:first?) { should be_true }
end
context 'page != 1' do
subject { Paginator::PageProxy.new({:current_page => 13}, 2, nil) }
its(:first?) { should_not be_true }
end
end
describe '#last?' do
context 'current_page == page' do
subject { Paginator::PageProxy.new({:total_pages => 39}, 39, nil) }
its(:last?) { should be_true }
end
context 'current_page != page' do
subject { Paginator::PageProxy.new({:total_pages => 39}, 38, nil) }
its(:last?) { should_not be_true }
end
end
describe '#next?' do
context 'page == current_page + 1' do
subject { Paginator::PageProxy.new({:current_page => 52}, 53, nil) }
its(:next?) { should be_true }
end
context 'page != current_page + 1' do
subject { Paginator::PageProxy.new({:current_page => 52}, 77, nil) }
its(:next?) { should_not be_true }
end
end
describe '#prev?' do
context 'page == current_page - 1' do
subject { Paginator::PageProxy.new({:current_page => 77}, 76, nil) }
its(:prev?) { should be_true }
end
context 'page != current_page + 1' do
subject { Paginator::PageProxy.new({:current_page => 77}, 80, nil) }
its(:prev?) { should_not be_true }
end
end
describe '#left_outer?' do
context 'current_page == left' do
subject { Paginator::PageProxy.new({:left => 3}, 3, nil) }
its(:left_outer?) { should be_true }
end
context 'current_page == left + 1' do
subject { Paginator::PageProxy.new({:left => 3}, 4, nil) }
its(:left_outer?) { should_not be_true }
end
context 'current_page == left + 2' do
subject { Paginator::PageProxy.new({:left => 3}, 5, nil) }
its(:left_outer?) { should_not be_true }
end
end
describe '#right_outer?' do
context 'total_pages - page > right' do
subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 6, nil) }
its(:right_outer?) { should_not be_true }
end
context 'total_pages - page == right' do
subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 7, nil) }
its(:right_outer?) { should_not be_true }
end
context 'total_pages - page < right' do
subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 8, nil) }
its(:right_outer?) { should be_true }
end
end
describe '#inside_window?' do
context 'page > current_page' do
context 'page - current_page > window' do
subject { Paginator::PageProxy.new({:current_page => 4, :window => 5}, 10, nil) }
its(:inside_window?) { should_not be_true }
end
context 'page - current_page == window' do
subject { Paginator::PageProxy.new({:current_page => 4, :window => 6}, 10, nil) }
its(:inside_window?) { should be_true }
end
context 'page - current_page < window' do
subject { Paginator::PageProxy.new({:current_page => 4, :window => 7}, 10, nil) }
its(:inside_window?) { should be_true }
end
end
context 'current_page > page' do
context 'current_page - page > window' do
subject { Paginator::PageProxy.new({:current_page => 15, :window => 4}, 10, nil) }
its(:inside_window?) { should_not be_true }
end
context 'current_page - page == window' do
subject { Paginator::PageProxy.new({:current_page => 15, :window => 5}, 10, nil) }
its(:inside_window?) { should be_true }
end
context 'current_page - page < window' do
subject { Paginator::PageProxy.new({:current_page => 15, :window => 6}, 10, nil) }
its(:inside_window?) { should be_true }
end
end
end
describe '#was_truncated?' do
before do
stub(@template = Object.new) do
options { {} }
params { {} }
end
end
context 'last.is_a? Gap' do
subject { Paginator::PageProxy.new({}, 10, Gap.new(@template)) }
its(:was_truncated?) { should be_true }
end
context 'last.is not a Gap' do
subject { Paginator::PageProxy.new({}, 10, Page.new(@template)) }
its(:was_truncated?) { should_not be_true }
end
end
end
end
end
kaminari-0.16.3/spec/helpers/action_view_extension_spec.rb 0000644 0000041 0000041 00000026064 12477441644 024007 0 ustar www-data www-data require 'spec_helper'
describe 'Kaminari::ActionViewExtension', :if => defined?(Rails)do
describe '#paginate' do
before do
50.times {|i| User.create! :name => "user#{i}"}
@users = User.page(1)
end
subject { helper.paginate @users, :params => {:controller => 'users', :action => 'index'} }
it { should be_a String }
context 'escaping the pagination for javascript' do
it 'should escape for javascript' do
lambda { helper.escape_javascript(helper.paginate @users, :params => {:controller => 'users', :action => 'index'}) }.should_not raise_error
end
end
context 'accepts :theme option' do
before { helper.controller.append_view_path "spec/fake_app/views" }
subject { helper.paginate @users, :theme => "bootstrap", :params => {:controller => 'users', :action => 'index'} }
it { should match(/bootstrap-paginator/) }
it { should match(/bootstrap-page-link/) }
end
context 'accepts :view_prefix option' do
before { helper.controller.append_view_path "spec/fake_app/views" }
subject { helper.paginate @users, :views_prefix => "alternative/", :params => {:controller => 'users', :action => 'index'} }
it { should eq("
1\n") }
end
context "num_pages: 3" do
subject { helper.paginate @users, :num_pages => 3, :params => {:controller => 'users', :action => 'index'} }
it { should match(/
Last/) }
end
end
describe '#link_to_previous_page' do
before do
50.times {|i| User.create! :name => "user#{i}"}
end
context 'having previous pages' do
before do
@users = User.page(50)
end
context 'the default behaviour' do
subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
it { should be_a String }
it { should match(/rel="previous"/) }
end
context 'overriding rel=' do
subject { helper.link_to_previous_page @users, 'Previous', :rel => 'external', :params => {:controller => 'users', :action => 'index'} }
it { should match(/rel="external"/) }
end
end
context 'the first page' do
before do
@users = User.page(1)
end
subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
it { should_not be }
end
end
describe '#link_to_next_page' do
before do
50.times {|i| User.create! :name => "user#{i}"}
end
context 'having more page' do
before do
@users = User.page(1)
end
context 'the default behaviour' do
subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
it { should be_a String }
it { should match(/rel="next"/) }
end
context 'overriding rel=' do
subject { helper.link_to_next_page @users, 'More', :rel => 'external', :params => {:controller => 'users', :action => 'index'} }
it { should match(/rel="external"/) }
end
end
context 'the last page' do
before do
@users = User.page(2)
end
subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
it { should_not be }
end
end
describe '#page_entries_info' do
context 'on a model without namespace' do
before do
@users = User.page(1).per(25)
end
context 'having no entries' do
subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
it { should == 'No users found' }
context 'setting the entry name option to "member"' do
subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
it { should == 'No members found' }
end
end
context 'having 1 entry' do
before do
User.create! :name => 'user1'
@users = User.page(1).per(25)
end
subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
it { should == 'Displaying 1 user' }
context 'setting the entry name option to "member"' do
subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
it { should == 'Displaying 1 member' }
end
end
context 'having more than 1 but less than a page of entries' do
before do
10.times {|i| User.create! :name => "user#{i}"}
@users = User.page(1).per(25)
end
subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
it { should == 'Displaying all 10 users' }
context 'setting the entry name option to "member"' do
subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
it { should == 'Displaying all 10 members' }
end
end
context 'having more than one page of entries' do
before do
50.times {|i| User.create! :name => "user#{i}"}
end
describe 'the first page' do
before do
@users = User.page(1).per(25)
end
subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
it { should == 'Displaying users 1 - 25 of 50 in total' }
context 'setting the entry name option to "member"' do
subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
it { should == 'Displaying members 1 - 25 of 50 in total' }
end
end
describe 'the next page' do
before do
@users = User.page(2).per(25)
end
subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
it { should == 'Displaying users 26 - 50 of 50 in total' }
context 'setting the entry name option to "member"' do
subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
it { should == 'Displaying members 26 - 50 of 50 in total' }
end
end
end
end
context 'on a model with namespace' do
before do
@addresses = User::Address.page(1).per(25)
end
context 'having no entries' do
subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
it { should == 'No addresses found' }
end
context 'having 1 entry' do
before do
User::Address.create!
@addresses = User::Address.page(1).per(25)
end
subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
it { should == 'Displaying 1 address' }
context 'setting the entry name option to "place"' do
subject { helper.page_entries_info @addresses, :entry_name => 'place', :params => {:controller => 'addresses', :action => 'index'} }
it { should == 'Displaying 1 place' }
end
end
context 'having more than 1 but less than a page of entries' do
before do
10.times {|i| User::Address.create!}
@addresses = User::Address.page(1).per(25)
end
subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
it { should == 'Displaying all 10 addresses' }
context 'setting the entry name option to "place"' do
subject { helper.page_entries_info @addresses, :entry_name => 'place', :params => {:controller => 'addresses', :action => 'index'} }
it { should == 'Displaying all 10 places' }
end
end
context 'having more than one page of entries' do
before do
50.times {|i| User::Address.create!}
end
describe 'the first page' do
before do
@addresses = User::Address.page(1).per(25)
end
subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
it { should == 'Displaying addresses 1 - 25 of 50 in total' }
context 'setting the entry name option to "place"' do
subject { helper.page_entries_info @addresses, :entry_name => 'place', :params => {:controller => 'addresses', :action => 'index'} }
it { should == 'Displaying places 1 - 25 of 50 in total' }
end
end
describe 'the next page' do
before do
@addresses = User::Address.page(2).per(25)
end
subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
it { should == 'Displaying addresses 26 - 50 of 50 in total' }
context 'setting the entry name option to "place"' do
subject { helper.page_entries_info @addresses, :entry_name => 'place', :params => {:controller => 'addresses', :action => 'index'} }
it { should == 'Displaying places 26 - 50 of 50 in total' }
end
end
end
end
context 'on a PaginatableArray' do
before do
@numbers = Kaminari.paginate_array(%w{one two three}).page(1)
end
subject { helper.page_entries_info @numbers }
it { should == 'Displaying all 3 entries' }
end
end
describe '#rel_next_prev_link_tags' do
before do
80.times {|i| User.create! :name => "user#{i}"}
end
context 'the first page' do
before do
@users = User.page(1).per(25)
end
subject { helper.rel_next_prev_link_tags @users, :params => {:controller => 'users', :action => 'index'} }
it { should_not match(/rel="prev"/) }
it { should match(/rel="next"/) }
it { should match(/\?page=2/) }
end
context 'the middle page' do
before do
@users = User.page(3).per(25)
end
subject { helper.rel_next_prev_link_tags @users, :params => {:controller => 'users', :action => 'index'} }
it { should match(/rel="prev"/) }
it { should match(/\?page=2/) }
it { should match(/rel="next"/) }
it { should match(/\?page=4/) }
end
context 'the last page' do
before do
@users = User.page(4).per(25)
end
subject { helper.rel_next_prev_link_tags @users, :params => {:controller => 'users', :action => 'index'} }
it { should match(/rel="prev"/) }
it { should match(/\?page=3"/) }
it { should_not match(/rel="next"/) }
end
end
end
kaminari-0.16.3/spec/helpers/sinatra_helpers_spec.rb 0000644 0000041 0000041 00000015162 12477441644 022564 0 ustar www-data www-data require 'spec_helper'
if defined? Sinatra
ERB_TEMPLATE_FOR_PAGINATE = <
<% @users.each do |user| %>
- <%= user.id %>
<% end %>
<%= paginate @users, @options %>
EOT
ERB_TEMPLATE_FOR_PREVIOUS_PAGE = <