rails_paginate 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,11 +2,16 @@ source "http://rubygems.org"
2
2
  gem "rails", "~> 3.0.0"
3
3
 
4
4
  group :development do
5
- gem "sqlite3"
6
5
  gem "autotest"
7
6
  gem "bundler"
8
7
  gem "jeweler"
9
- gem 'simplecov', :require => false
10
8
  gem "rspec"
11
9
  gem "yard"
10
+ if defined? JRUBY_VERSION
11
+ gem "activerecord-jdbc-adapter"
12
+ gem "activerecord-jdbcsqlite3-adapter"
13
+ else
14
+ gem 'simplecov', :require => false
15
+ gem "sqlite3"
16
+ end
12
17
  end
data/Gemfile.lock CHANGED
@@ -87,6 +87,7 @@ GEM
87
87
  yard (0.6.4)
88
88
 
89
89
  PLATFORMS
90
+ java
90
91
  ruby
91
92
 
92
93
  DEPENDENCIES
data/README.rdoc CHANGED
@@ -1,7 +1,6 @@
1
1
  = rails_paginate
2
2
 
3
3
  a new rails 3 paginate plugin as will_paginate replacement
4
- better as will_paginate
5
4
 
6
5
  == Development status
7
6
 
@@ -31,6 +30,12 @@ If you want to use it as plugin
31
30
 
32
31
  (1..555).to_a.paginate :page => 1, :per_page => 10
33
32
 
33
+ == Test environments
34
+
35
+ * ruby-1.9.2
36
+ * ruby-1.8.7
37
+ * ree-1.8.7
38
+ * jruby-1.5.6
34
39
 
35
40
  == Maintainers
36
41
 
data/Rakefile CHANGED
@@ -19,10 +19,6 @@ Jeweler::Tasks.new do |gem|
19
19
  gem.description = %Q{a new rails 3 paginate plugin as will_paginate replacement}
20
20
  gem.email = "develop@marco-scholl.de"
21
21
  gem.authors = ["Marco Scholl"]
22
- # Include your dependencies below. Runtime dependencies are required when using your gem,
23
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
- # gem.add_development_dependency 'rspec', '> 1.2.3'
26
22
  end
27
23
  Jeweler::RubygemsDotOrgTasks.new
28
24
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -17,7 +17,6 @@ module RailsPaginate
17
17
  mattr_accessor :method
18
18
  @@method = :sliding
19
19
 
20
-
21
20
  class << self
22
21
  # to configure rails_paginate
23
22
  # for a sample look the readme.rdoc file
@@ -43,6 +42,7 @@ module RailsPaginate
43
42
  end
44
43
  end
45
44
 
45
+ # init rails paginate
46
46
  def init
47
47
  require 'rails_paginate/core_ext/active_record'
48
48
  require 'rails_paginate/core_ext/array'
@@ -37,10 +37,12 @@ module RailsPaginate
37
37
  # load result from input array_or_relation to internal array
38
38
  def load_result
39
39
  if array_or_relation.is_a? Array
40
- self.replace array_or_relation[offset..(offset + per_page - 1)]
40
+ result = array_or_relation[offset..(offset + per_page - 1)]
41
41
  else
42
- self.replace array_or_relation.limit(@per_page).offset(offset).all
42
+ result = array_or_relation.limit(per_page).offset(offset).all
43
43
  end
44
+
45
+ self.replace result.nil? ? [] : result
44
46
  end
45
47
 
46
48
  def total
@@ -48,7 +50,7 @@ module RailsPaginate
48
50
  end
49
51
 
50
52
  def pages
51
- @pages ||= (total / per_page.to_f).ceil
53
+ @pages ||= total == 0 ? 1 : (total / per_page.to_f).ceil
52
54
  end
53
55
 
54
56
  # get offset
@@ -1,6 +1,5 @@
1
1
  module RailsPaginate::Method
2
2
  # base method
3
3
  class Base
4
-
5
4
  end
6
5
  end
@@ -1,6 +1,5 @@
1
1
  module RailsPaginate::Renderer
2
2
  # base method
3
3
  class Base
4
-
5
4
  end
6
5
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails_paginate}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marco Scholl"]
12
- s.date = %q{2011-02-15}
12
+ s.date = %q{2011-02-16}
13
13
  s.description = %q{a new rails 3 paginate plugin as will_paginate replacement}
14
14
  s.email = %q{develop@marco-scholl.de}
15
15
  s.extra_rdoc_files = [
@@ -64,32 +64,32 @@ Gem::Specification.new do |s|
64
64
 
65
65
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
66
  s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"])
67
- s.add_development_dependency(%q<sqlite3>, [">= 0"])
68
67
  s.add_development_dependency(%q<autotest>, [">= 0"])
69
68
  s.add_development_dependency(%q<bundler>, [">= 0"])
70
69
  s.add_development_dependency(%q<jeweler>, [">= 0"])
71
- s.add_development_dependency(%q<simplecov>, [">= 0"])
72
70
  s.add_development_dependency(%q<rspec>, [">= 0"])
73
71
  s.add_development_dependency(%q<yard>, [">= 0"])
72
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
73
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
74
74
  else
75
75
  s.add_dependency(%q<rails>, ["~> 3.0.0"])
76
- s.add_dependency(%q<sqlite3>, [">= 0"])
77
76
  s.add_dependency(%q<autotest>, [">= 0"])
78
77
  s.add_dependency(%q<bundler>, [">= 0"])
79
78
  s.add_dependency(%q<jeweler>, [">= 0"])
80
- s.add_dependency(%q<simplecov>, [">= 0"])
81
79
  s.add_dependency(%q<rspec>, [">= 0"])
82
80
  s.add_dependency(%q<yard>, [">= 0"])
81
+ s.add_dependency(%q<simplecov>, [">= 0"])
82
+ s.add_dependency(%q<sqlite3>, [">= 0"])
83
83
  end
84
84
  else
85
85
  s.add_dependency(%q<rails>, ["~> 3.0.0"])
86
- s.add_dependency(%q<sqlite3>, [">= 0"])
87
86
  s.add_dependency(%q<autotest>, [">= 0"])
88
87
  s.add_dependency(%q<bundler>, [">= 0"])
89
88
  s.add_dependency(%q<jeweler>, [">= 0"])
90
- s.add_dependency(%q<simplecov>, [">= 0"])
91
89
  s.add_dependency(%q<rspec>, [">= 0"])
92
90
  s.add_dependency(%q<yard>, [">= 0"])
91
+ s.add_dependency(%q<simplecov>, [">= 0"])
92
+ s.add_dependency(%q<sqlite3>, [">= 0"])
93
93
  end
94
94
  end
95
95
 
@@ -55,10 +55,26 @@ describe RailsPaginate::Collection do
55
55
  it { should be_a RailsPaginate::Collection }
56
56
  end
57
57
 
58
+ context "without any result" do
59
+ before(:all) { @collection = Item.where(:dummy => "dasfindeterbestimmtnicht").paginate :page => 1 }
60
+ subject { @collection }
61
+ its(:count) { should eq 0 }
62
+ its(:current_page) { should eq 1 }
63
+ its(:pages) { should eq 1 }
64
+ its(:total) { should eq 0 }
65
+ its(:offset) { should eq 0 }
66
+ its(:next_page) { should be_nil }
67
+ its(:previous_page) { should be_nil }
68
+ its(:need_paginate?) { should be_false }
69
+ its(:first_page?) { should be_true }
70
+ its(:last_page?) { should be_true }
71
+ end
72
+
58
73
  context "without per_page on first page" do
59
74
  before(:all) { @collection = Item.paginate :page => 1 }
60
75
  subject { @collection }
61
76
  its(:count) { should eq 10 }
77
+ its(:current_page) { should eq 1 }
62
78
  its(:pages) { should eq 57 }
63
79
  its(:total) { should eq 561 }
64
80
  its(:offset) { should eq 0 }
@@ -73,6 +89,7 @@ describe RailsPaginate::Collection do
73
89
  before(:all) { @collection = Item.paginate :page => 10 }
74
90
  subject { @collection }
75
91
  its(:count) { should eq 10 }
92
+ its(:current_page) { should eq 10 }
76
93
  its(:pages) { should eq 57 }
77
94
  its(:total) { should eq 561 }
78
95
  its(:offset) { should eq 90 }
@@ -87,6 +104,7 @@ describe RailsPaginate::Collection do
87
104
  before(:all) { @collection = Item.paginate :page => 57 }
88
105
  subject { @collection }
89
106
  its(:count) { should eq 1 }
107
+ its(:current_page) { should eq 57 }
90
108
  its(:pages) { should eq 57 }
91
109
  its(:total) { should eq 561 }
92
110
  its(:offset) { should eq 560 }
@@ -97,10 +115,11 @@ describe RailsPaginate::Collection do
97
115
  its(:last_page?) { should be_true }
98
116
  end
99
117
 
100
- context "with per_page 60 on page 4" do
118
+ context "with per_page 60 on page 3" do
101
119
  before(:all) { @collection = Item.paginate :page => 3, :per_page => 60 }
102
120
  subject { @collection }
103
121
  its(:count) { should eq 60 }
122
+ its(:current_page) { should eq 3 }
104
123
  its(:pages) { should eq 10 }
105
124
  its(:total) { should eq 561 }
106
125
  its(:offset) { should eq 120 }
@@ -113,6 +132,32 @@ describe RailsPaginate::Collection do
113
132
 
114
133
  end
115
134
 
135
+ describe Array, "with 0 items" do
136
+ before(:all) { @array = [] }
137
+ subject { @array }
138
+ specify { should respond_to :paginate }
139
+
140
+ describe "return of #paginate" do
141
+ subject { @array.paginate }
142
+ it { should be_a RailsPaginate::Collection }
143
+ end
144
+
145
+ context "without per_page on first page" do
146
+ before(:all) { @collection = @array.paginate :page => 1 }
147
+ subject { @collection }
148
+ its(:count) { should eq 0 }
149
+ its(:current_page) { should eq 1 }
150
+ its(:pages) { should eq 1 }
151
+ its(:total) { should eq 0 }
152
+ its(:offset) { should eq 0 }
153
+ its(:next_page) { should be_nil }
154
+ its(:previous_page) { should be_nil }
155
+ its(:need_paginate?) { should be_false }
156
+ its(:first_page?) { should be_true }
157
+ its(:last_page?) { should be_true }
158
+ end
159
+ end
160
+
116
161
  describe Array, "with 199 items" do
117
162
  before(:all) { @array = (1..199).to_a }
118
163
  subject { @array }
@@ -127,6 +172,7 @@ describe RailsPaginate::Collection do
127
172
  before(:all) { @collection = @array.paginate :page => 1 }
128
173
  subject { @collection }
129
174
  its(:count) { should eq 10 }
175
+ its(:current_page) { should eq 1 }
130
176
  its(:pages) { should eq 20 }
131
177
  its(:total) { should eq 199 }
132
178
  its(:offset) { should eq 0 }
@@ -141,6 +187,7 @@ describe RailsPaginate::Collection do
141
187
  before(:all) { @collection = @array.paginate :page => 10 }
142
188
  subject { @collection }
143
189
  its(:count) { should eq 10 }
190
+ its(:current_page) { should eq 10 }
144
191
  its(:pages) { should eq 20 }
145
192
  its(:total) { should eq 199 }
146
193
  its(:offset) { should eq 90 }
@@ -155,6 +202,7 @@ describe RailsPaginate::Collection do
155
202
  before(:all) { @collection = @array.paginate :page => 20 }
156
203
  subject { @collection }
157
204
  its(:count) { should eq 9 }
205
+ its(:current_page) { should eq 20 }
158
206
  its(:pages) { should eq 20 }
159
207
  its(:total) { should eq 199 }
160
208
  its(:offset) { should eq 190 }
@@ -165,10 +213,11 @@ describe RailsPaginate::Collection do
165
213
  its(:last_page?) { should be_true }
166
214
  end
167
215
 
168
- context "with per_page 60 on page 4" do
216
+ context "with per_page 60 on page 3" do
169
217
  before(:all) { @collection = @array.paginate :page => 3, :per_page => 60 }
170
218
  subject { @collection }
171
219
  its(:count) { should eq 60 }
220
+ its(:current_page) { should eq 3 }
172
221
  its(:pages) { should eq 4 }
173
222
  its(:total) { should eq 199 }
174
223
  its(:offset) { should eq 120 }
@@ -187,6 +236,7 @@ describe RailsPaginate::Collection do
187
236
  before(:all) { @collection = @array.paginate :page => 1 }
188
237
  subject { @collection }
189
238
  its(:count) { should eq 6 }
239
+ its(:current_page) { should eq 1 }
190
240
  its(:pages) { should eq 1 }
191
241
  its(:total) { should eq 6 }
192
242
  its(:offset) { should eq 0 }
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'simplecov'
4
- SimpleCov.start 'rails'
3
+ unless defined? JRUBY_VERSION
4
+ require 'simplecov'
5
+ SimpleCov.start 'rails'
6
+ end
7
+
5
8
  require 'rspec'
6
9
  require 'rails_paginate'
7
10
 
@@ -1,5 +1,5 @@
1
1
  ActiveRecord::Base.establish_connection({
2
- :adapter => 'sqlite3',
2
+ :adapter => (defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3'),
3
3
  :database => ":memory:"
4
4
  })
5
5
  ActiveRecord::Migrator.up(File.join(File.dirname(__FILE__), '..', 'db', 'migrate'))
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rails_paginate
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Marco Scholl
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-15 00:00:00 +01:00
13
+ date: 2011-02-16 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -25,7 +25,7 @@ dependencies:
25
25
  prerelease: false
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
- name: sqlite3
28
+ name: autotest
29
29
  requirement: &id002 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
@@ -36,7 +36,7 @@ dependencies:
36
36
  prerelease: false
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
39
- name: autotest
39
+ name: bundler
40
40
  requirement: &id003 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
@@ -47,7 +47,7 @@ dependencies:
47
47
  prerelease: false
48
48
  version_requirements: *id003
49
49
  - !ruby/object:Gem::Dependency
50
- name: bundler
50
+ name: jeweler
51
51
  requirement: &id004 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
@@ -58,7 +58,7 @@ dependencies:
58
58
  prerelease: false
59
59
  version_requirements: *id004
60
60
  - !ruby/object:Gem::Dependency
61
- name: jeweler
61
+ name: rspec
62
62
  requirement: &id005 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
@@ -69,7 +69,7 @@ dependencies:
69
69
  prerelease: false
70
70
  version_requirements: *id005
71
71
  - !ruby/object:Gem::Dependency
72
- name: simplecov
72
+ name: yard
73
73
  requirement: &id006 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
@@ -80,7 +80,7 @@ dependencies:
80
80
  prerelease: false
81
81
  version_requirements: *id006
82
82
  - !ruby/object:Gem::Dependency
83
- name: rspec
83
+ name: simplecov
84
84
  requirement: &id007 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
@@ -91,7 +91,7 @@ dependencies:
91
91
  prerelease: false
92
92
  version_requirements: *id007
93
93
  - !ruby/object:Gem::Dependency
94
- name: yard
94
+ name: sqlite3
95
95
  requirement: &id008 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
@@ -153,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
153
  requirements:
154
154
  - - ">="
155
155
  - !ruby/object:Gem::Version
156
- hash: 2756331228915534243
156
+ hash: -3849386219473513286
157
157
  segments:
158
158
  - 0
159
159
  version: "0"