kaminari 0.16.2 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +19 -0
  3. data/.gitignore +1 -1
  4. data/.travis.yml +82 -47
  5. data/CHANGELOG.md +636 -0
  6. data/CONTRIBUTING.md +22 -0
  7. data/Gemfile +2 -0
  8. data/README.md +573 -0
  9. data/Rakefile +33 -14
  10. data/gemfiles/active_record_41.gemfile +10 -6
  11. data/gemfiles/active_record_42.gemfile +10 -6
  12. data/gemfiles/active_record_50.gemfile +24 -0
  13. data/gemfiles/active_record_51.gemfile +24 -0
  14. data/gemfiles/active_record_52.gemfile +24 -0
  15. data/gemfiles/active_record_60.gemfile +26 -0
  16. data/gemfiles/active_record_edge.gemfile +15 -12
  17. data/kaminari.gemspec +23 -27
  18. data/lib/kaminari/version.rb +3 -1
  19. data/lib/kaminari.rb +4 -38
  20. data/misc/bug_report_template.rb +57 -0
  21. metadata +48 -184
  22. data/.gemtest +0 -0
  23. data/.rspec +0 -2
  24. data/CHANGELOG.rdoc +0 -446
  25. data/README.rdoc +0 -336
  26. data/app/views/kaminari/_first_page.html.erb +0 -11
  27. data/app/views/kaminari/_first_page.html.haml +0 -9
  28. data/app/views/kaminari/_first_page.html.slim +0 -10
  29. data/app/views/kaminari/_gap.html.erb +0 -8
  30. data/app/views/kaminari/_gap.html.haml +0 -8
  31. data/app/views/kaminari/_gap.html.slim +0 -9
  32. data/app/views/kaminari/_last_page.html.erb +0 -11
  33. data/app/views/kaminari/_last_page.html.haml +0 -9
  34. data/app/views/kaminari/_last_page.html.slim +0 -10
  35. data/app/views/kaminari/_next_page.html.erb +0 -11
  36. data/app/views/kaminari/_next_page.html.haml +0 -9
  37. data/app/views/kaminari/_next_page.html.slim +0 -10
  38. data/app/views/kaminari/_page.html.erb +0 -12
  39. data/app/views/kaminari/_page.html.haml +0 -10
  40. data/app/views/kaminari/_page.html.slim +0 -11
  41. data/app/views/kaminari/_paginator.html.erb +0 -23
  42. data/app/views/kaminari/_paginator.html.haml +0 -18
  43. data/app/views/kaminari/_paginator.html.slim +0 -19
  44. data/app/views/kaminari/_prev_page.html.erb +0 -11
  45. data/app/views/kaminari/_prev_page.html.haml +0 -9
  46. data/app/views/kaminari/_prev_page.html.slim +0 -10
  47. data/config/locales/kaminari.yml +0 -19
  48. data/gemfiles/active_record_30.gemfile +0 -30
  49. data/gemfiles/active_record_31.gemfile +0 -33
  50. data/gemfiles/active_record_32.gemfile +0 -33
  51. data/gemfiles/active_record_40.gemfile +0 -25
  52. data/gemfiles/data_mapper_12.gemfile +0 -39
  53. data/gemfiles/mongo_mapper.gemfile +0 -31
  54. data/gemfiles/mongoid_24.gemfile +0 -25
  55. data/gemfiles/mongoid_30.gemfile +0 -21
  56. data/gemfiles/mongoid_31.gemfile +0 -20
  57. data/gemfiles/mongoid_40.gemfile +0 -18
  58. data/gemfiles/sinatra_13.gemfile +0 -43
  59. data/gemfiles/sinatra_14.gemfile +0 -43
  60. data/lib/generators/kaminari/config_generator.rb +0 -16
  61. data/lib/generators/kaminari/templates/kaminari_config.rb +0 -10
  62. data/lib/generators/kaminari/views_generator.rb +0 -119
  63. data/lib/kaminari/config.rb +0 -51
  64. data/lib/kaminari/engine.rb +0 -4
  65. data/lib/kaminari/grape.rb +0 -4
  66. data/lib/kaminari/helpers/action_view_extension.rb +0 -132
  67. data/lib/kaminari/helpers/paginator.rb +0 -195
  68. data/lib/kaminari/helpers/sinatra_helpers.rb +0 -176
  69. data/lib/kaminari/helpers/tags.rb +0 -105
  70. data/lib/kaminari/hooks.rb +0 -36
  71. data/lib/kaminari/models/active_record_extension.rb +0 -22
  72. data/lib/kaminari/models/active_record_model_extension.rb +0 -22
  73. data/lib/kaminari/models/active_record_relation_methods.rb +0 -42
  74. data/lib/kaminari/models/array_extension.rb +0 -66
  75. data/lib/kaminari/models/configuration_methods.rb +0 -48
  76. data/lib/kaminari/models/data_mapper_collection_methods.rb +0 -19
  77. data/lib/kaminari/models/data_mapper_extension.rb +0 -51
  78. data/lib/kaminari/models/mongo_mapper_extension.rb +0 -18
  79. data/lib/kaminari/models/mongoid_criteria_methods.rb +0 -40
  80. data/lib/kaminari/models/mongoid_extension.rb +0 -27
  81. data/lib/kaminari/models/page_scope_methods.rb +0 -70
  82. data/lib/kaminari/models/plucky_criteria_methods.rb +0 -23
  83. data/lib/kaminari/railtie.rb +0 -7
  84. data/lib/kaminari/sinatra.rb +0 -5
  85. data/spec/config/config_spec.rb +0 -91
  86. data/spec/fake_app/active_record/config.rb +0 -3
  87. data/spec/fake_app/active_record/models.rb +0 -65
  88. data/spec/fake_app/data_mapper/config.rb +0 -1
  89. data/spec/fake_app/data_mapper/models.rb +0 -27
  90. data/spec/fake_app/mongo_mapper/config.rb +0 -2
  91. data/spec/fake_app/mongo_mapper/models.rb +0 -9
  92. data/spec/fake_app/mongoid/config.rb +0 -18
  93. data/spec/fake_app/mongoid/models.rb +0 -34
  94. data/spec/fake_app/rails_app.rb +0 -56
  95. data/spec/fake_app/sinatra_app.rb +0 -22
  96. data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +0 -1
  97. data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +0 -3
  98. data/spec/fake_app/views/kaminari/bootstrap/_page.html.erb +0 -1
  99. data/spec/fake_app/views/kaminari/bootstrap/_paginator.html.erb +0 -7
  100. data/spec/fake_gem.rb +0 -4
  101. data/spec/generators/views_generator_spec.rb +0 -18
  102. data/spec/helpers/action_view_extension_spec.rb +0 -306
  103. data/spec/helpers/helpers_spec.rb +0 -144
  104. data/spec/helpers/sinatra_helpers_spec.rb +0 -223
  105. data/spec/helpers/tags_spec.rb +0 -140
  106. data/spec/models/active_record/active_record_relation_methods_spec.rb +0 -77
  107. data/spec/models/active_record/scopes_spec.rb +0 -262
  108. data/spec/models/array_spec.rb +0 -172
  109. data/spec/models/configuration_methods_spec.rb +0 -125
  110. data/spec/models/data_mapper/data_mapper_spec.rb +0 -205
  111. data/spec/models/mongo_mapper/mongo_mapper_spec.rb +0 -84
  112. data/spec/models/mongoid/mongoid_spec.rb +0 -223
  113. data/spec/requests/users_spec.rb +0 -53
  114. data/spec/spec_helper.rb +0 -34
  115. data/spec/spec_helper_for_sinatra.rb +0 -34
  116. data/spec/support/database_cleaner.rb +0 -19
  117. data/spec/support/matchers.rb +0 -52
@@ -1,223 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if defined? Mongoid
4
- describe Kaminari::MongoidCriteriaMethods do
5
- describe "#total_count" do
6
- before do
7
- 2.times {|i| User.create!(:salary => i) }
8
- end
9
-
10
- context "when the scope is cloned" do
11
- it "should reset total_coount momoization" do
12
- User.page.tap(&:total_count).where(:salary => 1).total_count.should == 1
13
- end
14
- end
15
- end
16
- end
17
-
18
- describe Kaminari::MongoidExtension do
19
- before(:each) do
20
- 41.times do
21
- User.create!({:salary => 1})
22
- end
23
- end
24
-
25
- describe 'max_scan', :if => Mongoid::VERSION >= '3' do
26
- context 'less than total' do
27
- context 'page 1' do
28
- subject { User.max_scan(20).page 1 }
29
- it { should be_a Mongoid::Criteria }
30
- its(:current_page) { should == 1 }
31
- its(:prev_page) { should be_nil }
32
- its(:next_page) { should be_nil }
33
- its(:limit_value) { should == 25 }
34
- its(:total_pages) { should == 1 }
35
- its(:total_count) { should == 20 }
36
- it { should skip(0) }
37
- end
38
-
39
- context 'page 2' do
40
- subject { User.max_scan(30).page 2 }
41
- it { should be_a Mongoid::Criteria }
42
- its(:current_page) { should == 2 }
43
- its(:prev_page) { should == 1 }
44
- its(:next_page) { should be_nil }
45
- its(:limit_value) { should == 25 }
46
- its(:total_pages) { should == 2 }
47
- its(:total_count) { should == 30 }
48
- it { should skip 25 }
49
- end
50
- end
51
-
52
- context 'more than total' do
53
- context 'page 1' do
54
- subject { User.max_scan(60).page 1 }
55
- it { should be_a Mongoid::Criteria }
56
- its(:current_page) { should == 1 }
57
- its(:prev_page) { should be_nil }
58
- its(:next_page) { should == 2 }
59
- its(:limit_value) { should == 25 }
60
- its(:total_pages) { should == 2 }
61
- its(:total_count) { should == 41 }
62
- it { should skip(0) }
63
- end
64
-
65
- context 'page 2' do
66
- subject { User.max_scan(60).page 2 }
67
- it { should be_a Mongoid::Criteria }
68
- its(:current_page) { should == 2 }
69
- its(:prev_page) { should == 1 }
70
- its(:next_page) { should be_nil }
71
- its(:limit_value) { should == 25 }
72
- its(:total_pages) { should == 2 }
73
- its(:total_count) { should == 41 }
74
- it { should skip 25 }
75
- end
76
- end
77
- end
78
-
79
- describe '#page' do
80
-
81
- context 'page 1' do
82
- subject { User.page 1 }
83
- it { should be_a Mongoid::Criteria }
84
- its(:current_page) { should == 1 }
85
- its(:prev_page) { should be_nil }
86
- its(:next_page) { should == 2 }
87
- its(:limit_value) { should == 25 }
88
- its(:total_pages) { should == 2 }
89
- it { should skip(0) }
90
- end
91
-
92
- context 'page 2' do
93
- subject { User.page 2 }
94
- it { should be_a Mongoid::Criteria }
95
- its(:current_page) { should == 2 }
96
- its(:prev_page) { should == 1 }
97
- its(:next_page) { should be_nil }
98
- its(:limit_value) { should == 25 }
99
- its(:total_pages) { should == 2 }
100
- it { should skip 25 }
101
- end
102
-
103
- context 'page "foobar"' do
104
- subject { User.page 'foobar' }
105
- it { should be_a Mongoid::Criteria }
106
- its(:current_page) { should == 1 }
107
- its(:prev_page) { should be_nil }
108
- its(:next_page) { should == 2 }
109
- its(:limit_value) { should == 25 }
110
- its(:total_pages) { should == 2 }
111
- it { should skip 0 }
112
- end
113
-
114
- shared_examples 'complete valid pagination' do
115
- if Mongoid::VERSION > '3.0.0'
116
- its(:selector) { should == {'salary' => 1} }
117
- else
118
- its(:selector) { should == {:salary => 1} }
119
- end
120
- its(:current_page) { should == 2 }
121
- its(:prev_page) { should == 1 }
122
- its(:next_page) { should be_nil }
123
- its(:limit_value) { should == 25 }
124
- its(:total_pages) { should == 2 }
125
- it { should skip 25 }
126
- end
127
-
128
- context 'with criteria before' do
129
- subject { User.where(:salary => 1).page 2 }
130
- it_should_behave_like 'complete valid pagination'
131
- end
132
-
133
- context 'with criteria after' do
134
- subject { User.page(2).where(:salary => 1) }
135
- it_should_behave_like 'complete valid pagination'
136
- end
137
-
138
- context "with database:", :if => Mongoid::VERSION >= '3' do
139
- before :all do
140
- 15.times { User.with(:database => "default_db").create!(:salary => 1) }
141
- 10.times { User.with(:database => "other_db").create!(:salary => 1) }
142
- end
143
-
144
- context "default_db" do
145
- subject { User.with(:database => "default_db").order_by(:artist.asc).page(1) }
146
- its(:total_count) { should == 15 }
147
- end
148
-
149
- context "other_db" do
150
- subject { User.with(:database => "other_db").order_by(:artist.asc).page(1) }
151
- its(:total_count) { should == 10 }
152
- end
153
- end
154
- end
155
-
156
- describe '#per' do
157
- subject { User.page(2).per(10) }
158
- it { should be_a Mongoid::Criteria }
159
- its(:current_page) { should == 2 }
160
- its(:prev_page) { should == 1 }
161
- its(:next_page) { should == 3 }
162
- its(:limit_value) { should == 10 }
163
- its(:total_pages) { should == 5 }
164
- it { should skip 10 }
165
- end
166
-
167
- describe '#page in embedded documents' do
168
- before do
169
- @mongo_developer = MongoMongoidExtensionDeveloper.new
170
- @mongo_developer.frameworks.new(:name => "rails", :language => "ruby")
171
- @mongo_developer.frameworks.new(:name => "merb", :language => "ruby")
172
- @mongo_developer.frameworks.new(:name => "sinatra", :language => "ruby")
173
- @mongo_developer.frameworks.new(:name => "cakephp", :language => "php")
174
- @mongo_developer.frameworks.new(:name => "tornado", :language => "python")
175
- end
176
-
177
- context 'page 1' do
178
- subject { @mongo_developer.frameworks.page(1).per(1) }
179
- it { should be_a Mongoid::Criteria }
180
- its(:total_count) { should == 5 }
181
- its(:limit_value) { should == 1 }
182
- its(:current_page) { should == 1 }
183
- its(:prev_page) { should be_nil }
184
- its(:next_page) { should == 2 }
185
- its(:total_pages) { should == 5 }
186
- end
187
-
188
- context 'with criteria after' do
189
- subject { @mongo_developer.frameworks.page(1).per(2).where(:language => "ruby") }
190
- it { should be_a Mongoid::Criteria }
191
- its(:total_count) { should == 3 }
192
- its(:limit_value) { should == 2 }
193
- its(:current_page) { should == 1 }
194
- its(:prev_page) { should be_nil }
195
- its(:next_page) { should == 2 }
196
- its(:total_pages) { should == 2 }
197
- end
198
-
199
- context 'with criteria before' do
200
- subject { @mongo_developer.frameworks.where(:language => "ruby").page(1).per(2) }
201
- it { should be_a Mongoid::Criteria }
202
- its(:total_count) { should == 3 }
203
- its(:limit_value) { should == 2 }
204
- its(:current_page) { should == 1 }
205
- its(:prev_page) { should be_nil }
206
- its(:next_page) { should == 2 }
207
- its(:total_pages) { should == 2 }
208
- end
209
- end
210
-
211
- describe '#paginates_per' do
212
- context 'when paginates_per is not defined in superclass' do
213
- subject { Product.all.page 1 }
214
- its(:limit_value) { should == 25 }
215
- end
216
-
217
- context 'when paginates_per is defined in subclass' do
218
- subject { Device.all.page 1 }
219
- its(:limit_value) { should == 100 }
220
- end
221
- end
222
- end
223
- end
@@ -1,53 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
-
4
- feature 'Users' do
5
- background do
6
- 1.upto(100) {|i| User.create! :name => "user#{'%03d' % i}" }
7
- end
8
- scenario 'navigating by pagination links' do
9
- visit '/users'
10
-
11
- within 'nav.pagination' do
12
- within 'span.page.current' do
13
- page.should have_content '1'
14
- end
15
- within 'span.next' do
16
- click_link 'Next ›'
17
- end
18
- end
19
-
20
- within 'nav.pagination' do
21
- within 'span.page.current' do
22
- page.should have_content '2'
23
- end
24
- within 'span.last' do
25
- click_link 'Last »'
26
- end
27
- end
28
-
29
- within 'nav.pagination' do
30
- within 'span.page.current' do
31
- page.should have_content '4'
32
- end
33
- within 'span.prev' do
34
- click_link '‹ Prev'
35
- end
36
- end
37
-
38
- within 'nav.pagination' do
39
- within 'span.page.current' do
40
- page.should have_content '3'
41
- end
42
- within 'span.first' do
43
- click_link '« First'
44
- end
45
- end
46
-
47
- within 'nav.pagination' do
48
- within 'span.page.current' do
49
- page.should have_content '1'
50
- end
51
- end
52
- end
53
- end
data/spec/spec_helper.rb DELETED
@@ -1,34 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
-
4
- begin
5
- require 'rails'
6
- rescue LoadError
7
- end
8
-
9
- require 'bundler/setup'
10
- Bundler.require
11
-
12
- require 'capybara/rspec'
13
- require 'database_cleaner'
14
-
15
- # Simulate a gem providing a subclass of ActiveRecord::Base before the Railtie is loaded.
16
- require 'fake_gem' if defined? ActiveRecord
17
-
18
- if defined? Rails
19
- require 'fake_app/rails_app'
20
-
21
- require 'rspec/rails'
22
- end
23
- if defined? Sinatra
24
- require 'spec_helper_for_sinatra'
25
- end
26
-
27
- # Requires supporting files with custom matchers and macros, etc,
28
- # in ./support/ and its subdirectories.
29
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
30
-
31
- RSpec.configure do |config|
32
- config.mock_with :rr
33
- config.filter_run_excluding :generator_spec => true if !ENV['GENERATOR_SPEC']
34
- end
@@ -1,34 +0,0 @@
1
- require 'kaminari/sinatra'
2
- require 'kaminari/helpers/action_view_extension'
3
- require 'rack/test'
4
- require 'sinatra/test_helpers'
5
- require 'capybara/rspec'
6
-
7
- require 'fake_app/sinatra_app'
8
-
9
- Capybara.app = SinatraApp
10
-
11
- module HelperMethodForHelperSpec
12
- module FakeEnv
13
- def env
14
- {'PATH_INFO' => '/'}
15
- end
16
- end
17
-
18
- def helper
19
- # OMG terrible object...
20
- ::Kaminari::Helpers::SinatraHelpers::ActionViewTemplateProxy.new(:current_params => {}, :current_path => '/', :param_name => Kaminari.config.param_name).extend(Padrino::Helpers, Kaminari::ActionViewExtension, Kaminari::Helpers::SinatraHelpers::HelperMethods, FakeEnv)
21
- end
22
- end
23
-
24
- RSpec.configure do |config|
25
- config.include Rack::Test::Methods
26
- config.include Sinatra::TestHelpers
27
- config.include HelperMethodForHelperSpec
28
- # config.include HelperMethodForHelperSpec, :type => :helper
29
- end
30
-
31
- require 'nokogiri'
32
- def last_document
33
- Nokogiri::HTML(last_response.body)
34
- end
@@ -1,19 +0,0 @@
1
- DatabaseCleaner[:active_record].strategy = :transaction if defined? ActiveRecord
2
- DatabaseCleaner[:data_mapper].strategy = :truncation if defined? DataMapper
3
- DatabaseCleaner[:mongoid].strategy = :truncation if defined? Mongoid
4
- DatabaseCleaner[:mongo_mapper].strategy = :truncation if defined? MongoMapper
5
-
6
- RSpec.configure do |config|
7
- config.before :suite do
8
- DatabaseCleaner.clean_with :truncation if defined? ActiveRecord
9
- DatabaseCleaner.clean_with :truncation if defined? DataMapper
10
- DatabaseCleaner.clean_with :truncation if defined? Mongoid
11
- DatabaseCleaner.clean_with :truncation if defined? MongoMapper
12
- end
13
- config.before :each do
14
- DatabaseCleaner.start
15
- end
16
- config.after :each do
17
- DatabaseCleaner.clean
18
- end
19
- end
@@ -1,52 +0,0 @@
1
- RSpec::Matchers.define :contain_tag do |klass|
2
- match do |collection|
3
- if @num.blank?
4
- collection.any? {|tag| tag.is_a? klass}
5
- else
6
- (@count = collection.count {|tag| tag.is_a? klass}) == @num
7
- end
8
- end
9
-
10
- def count(num)
11
- @num = num
12
- self
13
- end
14
-
15
- description do
16
- "contain #{@num || 'any'} instance(s) of #{klass.name}"
17
- end
18
- failure_message_for_should do |collection|
19
- "expected #{@num || 'any'} instance(s) of #{klass.name} but was #{@count}"
20
- end
21
- end
22
-
23
- RSpec::Matchers.define :contain_tag_old do |count|
24
- match do |collection|
25
- (@count = collection.count {|tag| tag.is_a? @klass}) == count
26
- end
27
-
28
- def instance_of(klass)
29
- @klass = klass
30
- self
31
- end
32
- alias :instances_of :instance_of
33
-
34
- description do
35
- "contain #{count || 'any'} instance(s) of #{@klass.name}"
36
- end
37
- failure_message_for_should do |collection|
38
- "expected #{count || 'any'} instance(s) of #{@klass.name} but was #{@count}"
39
- end
40
- end
41
-
42
- RSpec::Matchers.define :skip do |num|
43
- match do |criteria|
44
- criteria.instance_variable_get('@options')[:skip] == num
45
- end
46
- end
47
-
48
- RSpec::Matchers.define :offset do |num|
49
- match do |collection|
50
- collection.offset_value == num
51
- end
52
- end