kaminari 0.17.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kaminari might be problematic. Click here for more details.

Files changed (116) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +19 -0
  3. data/.gitignore +1 -1
  4. data/.travis.yml +38 -46
  5. data/CHANGELOG.md +600 -0
  6. data/CONTRIBUTING.md +16 -0
  7. data/Gemfile +1 -0
  8. data/README.md +558 -0
  9. data/Rakefile +23 -24
  10. data/gemfiles/active_record_41.gemfile +10 -7
  11. data/gemfiles/active_record_42.gemfile +10 -7
  12. data/gemfiles/active_record_50.gemfile +24 -0
  13. data/gemfiles/active_record_51.gemfile +24 -0
  14. data/gemfiles/active_record_edge.gemfile +17 -9
  15. data/kaminari.gemspec +22 -26
  16. data/lib/kaminari/version.rb +2 -1
  17. data/lib/kaminari.rb +4 -39
  18. data/misc/bug_report_template.rb +57 -0
  19. metadata +47 -186
  20. data/.gemtest +0 -0
  21. data/.rspec +0 -2
  22. data/CHANGELOG.rdoc +0 -480
  23. data/README.rdoc +0 -336
  24. data/app/views/kaminari/_first_page.html.erb +0 -11
  25. data/app/views/kaminari/_first_page.html.haml +0 -9
  26. data/app/views/kaminari/_first_page.html.slim +0 -10
  27. data/app/views/kaminari/_gap.html.erb +0 -8
  28. data/app/views/kaminari/_gap.html.haml +0 -8
  29. data/app/views/kaminari/_gap.html.slim +0 -9
  30. data/app/views/kaminari/_last_page.html.erb +0 -11
  31. data/app/views/kaminari/_last_page.html.haml +0 -9
  32. data/app/views/kaminari/_last_page.html.slim +0 -10
  33. data/app/views/kaminari/_next_page.html.erb +0 -11
  34. data/app/views/kaminari/_next_page.html.haml +0 -9
  35. data/app/views/kaminari/_next_page.html.slim +0 -10
  36. data/app/views/kaminari/_page.html.erb +0 -12
  37. data/app/views/kaminari/_page.html.haml +0 -10
  38. data/app/views/kaminari/_page.html.slim +0 -11
  39. data/app/views/kaminari/_paginator.html.erb +0 -23
  40. data/app/views/kaminari/_paginator.html.haml +0 -18
  41. data/app/views/kaminari/_paginator.html.slim +0 -19
  42. data/app/views/kaminari/_prev_page.html.erb +0 -11
  43. data/app/views/kaminari/_prev_page.html.haml +0 -9
  44. data/app/views/kaminari/_prev_page.html.slim +0 -10
  45. data/config/locales/kaminari.yml +0 -19
  46. data/gemfiles/active_record_30.gemfile +0 -28
  47. data/gemfiles/active_record_31.gemfile +0 -26
  48. data/gemfiles/active_record_32.gemfile +0 -25
  49. data/gemfiles/active_record_40.gemfile +0 -26
  50. data/gemfiles/data_mapper_12.gemfile +0 -32
  51. data/gemfiles/mongo_mapper.gemfile +0 -25
  52. data/gemfiles/mongoid_30.gemfile +0 -22
  53. data/gemfiles/mongoid_31.gemfile +0 -21
  54. data/gemfiles/mongoid_40.gemfile +0 -19
  55. data/gemfiles/mongoid_50.gemfile +0 -23
  56. data/gemfiles/sinatra_13.gemfile +0 -36
  57. data/gemfiles/sinatra_14.gemfile +0 -33
  58. data/lib/generators/kaminari/config_generator.rb +0 -16
  59. data/lib/generators/kaminari/templates/kaminari_config.rb +0 -10
  60. data/lib/generators/kaminari/views_generator.rb +0 -119
  61. data/lib/kaminari/config.rb +0 -51
  62. data/lib/kaminari/engine.rb +0 -4
  63. data/lib/kaminari/grape.rb +0 -4
  64. data/lib/kaminari/helpers/action_view_extension.rb +0 -132
  65. data/lib/kaminari/helpers/paginator.rb +0 -195
  66. data/lib/kaminari/helpers/sinatra_helpers.rb +0 -176
  67. data/lib/kaminari/helpers/tags.rb +0 -108
  68. data/lib/kaminari/hooks.rb +0 -53
  69. data/lib/kaminari/models/active_record_extension.rb +0 -22
  70. data/lib/kaminari/models/active_record_model_extension.rb +0 -22
  71. data/lib/kaminari/models/active_record_relation_methods.rb +0 -42
  72. data/lib/kaminari/models/array_extension.rb +0 -66
  73. data/lib/kaminari/models/configuration_methods.rb +0 -48
  74. data/lib/kaminari/models/data_mapper_collection_methods.rb +0 -19
  75. data/lib/kaminari/models/data_mapper_extension.rb +0 -51
  76. data/lib/kaminari/models/mongo_mapper_extension.rb +0 -18
  77. data/lib/kaminari/models/mongoid_criteria_methods.rb +0 -40
  78. data/lib/kaminari/models/mongoid_extension.rb +0 -26
  79. data/lib/kaminari/models/page_scope_methods.rb +0 -73
  80. data/lib/kaminari/models/plucky_criteria_methods.rb +0 -23
  81. data/lib/kaminari/railtie.rb +0 -7
  82. data/lib/kaminari/sinatra.rb +0 -7
  83. data/spec/config/config_spec.rb +0 -91
  84. data/spec/fake_app/active_record/config.rb +0 -3
  85. data/spec/fake_app/active_record/models.rb +0 -65
  86. data/spec/fake_app/data_mapper/config.rb +0 -1
  87. data/spec/fake_app/data_mapper/models.rb +0 -27
  88. data/spec/fake_app/mongo_mapper/config.rb +0 -2
  89. data/spec/fake_app/mongo_mapper/models.rb +0 -9
  90. data/spec/fake_app/mongoid/config.rb +0 -20
  91. data/spec/fake_app/mongoid/models.rb +0 -38
  92. data/spec/fake_app/rails_app.rb +0 -56
  93. data/spec/fake_app/sinatra_app.rb +0 -22
  94. data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +0 -1
  95. data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +0 -3
  96. data/spec/fake_app/views/kaminari/bootstrap/_page.html.erb +0 -1
  97. data/spec/fake_app/views/kaminari/bootstrap/_paginator.html.erb +0 -7
  98. data/spec/fake_gem.rb +0 -20
  99. data/spec/generators/views_generator_spec.rb +0 -18
  100. data/spec/helpers/action_view_extension_spec.rb +0 -318
  101. data/spec/helpers/helpers_spec.rb +0 -144
  102. data/spec/helpers/sinatra_helpers_spec.rb +0 -223
  103. data/spec/helpers/tags_spec.rb +0 -140
  104. data/spec/models/active_record/active_record_relation_methods_spec.rb +0 -77
  105. data/spec/models/active_record/inherited_spec.rb +0 -9
  106. data/spec/models/active_record/scopes_spec.rb +0 -265
  107. data/spec/models/array_spec.rb +0 -172
  108. data/spec/models/configuration_methods_spec.rb +0 -125
  109. data/spec/models/data_mapper/data_mapper_spec.rb +0 -205
  110. data/spec/models/mongo_mapper/mongo_mapper_spec.rb +0 -84
  111. data/spec/models/mongoid/mongoid_spec.rb +0 -228
  112. data/spec/requests/users_spec.rb +0 -53
  113. data/spec/spec_helper.rb +0 -34
  114. data/spec/spec_helper_for_sinatra.rb +0 -34
  115. data/spec/support/database_cleaner.rb +0 -19
  116. data/spec/support/matchers.rb +0 -52
@@ -1,223 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if defined? Sinatra
4
- ERB_TEMPLATE_FOR_PAGINATE = <<EOT
5
- <div>
6
- <ul>
7
- <% @users.each do |user| %>
8
- <li class="user_info"><%= user.id %></li>
9
- <% end %>
10
- </ul>
11
- <%= paginate @users, @options %>
12
- </div>
13
- EOT
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
-
26
- ERB_TEMPLATE_FOR_NEXT_PAGE = <<EOT
27
- <div>
28
- <ul>
29
- <% @users.each do |user| %>
30
- <li class="user_info"><%= user.id %></li>
31
- <% end %>
32
- </ul>
33
- <%= link_to_next_page(@users, "Next!", {:id => 'next_page_link'}.merge(@options || {})) %>
34
- </div>
35
- EOT
36
-
37
- describe 'Kaminari::Helpers::SinatraHelper' do
38
- before do
39
- 50.times {|i| User.create! :name => "user#{i}"}
40
- end
41
-
42
- describe '#paginate' do
43
- before do
44
- mock_app do
45
- register Kaminari::Helpers::SinatraHelpers
46
- get '/users' do
47
- @page = params[:page] || 1
48
- @users = User.page(@page)
49
- @options = {}
50
- erb ERB_TEMPLATE_FOR_PAGINATE
51
- end
52
- end
53
- end
54
-
55
- context 'normal paginations with Sinatra' do
56
- before { get '/users' }
57
-
58
- it 'should have a navigation tag' do
59
- last_document.search('nav.pagination').should_not be_empty
60
- end
61
-
62
- it 'should have pagination links' do
63
- last_document.search('.page a').should have_at_least(1).items
64
- last_document.search('.next a').should have_at_least(1).items
65
- last_document.search('.last a').should have_at_least(1).items
66
- end
67
-
68
- it 'should point to current page' do
69
- last_document.search('.current').text.should match(/1/)
70
-
71
- get '/users?page=2'
72
- last_document.search('.current').text.should match(/2/)
73
- end
74
-
75
- it 'should load 25 users' do
76
- last_document.search('li.user_info').should have(25).items
77
- end
78
-
79
- it 'should preserve params' do
80
- get '/users?foo=bar'
81
- last_document.search('.page a').should(be_all do |elm|
82
- elm.attribute('href').value =~ /foo=bar/
83
- end)
84
- end
85
- end
86
-
87
- context 'optional paginations with Sinatra' do
88
- it 'should have 5 windows with 1 gap' do
89
- mock_app do
90
- register Kaminari::Helpers::SinatraHelpers
91
- get '/users' do
92
- @page = params[:page] || 1
93
- @users = User.page(@page).per(5)
94
- @options = {}
95
- erb ERB_TEMPLATE_FOR_PAGINATE
96
- end
97
- end
98
-
99
- get '/users'
100
- last_document.search('.page').should have(6).items
101
- last_document.search('.gap').should have(1).item
102
- end
103
-
104
- it 'should controll the inner window size' do
105
- mock_app do
106
- register Kaminari::Helpers::SinatraHelpers
107
- get '/users' do
108
- @page = params[:page] || 1
109
- @users = User.page(@page).per(3)
110
- @options = {:window => 10}
111
- erb ERB_TEMPLATE_FOR_PAGINATE
112
- end
113
- end
114
-
115
- get '/users'
116
- last_document.search('.page').should have(12).items
117
- last_document.search('.gap').should have(1).item
118
- end
119
-
120
- it 'should specify a page param name' do
121
- mock_app do
122
- register Kaminari::Helpers::SinatraHelpers
123
- get '/users' do
124
- @page = params[:page] || 1
125
- @users = User.page(@page).per(3)
126
- @options = {:param_name => :user_page}
127
- erb ERB_TEMPLATE_FOR_PAGINATE
128
- end
129
- end
130
-
131
- get '/users'
132
- last_document.search('.page a').should(be_all do |elm|
133
- elm.attribute('href').value =~ /user_page=\d+/
134
- end)
135
- end
136
- end
137
- end
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
-
181
- describe '#link_to_next_page' do
182
- before do
183
- mock_app do
184
- register Kaminari::Helpers::SinatraHelpers
185
- get '/users' do
186
- @page = params[:page] || 1
187
- @users = User.page(@page)
188
- erb ERB_TEMPLATE_FOR_NEXT_PAGE
189
- end
190
-
191
- get '/users_placeholder' do
192
- @page = params[:page] || 1
193
- @options = {:placeholder => %{<span id='no_next_page'>No Next Page</span>}}
194
- @users = User.page(@page)
195
- erb ERB_TEMPLATE_FOR_NEXT_PAGE
196
- end
197
- end
198
- end
199
-
200
- context 'having more page' do
201
- it 'should have a more page link' do
202
- get '/users'
203
- last_document.search('a#next_page_link').should be_present
204
- last_document.search('a#next_page_link').text.should match(/Next!/)
205
- end
206
- end
207
-
208
- context 'the last page' do
209
- it 'should not have a more page link' do
210
- get '/users?page=2'
211
- last_document.search('a#next_page_link').should be_empty
212
- end
213
-
214
- it 'should have a no more page notation using placeholder' do
215
- get '/users_placeholder?page=2'
216
- last_document.search('a#next_page_link').should be_empty
217
- last_document.search('span#no_next_page').should be_present
218
- last_document.search('span#no_next_page').text.should match(/No Next Page/)
219
- end
220
- end
221
- end
222
- end
223
- end
@@ -1,140 +0,0 @@
1
- require 'spec_helper'
2
- include Kaminari::Helpers
3
-
4
- describe 'Kaminari::Helpers' do
5
- describe 'Paginator' do
6
- describe 'Paginator::PageProxy' do
7
- describe '#current?' do
8
- context 'current_page == page' do
9
- subject { Paginator::PageProxy.new({:current_page => 26}, 26, nil) }
10
- its(:current?) { should be_true }
11
- end
12
- context 'current_page != page' do
13
- subject { Paginator::PageProxy.new({:current_page => 13}, 26, nil) }
14
- its(:current?) { should_not be_true }
15
- end
16
- end
17
-
18
- describe '#first?' do
19
- context 'page == 1' do
20
- subject { Paginator::PageProxy.new({:current_page => 26}, 1, nil) }
21
- its(:first?) { should be_true }
22
- end
23
- context 'page != 1' do
24
- subject { Paginator::PageProxy.new({:current_page => 13}, 2, nil) }
25
- its(:first?) { should_not be_true }
26
- end
27
- end
28
-
29
- describe '#last?' do
30
- context 'current_page == page' do
31
- subject { Paginator::PageProxy.new({:total_pages => 39}, 39, nil) }
32
- its(:last?) { should be_true }
33
- end
34
- context 'current_page != page' do
35
- subject { Paginator::PageProxy.new({:total_pages => 39}, 38, nil) }
36
- its(:last?) { should_not be_true }
37
- end
38
- end
39
-
40
- describe '#next?' do
41
- context 'page == current_page + 1' do
42
- subject { Paginator::PageProxy.new({:current_page => 52}, 53, nil) }
43
- its(:next?) { should be_true }
44
- end
45
- context 'page != current_page + 1' do
46
- subject { Paginator::PageProxy.new({:current_page => 52}, 77, nil) }
47
- its(:next?) { should_not be_true }
48
- end
49
- end
50
-
51
- describe '#prev?' do
52
- context 'page == current_page - 1' do
53
- subject { Paginator::PageProxy.new({:current_page => 77}, 76, nil) }
54
- its(:prev?) { should be_true }
55
- end
56
- context 'page != current_page + 1' do
57
- subject { Paginator::PageProxy.new({:current_page => 77}, 80, nil) }
58
- its(:prev?) { should_not be_true }
59
- end
60
- end
61
-
62
- describe '#left_outer?' do
63
- context 'current_page == left' do
64
- subject { Paginator::PageProxy.new({:left => 3}, 3, nil) }
65
- its(:left_outer?) { should be_true }
66
- end
67
- context 'current_page == left + 1' do
68
- subject { Paginator::PageProxy.new({:left => 3}, 4, nil) }
69
- its(:left_outer?) { should_not be_true }
70
- end
71
- context 'current_page == left + 2' do
72
- subject { Paginator::PageProxy.new({:left => 3}, 5, nil) }
73
- its(:left_outer?) { should_not be_true }
74
- end
75
- end
76
-
77
- describe '#right_outer?' do
78
- context 'total_pages - page > right' do
79
- subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 6, nil) }
80
- its(:right_outer?) { should_not be_true }
81
- end
82
- context 'total_pages - page == right' do
83
- subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 7, nil) }
84
- its(:right_outer?) { should_not be_true }
85
- end
86
- context 'total_pages - page < right' do
87
- subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 8, nil) }
88
- its(:right_outer?) { should be_true }
89
- end
90
- end
91
-
92
- describe '#inside_window?' do
93
- context 'page > current_page' do
94
- context 'page - current_page > window' do
95
- subject { Paginator::PageProxy.new({:current_page => 4, :window => 5}, 10, nil) }
96
- its(:inside_window?) { should_not be_true }
97
- end
98
- context 'page - current_page == window' do
99
- subject { Paginator::PageProxy.new({:current_page => 4, :window => 6}, 10, nil) }
100
- its(:inside_window?) { should be_true }
101
- end
102
- context 'page - current_page < window' do
103
- subject { Paginator::PageProxy.new({:current_page => 4, :window => 7}, 10, nil) }
104
- its(:inside_window?) { should be_true }
105
- end
106
- end
107
- context 'current_page > page' do
108
- context 'current_page - page > window' do
109
- subject { Paginator::PageProxy.new({:current_page => 15, :window => 4}, 10, nil) }
110
- its(:inside_window?) { should_not be_true }
111
- end
112
- context 'current_page - page == window' do
113
- subject { Paginator::PageProxy.new({:current_page => 15, :window => 5}, 10, nil) }
114
- its(:inside_window?) { should be_true }
115
- end
116
- context 'current_page - page < window' do
117
- subject { Paginator::PageProxy.new({:current_page => 15, :window => 6}, 10, nil) }
118
- its(:inside_window?) { should be_true }
119
- end
120
- end
121
- end
122
- describe '#was_truncated?' do
123
- before do
124
- stub(@template = Object.new) do
125
- options { {} }
126
- params { {} }
127
- end
128
- end
129
- context 'last.is_a? Gap' do
130
- subject { Paginator::PageProxy.new({}, 10, Gap.new(@template)) }
131
- its(:was_truncated?) { should be_true }
132
- end
133
- context 'last.is not a Gap' do
134
- subject { Paginator::PageProxy.new({}, 10, Page.new(@template)) }
135
- its(:was_truncated?) { should_not be_true }
136
- end
137
- end
138
- end
139
- end
140
- end
@@ -1,77 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if defined? ActiveRecord
4
- describe Kaminari::ActiveRecordRelationMethods do
5
- describe '#total_count' do
6
- before do
7
- @author = User.create! :name => 'author'
8
- @author2 = User.create! :name => 'author2'
9
- @author3 = User.create! :name => 'author3'
10
- @books = 2.times.map {|i| @author.books_authored.create!(:title => "title%03d" % i) }
11
- @books2 = 3.times.map {|i| @author2.books_authored.create!(:title => "title%03d" % i) }
12
- @books3 = 4.times.map {|i| @author3.books_authored.create!(:title => "subject%03d" % i) }
13
- @readers = 4.times.map { User.create! :name => 'reader' }
14
- @books.each {|book| book.readers << @readers }
15
- end
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
-
23
- context "when the scope includes an order which references a generated column" do
24
- it "should successfully count the results" do
25
- @author.readers.by_read_count.page(1).total_count.should == @readers.size
26
- end
27
- end
28
-
29
- context "when the scope use conditions on includes" do
30
- it "should keep includes and successfully count the results" do
31
- # Only @author and @author2 have books titled with the title00x partern
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
73
- end
74
- end
75
- end
76
- end
77
- end
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if defined? ActiveRecord
4
- describe Kaminari::ActiveRecordModelExtension do
5
- subject { Class.new(ActiveRecord::Base) }
6
- it { should respond_to :page }
7
- it { should respond_to :fake_gem_defined_method }
8
- end
9
- end