dimkiriyenko-kaminari 0.12.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gemtest +0 -0
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/CHANGELOG +245 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +226 -0
- data/Rakefile +22 -0
- data/app/views/kaminari/_first_page.html.erb +11 -0
- data/app/views/kaminari/_first_page.html.haml +9 -0
- data/app/views/kaminari/_first_page.html.slim +10 -0
- data/app/views/kaminari/_gap.html.erb +8 -0
- data/app/views/kaminari/_gap.html.haml +8 -0
- data/app/views/kaminari/_gap.html.slim +9 -0
- data/app/views/kaminari/_last_page.html.erb +11 -0
- data/app/views/kaminari/_last_page.html.haml +9 -0
- data/app/views/kaminari/_last_page.html.slim +10 -0
- data/app/views/kaminari/_next_page.html.erb +11 -0
- data/app/views/kaminari/_next_page.html.haml +9 -0
- data/app/views/kaminari/_next_page.html.slim +10 -0
- data/app/views/kaminari/_page.html.erb +12 -0
- data/app/views/kaminari/_page.html.haml +10 -0
- data/app/views/kaminari/_page.html.slim +11 -0
- data/app/views/kaminari/_paginator.html.erb +23 -0
- data/app/views/kaminari/_paginator.html.haml +18 -0
- data/app/views/kaminari/_paginator.html.slim +19 -0
- data/app/views/kaminari/_prev_page.html.erb +11 -0
- data/app/views/kaminari/_prev_page.html.haml +9 -0
- data/app/views/kaminari/_prev_page.html.slim +10 -0
- data/config/locales/kaminari.yml +10 -0
- data/kaminari.gemspec +35 -0
- data/lib/generators/kaminari/config_generator.rb +16 -0
- data/lib/generators/kaminari/templates/kaminari_config.rb +8 -0
- data/lib/generators/kaminari/views_generator.rb +103 -0
- data/lib/kaminari.rb +2 -0
- data/lib/kaminari/config.rb +41 -0
- data/lib/kaminari/engine.rb +4 -0
- data/lib/kaminari/helpers/action_view_extension.rb +50 -0
- data/lib/kaminari/helpers/paginator.rb +154 -0
- data/lib/kaminari/helpers/tags.rb +95 -0
- data/lib/kaminari/models/active_record_extension.rb +25 -0
- data/lib/kaminari/models/active_record_relation_methods.rb +31 -0
- data/lib/kaminari/models/array_extension.rb +42 -0
- data/lib/kaminari/models/configuration_methods.rb +20 -0
- data/lib/kaminari/models/mongo_mapper_extension.rb +18 -0
- data/lib/kaminari/models/mongoid_criteria_methods.rb +18 -0
- data/lib/kaminari/models/mongoid_extension.rb +31 -0
- data/lib/kaminari/models/page_scope_methods.rb +36 -0
- data/lib/kaminari/models/plucky_criteria_methods.rb +18 -0
- data/lib/kaminari/railtie.rb +36 -0
- data/lib/kaminari/version.rb +3 -0
- data/spec/acceptance/acceptance_helper.rb +5 -0
- data/spec/acceptance/support/helpers.rb +5 -0
- data/spec/acceptance/support/paths.rb +9 -0
- data/spec/acceptance/users_spec.rb +53 -0
- data/spec/config/config_spec.rb +61 -0
- data/spec/fake_app.rb +80 -0
- data/spec/helpers/action_view_extension_spec.rb +37 -0
- data/spec/helpers/helpers_spec.rb +135 -0
- data/spec/helpers/tags_spec.rb +140 -0
- data/spec/models/active_record_relation_methods_spec.rb +40 -0
- data/spec/models/array_spec.rb +105 -0
- data/spec/models/default_per_page_spec.rb +29 -0
- data/spec/models/mongo_mapper_spec.rb +79 -0
- data/spec/models/mongoid_spec.rb +72 -0
- data/spec/models/scopes_spec.rb +149 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/support/database_cleaner.rb +13 -0
- data/spec/support/matchers.rb +46 -0
- metadata +314 -0
@@ -0,0 +1,135 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
include Kaminari::Helpers
|
3
|
+
|
4
|
+
describe 'Kaminari::Helpers::Paginator' do
|
5
|
+
let :template do
|
6
|
+
stub(r = Object.new) do
|
7
|
+
render.with_any_args
|
8
|
+
params { {} }
|
9
|
+
options { {} }
|
10
|
+
url_for {|h| "/foo?page=#{h[:page]}"}
|
11
|
+
end
|
12
|
+
r
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#params' do
|
16
|
+
before do
|
17
|
+
@paginator = Paginator.new(template, :params => {:controller => 'foo', :action => 'bar'})
|
18
|
+
end
|
19
|
+
subject { @paginator.page_tag(template).instance_variable_get('@params') }
|
20
|
+
it { should == {:controller => 'foo', :action => 'bar'} }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#param_name' do
|
24
|
+
before do
|
25
|
+
@paginator = Paginator.new(template, :param_name => :pagina)
|
26
|
+
end
|
27
|
+
subject { @paginator.page_tag(template).instance_variable_get('@param_name') }
|
28
|
+
it { should == :pagina }
|
29
|
+
end
|
30
|
+
|
31
|
+
#TODO test somehow...
|
32
|
+
# describe '#tagify_links' do
|
33
|
+
# def tags_with(options)
|
34
|
+
# PaginationRenderer.new(template, options).tagify_links
|
35
|
+
# end
|
36
|
+
|
37
|
+
# context '1 page in total' do
|
38
|
+
# subject { tags_with :num_pages => 1, :current_page => 1 }
|
39
|
+
# it { should have(0).tags }
|
40
|
+
# end
|
41
|
+
|
42
|
+
# context '10 pages in total' do
|
43
|
+
# context 'first page' do
|
44
|
+
# subject { tags_with :num_pages => 10, :current_page => 1 }
|
45
|
+
# it { should_not contain_tag PrevLink }
|
46
|
+
# it { should contain_tag PrevSpan }
|
47
|
+
# it { should contain_tag CurrentPage }
|
48
|
+
# it { should_not contain_tag FirstPageLink }
|
49
|
+
# it { should contain_tag LastPageLink }
|
50
|
+
# it { should contain_tag PageLink }
|
51
|
+
# it { should contain_tag NextLink }
|
52
|
+
# it { should_not contain_tag NextSpan }
|
53
|
+
# it { should contain_tag TruncatedSpan }
|
54
|
+
# end
|
55
|
+
|
56
|
+
# context 'second page' do
|
57
|
+
# subject { tags_with :num_pages => 10, :current_page => 2 }
|
58
|
+
# it { should contain_tag PrevLink }
|
59
|
+
# it { should_not contain_tag PrevSpan }
|
60
|
+
# it { should contain_tag CurrentPage }
|
61
|
+
# it { should contain_tag FirstPageLink }
|
62
|
+
# it { should contain_tag LastPageLink }
|
63
|
+
# it { should contain_tag PageLink }
|
64
|
+
# it { should contain_tag NextLink }
|
65
|
+
# it { should_not contain_tag NextSpan }
|
66
|
+
# it { should contain_tag TruncatedSpan }
|
67
|
+
# end
|
68
|
+
|
69
|
+
# context 'third page' do
|
70
|
+
# subject { tags_with :num_pages => 10, :current_page => 3 }
|
71
|
+
# it { should contain_tag PrevLink }
|
72
|
+
# it { should_not contain_tag PrevSpan }
|
73
|
+
# it { should contain_tag CurrentPage }
|
74
|
+
# it { should contain_tag FirstPageLink }
|
75
|
+
# it { should contain_tag LastPageLink }
|
76
|
+
# it { should contain_tag PageLink }
|
77
|
+
# it { should contain_tag NextLink }
|
78
|
+
# it { should_not contain_tag NextSpan }
|
79
|
+
# it { should contain_tag TruncatedSpan }
|
80
|
+
# end
|
81
|
+
|
82
|
+
# context 'fourth page(no truncation)' do
|
83
|
+
# subject { tags_with :num_pages => 10, :current_page => 4 }
|
84
|
+
# it { should contain_tag PrevLink }
|
85
|
+
# it { should_not contain_tag PrevSpan }
|
86
|
+
# it { should contain_tag CurrentPage }
|
87
|
+
# it { should contain_tag FirstPageLink }
|
88
|
+
# it { should contain_tag LastPageLink }
|
89
|
+
# it { should contain_tag PageLink }
|
90
|
+
# it { should contain_tag NextLink }
|
91
|
+
# it { should_not contain_tag NextSpan }
|
92
|
+
# it { should_not contain_tag TruncatedSpan }
|
93
|
+
# end
|
94
|
+
|
95
|
+
# context 'seventh page(no truncation)' do
|
96
|
+
# subject { tags_with :num_pages => 10, :current_page => 7 }
|
97
|
+
# it { should contain_tag PrevLink }
|
98
|
+
# it { should_not contain_tag PrevSpan }
|
99
|
+
# it { should contain_tag CurrentPage }
|
100
|
+
# it { should contain_tag FirstPageLink }
|
101
|
+
# it { should contain_tag LastPageLink }
|
102
|
+
# it { should contain_tag PageLink }
|
103
|
+
# it { should contain_tag NextLink }
|
104
|
+
# it { should_not contain_tag NextSpan }
|
105
|
+
# it { should_not contain_tag TruncatedSpan }
|
106
|
+
# end
|
107
|
+
|
108
|
+
# context 'eighth page' do
|
109
|
+
# subject { tags_with :num_pages => 10, :current_page => 8 }
|
110
|
+
# it { should contain_tag PrevLink }
|
111
|
+
# it { should_not contain_tag PrevSpan }
|
112
|
+
# it { should contain_tag CurrentPage }
|
113
|
+
# it { should contain_tag FirstPageLink }
|
114
|
+
# it { should contain_tag LastPageLink }
|
115
|
+
# it { should contain_tag PageLink }
|
116
|
+
# it { should contain_tag NextLink }
|
117
|
+
# it { should_not contain_tag NextSpan }
|
118
|
+
# it { should contain_tag TruncatedSpan }
|
119
|
+
# end
|
120
|
+
|
121
|
+
# context 'last page' do
|
122
|
+
# subject { tags_with :num_pages => 10, :current_page => 10 }
|
123
|
+
# it { should contain_tag PrevLink }
|
124
|
+
# it { should_not contain_tag PrevSpan }
|
125
|
+
# it { should contain_tag CurrentPage }
|
126
|
+
# it { should contain_tag FirstPageLink }
|
127
|
+
# it { should_not contain_tag LastPageLink }
|
128
|
+
# it { should contain_tag PageLink }
|
129
|
+
# it { should_not contain_tag NextLink }
|
130
|
+
# it { should contain_tag NextSpan }
|
131
|
+
# it { should contain_tag TruncatedSpan }
|
132
|
+
# end
|
133
|
+
# end
|
134
|
+
# end
|
135
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
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({:num_pages => 39}, 39, nil) }
|
32
|
+
its(:last?) { should be_true }
|
33
|
+
end
|
34
|
+
context 'current_page != page' do
|
35
|
+
subject { Paginator::PageProxy.new({:num_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 'num_pages - page > right' do
|
79
|
+
subject { Paginator::PageProxy.new({:num_pages => 10, :right => 3}, 6, nil) }
|
80
|
+
its(:right_outer?) { should_not be_true }
|
81
|
+
end
|
82
|
+
context 'num_pages - page == right' do
|
83
|
+
subject { Paginator::PageProxy.new({:num_pages => 10, :right => 3}, 7, nil) }
|
84
|
+
its(:right_outer?) { should_not be_true }
|
85
|
+
end
|
86
|
+
context 'num_pages - page < right' do
|
87
|
+
subject { Paginator::PageProxy.new({:num_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
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Kaminari::ActiveRecordRelationMethods do
|
4
|
+
describe '#total_count' do
|
5
|
+
before do
|
6
|
+
@author = User.create! :name => 'author'
|
7
|
+
@author2 = User.create! :name => 'author2'
|
8
|
+
@author3 = User.create! :name => 'author3'
|
9
|
+
@books = 2.times.map {|i| @author.books_authored.create!(:title => "title%03d" % i) }
|
10
|
+
@books2 = 3.times.map {|i| @author2.books_authored.create!(:title => "title%03d" % i) }
|
11
|
+
@books3 = 4.times.map {|i| @author3.books_authored.create!(:title => "subject%03d" % i) }
|
12
|
+
@readers = 4.times.map { User.create! :name => 'reader' }
|
13
|
+
@books.each {|book| book.readers << @readers }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when the scope includes an order which references a generated column" do
|
17
|
+
it "should successfully count the results" do
|
18
|
+
@author.readers.by_read_count.page(1).total_count.should == @readers.size
|
19
|
+
end
|
20
|
+
end
|
21
|
+
context "when the scope use conditions on includes" do
|
22
|
+
it "should keep includes and successfully count the results" do
|
23
|
+
# Only @author and @author2 have books titled with the title00x partern
|
24
|
+
User.includes(:books_authored).where("books.title LIKE 'title00%'").page(1).total_count.should == 2
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when the scope responds to smart_count" do
|
29
|
+
module SmartCount
|
30
|
+
def smart_count
|
31
|
+
123
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should call smart_count on scope and return the given value" do
|
36
|
+
@author.readers.by_read_count.page(1).extending(SmartCount).total_count.should == 123
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Kaminari::PaginatableArray do
|
4
|
+
let(:array) { Kaminari::PaginatableArray.new((1..100).to_a) }
|
5
|
+
describe '#page' do
|
6
|
+
shared_examples_for 'the first page of array' do
|
7
|
+
it { should have(25).users }
|
8
|
+
its(:first) { should == 1 }
|
9
|
+
end
|
10
|
+
|
11
|
+
shared_examples_for 'blank array page' do
|
12
|
+
it { should have(0).items }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'page 1' do
|
16
|
+
subject { array.page 1 }
|
17
|
+
it_should_behave_like 'the first page of array'
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'page 2' do
|
21
|
+
subject { array.page 2 }
|
22
|
+
it { should have(25).users }
|
23
|
+
its(:first) { should == 26 }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'page without an argument' do
|
27
|
+
subject { array.page }
|
28
|
+
it_should_behave_like 'the first page of array'
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'page < 1' do
|
32
|
+
subject { array.page 0 }
|
33
|
+
it_should_behave_like 'the first page of array'
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'page > max page' do
|
37
|
+
subject { array.page 5 }
|
38
|
+
it_should_behave_like 'blank array page'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#per' do
|
43
|
+
context 'page 1 per 5' do
|
44
|
+
subject { array.page(1).per(5) }
|
45
|
+
it { should have(5).users }
|
46
|
+
its(:first) { should == 1 }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#num_pages' do
|
51
|
+
context 'per 25 (default)' do
|
52
|
+
subject { array.page }
|
53
|
+
its(:num_pages) { should == 4 }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'per 7' do
|
57
|
+
subject { array.page(2).per(7) }
|
58
|
+
its(:num_pages) { should == 15 }
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'per 65536' do
|
62
|
+
subject { array.page(50).per(65536) }
|
63
|
+
its(:num_pages) { should == 1 }
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'per 0 (using default)' do
|
67
|
+
subject { array.page(50).per(0) }
|
68
|
+
its(:num_pages) { should == 4 }
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'per -1 (using default)' do
|
72
|
+
subject { array.page(5).per(-1) }
|
73
|
+
its(:num_pages) { should == 4 }
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'per "String value that can not be converted into Number" (using default)' do
|
77
|
+
subject { array.page(5).per('aho') }
|
78
|
+
its(:num_pages) { should == 4 }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#current_page' do
|
83
|
+
context 'page 1' do
|
84
|
+
subject { array.page }
|
85
|
+
its(:current_page) { should == 1 }
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'page 2' do
|
89
|
+
subject { array.page(2).per 3 }
|
90
|
+
its(:current_page) { should == 2 }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#count' do
|
95
|
+
context 'page 1' do
|
96
|
+
subject { array.page }
|
97
|
+
its(:count) { should == 25 }
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'page 2' do
|
101
|
+
subject { array.page 2 }
|
102
|
+
its(:count) { should == 25 }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe 'default per_page' do
|
4
|
+
describe 'AR::Base' do
|
5
|
+
subject { ActiveRecord::Base }
|
6
|
+
it { should_not respond_to :paginates_per }
|
7
|
+
end
|
8
|
+
|
9
|
+
subject { User.page 0 }
|
10
|
+
|
11
|
+
context 'by default' do
|
12
|
+
its(:limit_value) { should == 25 }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when explicitly set via paginates_per' do
|
16
|
+
before { User.paginates_per 1326 }
|
17
|
+
its(:limit_value) { should == 1326 }
|
18
|
+
after { User.paginates_per nil }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "default per_page value's independency per model" do
|
22
|
+
context "when User's default per_page was changed" do
|
23
|
+
before { User.paginates_per 1326 }
|
24
|
+
subject { Book.page 0 }
|
25
|
+
its(:limit_value) { should == 25 }
|
26
|
+
after { User.paginates_per nil }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|