objectreload-pagination 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/pagination.rb +5 -1
- data/lib/pagination/collection.rb +2 -2
- data/test/collection_test.rb +10 -5
- data/test/lib/view_test_process.rb +4 -1
- data/test/view_helpers_test.rb +6 -1
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
data/lib/pagination.rb
CHANGED
@@ -9,4 +9,8 @@ require 'pagination/enumerable'
|
|
9
9
|
require 'pagination/view_helpers'
|
10
10
|
|
11
11
|
# Loads the :paginate view helper
|
12
|
-
ActionView::Base.send :include, Pagination::ViewHelpers
|
12
|
+
ActionView::Base.send :include, Pagination::ViewHelpers
|
13
|
+
|
14
|
+
if defined?(ActionController::Base) and ActionController::Base.respond_to? :rescue_responses
|
15
|
+
ActionController::Base.rescue_responses['Pagination::InvalidPage'] = :not_found
|
16
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Pagination
|
2
|
-
class InvalidPage <
|
2
|
+
class InvalidPage < ArgumentError
|
3
3
|
def initialize(page, max = 1)
|
4
4
|
super "#{page} must be greater than 0" if page < 1
|
5
5
|
super "#{page} must be less than #{max}" if page >= 1
|
@@ -19,7 +19,7 @@ module Pagination
|
|
19
19
|
else
|
20
20
|
@current_page = options[:current_page].to_i
|
21
21
|
@per_page = options[:per_page].to_i
|
22
|
-
self.total_entries ||= @collection.count(:
|
22
|
+
self.total_entries ||= @collection.count(:distinct => true, :select => :id)
|
23
23
|
end
|
24
24
|
|
25
25
|
raise InvalidPage.new(@current_page) if @current_page < 1
|
data/test/collection_test.rb
CHANGED
@@ -5,7 +5,9 @@ require File.dirname(__FILE__) + '/../lib/pagination/enumerable'
|
|
5
5
|
class CollectionTest < Test::Unit::TestCase
|
6
6
|
context "collection test" do
|
7
7
|
setup do
|
8
|
-
|
8
|
+
Article.destroy_all
|
9
|
+
5.times {|i| Article.create!(:id => i, :user => User.create)}
|
10
|
+
@collection = Article.all
|
9
11
|
end
|
10
12
|
|
11
13
|
should "return elements from specific range" do
|
@@ -13,9 +15,9 @@ class CollectionTest < Test::Unit::TestCase
|
|
13
15
|
# limit = per_page
|
14
16
|
# offset = (current_page - 1) * limit
|
15
17
|
[
|
16
|
-
{ :offset => 0, :limit => 3, :expected =>
|
17
|
-
{ :offset => 3, :limit => 3, :expected =>
|
18
|
-
{ :offset => 0, :limit => 5, :expected =>
|
18
|
+
{ :offset => 0, :limit => 3, :expected => [@collection[0],@collection[1], @collection[2]] },
|
19
|
+
{ :offset => 3, :limit => 3, :expected => [@collection[3],@collection[4]] },
|
20
|
+
{ :offset => 0, :limit => 5, :expected => [@collection[0],@collection[1], @collection[2], @collection[3], @collection[4]] },
|
19
21
|
{ :offset => 6, :limit => 3, :expected => [] },
|
20
22
|
].
|
21
23
|
each do |conditions|
|
@@ -26,7 +28,6 @@ class CollectionTest < Test::Unit::TestCase
|
|
26
28
|
|
27
29
|
context "init pagination collection" do
|
28
30
|
setup do
|
29
|
-
@collection = [1,2,3,4,5]
|
30
31
|
@paginated_collection = paginate_collection(@collection)
|
31
32
|
end
|
32
33
|
|
@@ -56,6 +57,10 @@ class CollectionTest < Test::Unit::TestCase
|
|
56
57
|
should "rise an error ArgumentError" do
|
57
58
|
assert_raise(ArgumentError) { paginate_collection(@collection, 2, -2) }
|
58
59
|
end
|
60
|
+
|
61
|
+
should "test_rescue_response_hook_presence" do
|
62
|
+
assert_equal :not_found, ActionController::Base.rescue_responses['Pagination::InvalidPage']
|
63
|
+
end
|
59
64
|
end
|
60
65
|
|
61
66
|
context "having already paginated collection" do
|
@@ -43,9 +43,12 @@ class Pagination::ViewTestCase < Test::Unit::TestCase
|
|
43
43
|
|
44
44
|
def paginate(collection = {}, options = {}, &block)
|
45
45
|
|
46
|
+
Article.destroy_all
|
47
|
+
11.times {|i| Article.create!(:id => i, :user => User.create)}
|
48
|
+
|
46
49
|
if collection.instance_of? Hash
|
47
50
|
@request.params :page => collection[:page] || 1
|
48
|
-
collection =
|
51
|
+
collection = Article.all
|
49
52
|
end
|
50
53
|
options = {:per_page => 4, :controls => :top}.merge(options)
|
51
54
|
|
data/test/view_helpers_test.rb
CHANGED
@@ -3,6 +3,11 @@ require File.dirname(__FILE__) + '/lib/view_test_process'
|
|
3
3
|
|
4
4
|
class ViewHelpersTest < Pagination::ViewTestCase
|
5
5
|
context "paginate method" do
|
6
|
+
setup do
|
7
|
+
Article.destroy_all
|
8
|
+
5.times {|i| Article.create!(:id => i, :user => User.create)}
|
9
|
+
@collection = Article.all
|
10
|
+
end
|
6
11
|
|
7
12
|
should "return full output" do
|
8
13
|
paginate({:page => 1})
|
@@ -123,7 +128,7 @@ class ViewHelpersTest < Pagination::ViewTestCase
|
|
123
128
|
|
124
129
|
# magic ID
|
125
130
|
paginate({}, :id => true) do |div|
|
126
|
-
assert_equal '
|
131
|
+
assert_equal 'articles_pagination', div.first['id']
|
127
132
|
end
|
128
133
|
|
129
134
|
# explicit ID
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 6
|
9
|
+
version: 0.1.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mateusz Drozdzynski
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-07-01 00:00:00 +03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -79,8 +79,8 @@ signing_key:
|
|
79
79
|
specification_version: 3
|
80
80
|
summary: Simple pagination - without changes in controllers
|
81
81
|
test_files:
|
82
|
+
- test/lib/view_test_process.rb
|
82
83
|
- test/active_record_extentions_test.rb
|
83
84
|
- test/collection_test.rb
|
84
|
-
- test/lib/view_test_process.rb
|
85
|
-
- test/test_helper.rb
|
86
85
|
- test/view_helpers_test.rb
|
86
|
+
- test/test_helper.rb
|