kaminari 0.14.1 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kaminari might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.document +1 -4
- data/.gitignore +1 -0
- data/.travis.yml +52 -5
- data/{CHANGELOG → CHANGELOG.rdoc} +129 -0
- data/Gemfile +1 -1
- data/README.rdoc +66 -25
- data/Rakefile +32 -9
- data/app/views/kaminari/_first_page.html.erb +1 -1
- data/app/views/kaminari/_first_page.html.haml +1 -1
- data/app/views/kaminari/_first_page.html.slim +1 -1
- data/app/views/kaminari/_gap.html.erb +1 -1
- data/app/views/kaminari/_gap.html.haml +1 -1
- data/app/views/kaminari/_gap.html.slim +1 -1
- data/app/views/kaminari/_last_page.html.erb +1 -1
- data/app/views/kaminari/_last_page.html.haml +1 -1
- data/app/views/kaminari/_last_page.html.slim +1 -1
- data/app/views/kaminari/_next_page.html.erb +1 -1
- data/app/views/kaminari/_next_page.html.haml +1 -1
- data/app/views/kaminari/_next_page.html.slim +1 -1
- data/app/views/kaminari/_prev_page.html.erb +1 -1
- data/app/views/kaminari/_prev_page.html.haml +1 -1
- data/app/views/kaminari/_prev_page.html.slim +1 -1
- data/gemfiles/active_record_30.gemfile +25 -4
- data/gemfiles/active_record_31.gemfile +23 -4
- data/gemfiles/active_record_32.gemfile +22 -4
- data/gemfiles/active_record_40.gemfile +26 -0
- data/gemfiles/active_record_41.gemfile +25 -0
- data/gemfiles/active_record_42.gemfile +25 -0
- data/gemfiles/active_record_edge.gemfile +30 -0
- data/gemfiles/data_mapper_12.gemfile +30 -10
- data/gemfiles/mongo_mapper.gemfile +20 -2
- data/gemfiles/mongoid_30.gemfile +18 -3
- data/gemfiles/mongoid_31.gemfile +21 -0
- data/gemfiles/mongoid_40.gemfile +19 -0
- data/gemfiles/mongoid_50.gemfile +23 -0
- data/gemfiles/sinatra_13.gemfile +36 -0
- data/gemfiles/sinatra_14.gemfile +33 -0
- data/kaminari.gemspec +13 -14
- data/lib/generators/kaminari/views_generator.rb +9 -8
- data/lib/kaminari/config.rb +2 -0
- data/lib/kaminari/helpers/action_view_extension.rb +9 -28
- data/lib/kaminari/helpers/paginator.rb +38 -18
- data/lib/kaminari/helpers/sinatra_helpers.rb +41 -3
- data/lib/kaminari/helpers/tags.rb +18 -5
- data/lib/kaminari/hooks.rb +31 -15
- data/lib/kaminari/models/active_record_extension.rb +8 -8
- data/lib/kaminari/models/active_record_model_extension.rb +8 -6
- data/lib/kaminari/models/active_record_relation_methods.rb +21 -10
- data/lib/kaminari/models/array_extension.rb +17 -11
- data/lib/kaminari/models/configuration_methods.rb +16 -2
- data/lib/kaminari/models/data_mapper_collection_methods.rb +4 -0
- data/lib/kaminari/models/data_mapper_extension.rb +5 -2
- data/lib/kaminari/models/mongoid_criteria_methods.rb +18 -1
- data/lib/kaminari/models/mongoid_extension.rb +8 -15
- data/lib/kaminari/models/page_scope_methods.rb +37 -5
- data/lib/kaminari/models/plucky_criteria_methods.rb +6 -1
- data/lib/kaminari/railtie.rb +1 -1
- data/lib/kaminari/sinatra.rb +2 -0
- data/lib/kaminari/version.rb +1 -1
- data/lib/kaminari.rb +5 -4
- data/spec/config/config_spec.rb +15 -0
- data/spec/fake_app/active_record/config.rb +1 -1
- data/spec/fake_app/active_record/models.rb +9 -1
- data/spec/fake_app/mongo_mapper/config.rb +1 -1
- data/spec/fake_app/mongoid/config.rb +7 -3
- data/spec/fake_app/mongoid/models.rb +16 -0
- data/spec/fake_app/rails_app.rb +1 -0
- data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +1 -0
- data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +3 -0
- data/spec/fake_app/views/kaminari/bootstrap/_page.html.erb +1 -0
- data/spec/fake_app/views/kaminari/bootstrap/_paginator.html.erb +7 -0
- data/spec/fake_gem.rb +18 -2
- data/spec/generators/views_generator_spec.rb +18 -0
- data/spec/helpers/action_view_extension_spec.rb +68 -12
- data/spec/helpers/helpers_spec.rb +9 -0
- data/spec/helpers/sinatra_helpers_spec.rb +53 -0
- data/spec/models/active_record/active_record_relation_methods_spec.rb +48 -1
- data/spec/models/active_record/inherited_spec.rb +9 -0
- data/spec/models/active_record/scopes_spec.rb +104 -5
- data/spec/models/array_spec.rb +55 -4
- data/spec/models/configuration_methods_spec.rb +125 -0
- data/spec/models/data_mapper/data_mapper_spec.rb +76 -26
- data/spec/models/mongo_mapper/mongo_mapper_spec.rb +12 -0
- data/spec/models/mongoid/mongoid_spec.rb +119 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/spec_helper_for_sinatra.rb +2 -3
- data/spec/support/database_cleaner.rb +5 -2
- metadata +63 -87
- data/gemfiles/mongoid_24.gemfile +0 -7
- data/gemfiles/sinatra.gemfile +0 -10
- data/spec/models/active_record/default_per_page_spec.rb +0 -32
- data/spec/models/active_record/max_per_page_spec.rb +0 -32
data/lib/kaminari/version.rb
CHANGED
data/lib/kaminari.rb
CHANGED
@@ -10,15 +10,16 @@ end
|
|
10
10
|
|
11
11
|
$stderr.puts <<-EOC if !defined?(Rails) && !defined?(Sinatra) && !defined?(Grape)
|
12
12
|
warning: no framework detected.
|
13
|
-
|
13
|
+
|
14
|
+
Your Gemfile might not be configured properly.
|
14
15
|
---- e.g. ----
|
15
|
-
|
16
|
+
Rails:
|
16
17
|
gem 'kaminari'
|
17
18
|
|
18
|
-
|
19
|
+
Sinatra/Padrino:
|
19
20
|
gem 'kaminari', :require => 'kaminari/sinatra'
|
20
21
|
|
21
|
-
|
22
|
+
Grape:
|
22
23
|
gem 'kaminari', :require => 'kaminari/grape'
|
23
24
|
|
24
25
|
EOC
|
data/spec/config/config_spec.rb
CHANGED
@@ -73,4 +73,19 @@ describe Kaminari::Configuration do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
describe 'max_pages' do
|
78
|
+
context 'by default' do
|
79
|
+
its(:max_pages) { should == nil }
|
80
|
+
end
|
81
|
+
context 'configure via config block' do
|
82
|
+
before do
|
83
|
+
Kaminari.configure {|c| c.max_pages = 5}
|
84
|
+
end
|
85
|
+
its(:max_pages) { should == 5 }
|
86
|
+
after do
|
87
|
+
Kaminari.configure {|c| c.max_pages = nil}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
76
91
|
end
|
@@ -10,7 +10,7 @@ class User < ActiveRecord::Base
|
|
10
10
|
User.joins(:books_read => :authors).where(:authors_books => {:id => self})
|
11
11
|
end
|
12
12
|
|
13
|
-
scope :by_name, order(:name)
|
13
|
+
scope :by_name, lambda { order(:name) }
|
14
14
|
scope :by_read_count, lambda {
|
15
15
|
cols = if connection.adapter_name == "PostgreSQL"
|
16
16
|
column_names.map { |column| %{"users"."#{column}"} }.join(", ")
|
@@ -42,6 +42,13 @@ class User::Address < ActiveRecord::Base
|
|
42
42
|
belongs_to :user
|
43
43
|
end
|
44
44
|
|
45
|
+
# a class that uses abstract class
|
46
|
+
class Product < ActiveRecord::Base
|
47
|
+
self.abstract_class = true
|
48
|
+
end
|
49
|
+
class Device < Product
|
50
|
+
end
|
51
|
+
|
45
52
|
#migrations
|
46
53
|
class CreateAllTables < ActiveRecord::Migration
|
47
54
|
def self.up
|
@@ -51,6 +58,7 @@ class CreateAllTables < ActiveRecord::Migration
|
|
51
58
|
create_table(:readerships) {|t| t.integer :user_id; t.integer :book_id }
|
52
59
|
create_table(:authorships) {|t| t.integer :user_id; t.integer :book_id }
|
53
60
|
create_table(:user_addresses) {|t| t.string :street; t.integer :user_id }
|
61
|
+
create_table(:devices) {|t| t.string :name; t.integer :age}
|
54
62
|
end
|
55
63
|
end
|
56
64
|
ActiveRecord::Migration.verbose = false
|
@@ -1,2 +1,2 @@
|
|
1
|
-
MongoMapper.connection = Mongo::Connection.new '
|
1
|
+
MongoMapper.connection = Mongo::Connection.new '0.0.0.0', 27017
|
2
2
|
MongoMapper.database = 'kaminari_test'
|
@@ -3,13 +3,17 @@
|
|
3
3
|
# Psych does not yet support YAML 1.1 merge keys.
|
4
4
|
# Merge keys is often used in mongoid.yml
|
5
5
|
# See: http://redmine.ruby-lang.org/issues/show/4300
|
6
|
-
|
6
|
+
require 'mongoid/version'
|
7
|
+
|
8
|
+
if RUBY_VERSION >= '1.9.2' && RUBY_VERSION < '2.2.0'
|
7
9
|
YAML::ENGINE.yamler = 'syck'
|
8
10
|
end
|
9
11
|
|
10
12
|
Mongoid.configure do |config|
|
11
|
-
if Mongoid::VERSION
|
12
|
-
config.
|
13
|
+
if Mongoid::VERSION >= '5.0.0'
|
14
|
+
config.connect_to 'kaminari_test'
|
15
|
+
elsif Mongoid::VERSION > '3.0.0'
|
16
|
+
config.sessions = {:default => {:hosts => ['0.0.0.0:27017'], :database => 'kaminari_test'}}
|
13
17
|
else
|
14
18
|
config.master = Mongo::Connection.new.db('kaminari_test')
|
15
19
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
class User
|
2
2
|
include ::Mongoid::Document
|
3
|
+
if Mongoid::VERSION >= '4.0.0'
|
4
|
+
include Mongoid::Attributes::Dynamic
|
5
|
+
end
|
6
|
+
|
3
7
|
field :name, :type => String
|
4
8
|
field :age, :type => Integer
|
5
9
|
end
|
@@ -8,6 +12,18 @@ class User::Address
|
|
8
12
|
include ::Mongoid::Document
|
9
13
|
end
|
10
14
|
|
15
|
+
class Product
|
16
|
+
include ::Mongoid::Document
|
17
|
+
end
|
18
|
+
|
19
|
+
class Device < Product
|
20
|
+
paginates_per 100
|
21
|
+
end
|
22
|
+
|
23
|
+
class Android < Device
|
24
|
+
paginates_per 200
|
25
|
+
end
|
26
|
+
|
11
27
|
class MongoMongoidExtensionDeveloper
|
12
28
|
include ::Mongoid::Document
|
13
29
|
field :salary, :type => Integer
|
data/spec/fake_app/rails_app.rb
CHANGED
@@ -11,6 +11,7 @@ app = Class.new(Rails::Application)
|
|
11
11
|
app.config.secret_token = '3b7cd727ee24e8444053437c36cc66c4'
|
12
12
|
app.config.session_store :cookie_store, :key => '_myapp_session'
|
13
13
|
app.config.active_support.deprecation = :log
|
14
|
+
app.config.eager_load = false
|
14
15
|
# Rais.root
|
15
16
|
app.config.root = File.dirname(__FILE__)
|
16
17
|
Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1 @@
|
|
1
|
+
<b><%= current_page %></b>
|
@@ -0,0 +1 @@
|
|
1
|
+
<li class="bootstrap-page-link"><%= link_to page, url %></li>
|
data/spec/fake_gem.rb
CHANGED
@@ -1,4 +1,20 @@
|
|
1
|
-
|
1
|
+
module Kaminari
|
2
|
+
module FakeGem
|
3
|
+
extend ActiveSupport::Concern
|
2
4
|
|
3
|
-
|
5
|
+
module ClassMethods
|
6
|
+
def inherited(kls)
|
7
|
+
super
|
8
|
+
def kls.fake_gem_defined_method; end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
ActiveSupport.on_load :active_record do
|
15
|
+
ActiveRecord::Base.send :include, Kaminari::FakeGem
|
16
|
+
|
17
|
+
# Simulate a gem providing a subclass of ActiveRecord::Base before the Railtie is loaded.
|
18
|
+
class GemDefinedModel < ActiveRecord::Base
|
19
|
+
end
|
4
20
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
if defined?(Rails)
|
4
|
+
require 'rails/generators'
|
5
|
+
require 'generators/kaminari/views_generator'
|
6
|
+
|
7
|
+
describe Kaminari::Generators::GitHubApiHelper, :generator_spec => true do
|
8
|
+
describe '.get_files_in_master' do
|
9
|
+
subject { Kaminari::Generators::GitHubApiHelper.get_files_in_master }
|
10
|
+
it { should include(["README", "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"]) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.get_content_for' do
|
14
|
+
subject { Kaminari::Generators::GitHubApiHelper.get_content_for("README") }
|
15
|
+
it { should == "" }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'Kaminari::ActionViewExtension' do
|
3
|
+
describe 'Kaminari::ActionViewExtension', :if => defined?(Rails)do
|
4
4
|
describe '#paginate' do
|
5
5
|
before do
|
6
6
|
50.times {|i| User.create! :name => "user#{i}"}
|
7
7
|
@users = User.page(1)
|
8
8
|
end
|
9
|
+
|
9
10
|
subject { helper.paginate @users, :params => {:controller => 'users', :action => 'index'} }
|
10
11
|
it { should be_a String }
|
11
12
|
|
@@ -14,30 +15,53 @@ describe 'Kaminari::ActionViewExtension' do
|
|
14
15
|
lambda { helper.escape_javascript(helper.paginate @users, :params => {:controller => 'users', :action => 'index'}) }.should_not raise_error
|
15
16
|
end
|
16
17
|
end
|
18
|
+
|
19
|
+
context 'accepts :theme option' do
|
20
|
+
before { helper.controller.append_view_path "spec/fake_app/views" }
|
21
|
+
subject { helper.paginate @users, :theme => "bootstrap", :params => {:controller => 'users', :action => 'index'} }
|
22
|
+
it { should match(/bootstrap-paginator/) }
|
23
|
+
it { should match(/bootstrap-page-link/) }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'accepts :view_prefix option' do
|
27
|
+
before { helper.controller.append_view_path "spec/fake_app/views" }
|
28
|
+
subject { helper.paginate @users, :views_prefix => "alternative/", :params => {:controller => 'users', :action => 'index'} }
|
29
|
+
it { should eq(" <b>1</b>\n") }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "num_pages: 3" do
|
33
|
+
subject { helper.paginate @users, :num_pages => 3, :params => {:controller => 'users', :action => 'index'} }
|
34
|
+
it { should match(/<a href="\/users\?page=3">Last/) }
|
35
|
+
end
|
17
36
|
end
|
18
37
|
|
19
38
|
describe '#link_to_previous_page' do
|
20
39
|
before do
|
21
40
|
50.times {|i| User.create! :name => "user#{i}"}
|
22
41
|
end
|
42
|
+
|
23
43
|
context 'having previous pages' do
|
24
44
|
before do
|
25
45
|
@users = User.page(50)
|
26
46
|
end
|
47
|
+
|
27
48
|
context 'the default behaviour' do
|
28
49
|
subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
|
29
50
|
it { should be_a String }
|
30
51
|
it { should match(/rel="previous"/) }
|
31
52
|
end
|
53
|
+
|
32
54
|
context 'overriding rel=' do
|
33
55
|
subject { helper.link_to_previous_page @users, 'Previous', :rel => 'external', :params => {:controller => 'users', :action => 'index'} }
|
34
56
|
it { should match(/rel="external"/) }
|
35
57
|
end
|
36
58
|
end
|
59
|
+
|
37
60
|
context 'the first page' do
|
38
61
|
before do
|
39
62
|
@users = User.page(1)
|
40
63
|
end
|
64
|
+
|
41
65
|
subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
|
42
66
|
it { should_not be }
|
43
67
|
end
|
@@ -47,24 +71,29 @@ describe 'Kaminari::ActionViewExtension' do
|
|
47
71
|
before do
|
48
72
|
50.times {|i| User.create! :name => "user#{i}"}
|
49
73
|
end
|
74
|
+
|
50
75
|
context 'having more page' do
|
51
76
|
before do
|
52
77
|
@users = User.page(1)
|
53
78
|
end
|
79
|
+
|
54
80
|
context 'the default behaviour' do
|
55
81
|
subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
|
56
82
|
it { should be_a String }
|
57
83
|
it { should match(/rel="next"/) }
|
58
84
|
end
|
85
|
+
|
59
86
|
context 'overriding rel=' do
|
60
87
|
subject { helper.link_to_next_page @users, 'More', :rel => 'external', :params => {:controller => 'users', :action => 'index'} }
|
61
88
|
it { should match(/rel="external"/) }
|
62
89
|
end
|
63
90
|
end
|
91
|
+
|
64
92
|
context 'the last page' do
|
65
93
|
before do
|
66
94
|
@users = User.page(2)
|
67
95
|
end
|
96
|
+
|
68
97
|
subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
|
69
98
|
it { should_not be }
|
70
99
|
end
|
@@ -75,9 +104,10 @@ describe 'Kaminari::ActionViewExtension' do
|
|
75
104
|
before do
|
76
105
|
@users = User.page(1).per(25)
|
77
106
|
end
|
107
|
+
|
78
108
|
context 'having no entries' do
|
79
109
|
subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
|
80
|
-
it { should == 'No
|
110
|
+
it { should == 'No users found' }
|
81
111
|
|
82
112
|
context 'setting the entry name option to "member"' do
|
83
113
|
subject { helper.page_entries_info @users, :entry_name => 'member', :params => {:controller => 'users', :action => 'index'} }
|
@@ -90,6 +120,7 @@ describe 'Kaminari::ActionViewExtension' do
|
|
90
120
|
User.create! :name => 'user1'
|
91
121
|
@users = User.page(1).per(25)
|
92
122
|
end
|
123
|
+
|
93
124
|
subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
|
94
125
|
it { should == 'Displaying <b>1</b> user' }
|
95
126
|
|
@@ -104,6 +135,7 @@ describe 'Kaminari::ActionViewExtension' do
|
|
104
135
|
10.times {|i| User.create! :name => "user#{i}"}
|
105
136
|
@users = User.page(1).per(25)
|
106
137
|
end
|
138
|
+
|
107
139
|
subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
|
108
140
|
it { should == 'Displaying <b>all 10</b> users' }
|
109
141
|
|
@@ -122,6 +154,7 @@ describe 'Kaminari::ActionViewExtension' do
|
|
122
154
|
before do
|
123
155
|
@users = User.page(1).per(25)
|
124
156
|
end
|
157
|
+
|
125
158
|
subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
|
126
159
|
it { should == 'Displaying users <b>1 - 25</b> of <b>50</b> in total' }
|
127
160
|
|
@@ -135,6 +168,7 @@ describe 'Kaminari::ActionViewExtension' do
|
|
135
168
|
before do
|
136
169
|
@users = User.page(2).per(25)
|
137
170
|
end
|
171
|
+
|
138
172
|
subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
|
139
173
|
it { should == 'Displaying users <b>26 - 50</b> of <b>50</b> in total' }
|
140
174
|
|
@@ -143,15 +177,28 @@ describe 'Kaminari::ActionViewExtension' do
|
|
143
177
|
it { should == 'Displaying members <b>26 - 50</b> of <b>50</b> in total' }
|
144
178
|
end
|
145
179
|
end
|
180
|
+
|
181
|
+
describe 'the last page' do
|
182
|
+
before do
|
183
|
+
User.max_pages_per 4
|
184
|
+
@users = User.page(4).per(10)
|
185
|
+
end
|
186
|
+
|
187
|
+
after { User.max_pages_per nil }
|
188
|
+
|
189
|
+
subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} }
|
190
|
+
it { should == 'Displaying users <b>31 - 40</b> of <b>50</b> in total' }
|
191
|
+
end
|
146
192
|
end
|
147
193
|
end
|
148
194
|
context 'on a model with namespace' do
|
149
195
|
before do
|
150
196
|
@addresses = User::Address.page(1).per(25)
|
151
197
|
end
|
198
|
+
|
152
199
|
context 'having no entries' do
|
153
200
|
subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
|
154
|
-
it { should == 'No
|
201
|
+
it { should == 'No addresses found' }
|
155
202
|
end
|
156
203
|
|
157
204
|
context 'having 1 entry' do
|
@@ -159,6 +206,7 @@ describe 'Kaminari::ActionViewExtension' do
|
|
159
206
|
User::Address.create!
|
160
207
|
@addresses = User::Address.page(1).per(25)
|
161
208
|
end
|
209
|
+
|
162
210
|
subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
|
163
211
|
it { should == 'Displaying <b>1</b> address' }
|
164
212
|
|
@@ -173,6 +221,7 @@ describe 'Kaminari::ActionViewExtension' do
|
|
173
221
|
10.times {|i| User::Address.create!}
|
174
222
|
@addresses = User::Address.page(1).per(25)
|
175
223
|
end
|
224
|
+
|
176
225
|
subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
|
177
226
|
it { should == 'Displaying <b>all 10</b> addresses' }
|
178
227
|
|
@@ -191,6 +240,7 @@ describe 'Kaminari::ActionViewExtension' do
|
|
191
240
|
before do
|
192
241
|
@addresses = User::Address.page(1).per(25)
|
193
242
|
end
|
243
|
+
|
194
244
|
subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
|
195
245
|
it { should == 'Displaying addresses <b>1 - 25</b> of <b>50</b> in total' }
|
196
246
|
|
@@ -204,6 +254,7 @@ describe 'Kaminari::ActionViewExtension' do
|
|
204
254
|
before do
|
205
255
|
@addresses = User::Address.page(2).per(25)
|
206
256
|
end
|
257
|
+
|
207
258
|
subject { helper.page_entries_info @addresses, :params => {:controller => 'addresses', :action => 'index'} }
|
208
259
|
it { should == 'Displaying addresses <b>26 - 50</b> of <b>50</b> in total' }
|
209
260
|
|
@@ -219,6 +270,7 @@ describe 'Kaminari::ActionViewExtension' do
|
|
219
270
|
before do
|
220
271
|
@numbers = Kaminari.paginate_array(%w{one two three}).page(1)
|
221
272
|
end
|
273
|
+
|
222
274
|
subject { helper.page_entries_info @numbers }
|
223
275
|
it { should == 'Displaying <b>all 3</b> entries' }
|
224
276
|
end
|
@@ -226,37 +278,41 @@ describe 'Kaminari::ActionViewExtension' do
|
|
226
278
|
|
227
279
|
describe '#rel_next_prev_link_tags' do
|
228
280
|
before do
|
229
|
-
|
281
|
+
80.times {|i| User.create! :name => "user#{i}"}
|
230
282
|
end
|
283
|
+
|
231
284
|
context 'the first page' do
|
232
285
|
before do
|
233
286
|
@users = User.page(1).per(25)
|
234
287
|
end
|
235
288
|
|
236
289
|
subject { helper.rel_next_prev_link_tags @users, :params => {:controller => 'users', :action => 'index'} }
|
237
|
-
it { should be_a String }
|
238
|
-
it { should match(/rel="next"/) }
|
239
290
|
it { should_not match(/rel="prev"/) }
|
291
|
+
it { should match(/rel="next"/) }
|
292
|
+
it { should match(/\?page=2/) }
|
240
293
|
end
|
294
|
+
|
241
295
|
context 'the middle page' do
|
242
296
|
before do
|
243
|
-
@users = User.page(
|
297
|
+
@users = User.page(3).per(25)
|
244
298
|
end
|
245
299
|
|
246
300
|
subject { helper.rel_next_prev_link_tags @users, :params => {:controller => 'users', :action => 'index'} }
|
247
|
-
it { should be_a String }
|
248
|
-
it { should match(/rel="next"/) }
|
249
301
|
it { should match(/rel="prev"/) }
|
302
|
+
it { should match(/\?page=2/) }
|
303
|
+
it { should match(/rel="next"/) }
|
304
|
+
it { should match(/\?page=4/) }
|
250
305
|
end
|
306
|
+
|
251
307
|
context 'the last page' do
|
252
308
|
before do
|
253
|
-
@users = User.page(
|
309
|
+
@users = User.page(4).per(25)
|
254
310
|
end
|
255
311
|
|
256
312
|
subject { helper.rel_next_prev_link_tags @users, :params => {:controller => 'users', :action => 'index'} }
|
257
|
-
it { should be_a String }
|
258
|
-
it { should_not match(/rel="next"/) }
|
259
313
|
it { should match(/rel="prev"/) }
|
314
|
+
it { should match(/\?page=3"/) }
|
315
|
+
it { should_not match(/rel="next"/) }
|
260
316
|
end
|
261
317
|
end
|
262
318
|
end
|
@@ -8,10 +8,19 @@ describe 'Kaminari::Helpers::Paginator' do
|
|
8
8
|
params { {} }
|
9
9
|
options { {} }
|
10
10
|
url_for {|h| "/foo?page=#{h[:page]}"}
|
11
|
+
link_to { "<a href='#'>link</a>" }
|
11
12
|
end
|
12
13
|
r
|
13
14
|
end
|
14
15
|
|
16
|
+
describe "view helper methods delegated to template" do
|
17
|
+
before do
|
18
|
+
@paginator = Paginator.new(template, :params => {})
|
19
|
+
end
|
20
|
+
subject { @paginator.link_to("link", "#") }
|
21
|
+
it { should == "<a href='#'>link</a>" }
|
22
|
+
end
|
23
|
+
|
15
24
|
describe '#params' do
|
16
25
|
before do
|
17
26
|
@paginator = Paginator.new(template, :params => {:controller => 'foo', :action => 'bar'})
|
@@ -12,6 +12,17 @@ if defined? Sinatra
|
|
12
12
|
</div>
|
13
13
|
EOT
|
14
14
|
|
15
|
+
ERB_TEMPLATE_FOR_PREVIOUS_PAGE = <<EOT
|
16
|
+
<div>
|
17
|
+
<ul>
|
18
|
+
<% @users.each do |user| %>
|
19
|
+
<li class="user_info"><%= user.id %></li>
|
20
|
+
<% end %>
|
21
|
+
</ul>
|
22
|
+
<%= link_to_previous_page(@users, "Previous!", {:id => 'previous_page_link'}.merge(@options || {})) %>
|
23
|
+
</div>
|
24
|
+
EOT
|
25
|
+
|
15
26
|
ERB_TEMPLATE_FOR_NEXT_PAGE = <<EOT
|
16
27
|
<div>
|
17
28
|
<ul>
|
@@ -125,6 +136,48 @@ EOT
|
|
125
136
|
end
|
126
137
|
end
|
127
138
|
|
139
|
+
describe '#link_to_previous_page' do
|
140
|
+
before do
|
141
|
+
mock_app do
|
142
|
+
register Kaminari::Helpers::SinatraHelpers
|
143
|
+
get '/users' do
|
144
|
+
@page = params[:page] || 2
|
145
|
+
@users = User.page(@page)
|
146
|
+
erb ERB_TEMPLATE_FOR_PREVIOUS_PAGE
|
147
|
+
end
|
148
|
+
|
149
|
+
get '/users_placeholder' do
|
150
|
+
@page = params[:page] || 2
|
151
|
+
@options = {:placeholder => %{<span id='no_previous_page'>No Previous Page</span>}}
|
152
|
+
@users = User.page(@page)
|
153
|
+
erb ERB_TEMPLATE_FOR_PREVIOUS_PAGE
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'having more page' do
|
159
|
+
it 'should have a more page link' do
|
160
|
+
get '/users'
|
161
|
+
last_document.search('a#previous_page_link').should be_present
|
162
|
+
last_document.search('a#previous_page_link').text.should match(/Previous!/)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context 'the first page' do
|
167
|
+
it 'should not have a more page link' do
|
168
|
+
get '/users?page=1'
|
169
|
+
last_document.search('a#previous_page_link').should be_empty
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should have a no more page notation using placeholder' do
|
173
|
+
get '/users_placeholder?page=1'
|
174
|
+
last_document.search('a#previous_page_link').should be_empty
|
175
|
+
last_document.search('span#no_previous_page').should be_present
|
176
|
+
last_document.search('span#no_previous_page').text.should match(/No Previous Page/)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
128
181
|
describe '#link_to_next_page' do
|
129
182
|
before do
|
130
183
|
mock_app do
|
@@ -14,15 +14,62 @@ if defined? ActiveRecord
|
|
14
14
|
@books.each {|book| book.readers << @readers }
|
15
15
|
end
|
16
16
|
|
17
|
+
context "when the scope is cloned" do
|
18
|
+
it "should reset total_coount momoization" do
|
19
|
+
User.page.tap(&:total_count).where(:name => 'author').total_count.should == 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
17
23
|
context "when the scope includes an order which references a generated column" do
|
18
24
|
it "should successfully count the results" do
|
19
25
|
@author.readers.by_read_count.page(1).total_count.should == @readers.size
|
20
26
|
end
|
21
27
|
end
|
28
|
+
|
22
29
|
context "when the scope use conditions on includes" do
|
23
30
|
it "should keep includes and successfully count the results" do
|
24
31
|
# Only @author and @author2 have books titled with the title00x partern
|
25
|
-
|
32
|
+
if ActiveRecord::VERSION::STRING >= "4.1.0"
|
33
|
+
User.includes(:books_authored).references(:books).where("books.title LIKE 'title00%'").page(1).total_count.should == 2
|
34
|
+
else
|
35
|
+
User.includes(:books_authored).where("books.title LIKE 'title00%'").page(1).total_count.should == 2
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when the Relation has custom select clause' do
|
41
|
+
specify do
|
42
|
+
lambda { User.select('*, 1 as one').page(1).total_count }.should_not raise_exception
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when total_count receives options" do
|
47
|
+
it "should return a distinct total count for rails < 4.1" do
|
48
|
+
if ActiveRecord::VERSION::STRING < "4.1.0"
|
49
|
+
User.page(1).total_count(:name, :distinct => true).should == 4
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should ignore the options for rails 4.1+" do
|
54
|
+
if ActiveRecord::VERSION::STRING >= "4.1.0"
|
55
|
+
User.page(1).total_count(:name, :distinct => true).should == 7
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if ActiveRecord::VERSION::STRING < '4.1.0'
|
61
|
+
context 'when count receives options' do
|
62
|
+
it 'should return a distinct set by column for rails < 4.1' do
|
63
|
+
User.page(1).count(:name, :distinct => true).should == 4
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when the scope returns an ActiveSupport::OrderedHash" do
|
69
|
+
it "should not throw exception by passing options to count" do
|
70
|
+
lambda {
|
71
|
+
@author.readers.by_read_count.page(1).total_count(:name, :distinct => true)
|
72
|
+
}.should_not raise_exception
|
26
73
|
end
|
27
74
|
end
|
28
75
|
end
|