kaminari 0.1.0 → 0.2.0
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.
- data/VERSION +1 -1
- data/kaminari.gemspec +1 -1
- data/lib/kaminari/active_record.rb +2 -2
- data/spec/models/scopes_spec.rb +18 -18
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.2.0
|
data/kaminari.gemspec
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Kaminari
|
|
2
2
|
module ActiveRecord
|
|
3
3
|
extend ActiveSupport::Concern
|
|
4
|
-
PER_PAGE =
|
|
4
|
+
PER_PAGE = 25
|
|
5
5
|
|
|
6
6
|
included do
|
|
7
7
|
def self.inherited(kls)
|
|
@@ -17,7 +17,7 @@ module Kaminari
|
|
|
17
17
|
scope :page, lambda {|num|
|
|
18
18
|
offset(PER_PAGE * ([num.to_i, 1].max - 1)).limit(PER_PAGE)
|
|
19
19
|
} do
|
|
20
|
-
# page(3).per(
|
|
20
|
+
# page(3).per(10)
|
|
21
21
|
def per(num)
|
|
22
22
|
offset(offset_value / limit_value * num).limit(num)
|
|
23
23
|
end
|
data/spec/models/scopes_spec.rb
CHANGED
|
@@ -3,13 +3,13 @@ require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
|
|
3
3
|
describe Kaminari::ActiveRecord do
|
|
4
4
|
before :all do
|
|
5
5
|
User.delete_all
|
|
6
|
-
1.upto(
|
|
6
|
+
1.upto(100) {|i| User.create! :name => "user#{'%03d' % i}" }
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
describe '#page' do
|
|
10
10
|
shared_examples_for 'the first page' do
|
|
11
|
-
it { should have(
|
|
12
|
-
its('first.name') { should == '
|
|
11
|
+
it { should have(25).users }
|
|
12
|
+
its('first.name') { should == 'user001' }
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
shared_examples_for 'blank page' do
|
|
@@ -23,8 +23,8 @@ describe Kaminari::ActiveRecord do
|
|
|
23
23
|
|
|
24
24
|
context 'page 2' do
|
|
25
25
|
subject { User.page 2 }
|
|
26
|
-
it { should have(
|
|
27
|
-
its('first.name') { should == '
|
|
26
|
+
it { should have(25).users }
|
|
27
|
+
its('first.name') { should == 'user026' }
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
context 'page without an argument' do
|
|
@@ -38,7 +38,7 @@ describe Kaminari::ActiveRecord do
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
context 'page > max page' do
|
|
41
|
-
subject { User.page
|
|
41
|
+
subject { User.page 5 }
|
|
42
42
|
it_should_behave_like 'blank page'
|
|
43
43
|
end
|
|
44
44
|
end
|
|
@@ -47,36 +47,36 @@ describe Kaminari::ActiveRecord do
|
|
|
47
47
|
context 'page 1 per 5' do
|
|
48
48
|
subject { User.page(1).per(5) }
|
|
49
49
|
it { should have(5).users }
|
|
50
|
-
its('first.name') { should == '
|
|
50
|
+
its('first.name') { should == 'user001' }
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
describe '#num_pages' do
|
|
55
|
-
context 'per
|
|
56
|
-
subject { User.page
|
|
57
|
-
|
|
55
|
+
context 'per 25 (default)' do
|
|
56
|
+
subject { User.page }
|
|
57
|
+
its(:num_pages) { should == 4 }
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
context 'per 7' do
|
|
61
|
-
subject { User.page(2).per(7)
|
|
62
|
-
|
|
61
|
+
subject { User.page(2).per(7) }
|
|
62
|
+
its(:num_pages) { should == 15 }
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
context 'per 65536' do
|
|
66
|
-
subject { User.page(50).per(65536)
|
|
67
|
-
|
|
66
|
+
subject { User.page(50).per(65536) }
|
|
67
|
+
its(:num_pages) { should == 1 }
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
describe '#current_page' do
|
|
72
72
|
context 'page 1' do
|
|
73
|
-
subject { User.page
|
|
74
|
-
|
|
73
|
+
subject { User.page }
|
|
74
|
+
its(:current_page) { should == 1 }
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
context 'page 2' do
|
|
78
|
-
subject { User.page(2).per
|
|
79
|
-
|
|
78
|
+
subject { User.page(2).per 3 }
|
|
79
|
+
its(:current_page) { should == 2 }
|
|
80
80
|
end
|
|
81
81
|
end
|
|
82
82
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kaminari
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
8
|
+
- 2
|
|
9
9
|
- 0
|
|
10
|
-
version: 0.
|
|
10
|
+
version: 0.2.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Akira Matsuda
|