objectreload-pagination 0.1.6 → 0.1.7
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/lib/pagination/collection.rb +1 -1
- data/test/collection_test.rb +11 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
@@ -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.empty? ? 0 : @collection.count(:id , :distinct => true)
|
23
23
|
end
|
24
24
|
|
25
25
|
raise InvalidPage.new(@current_page) if @current_page < 1
|
data/test/collection_test.rb
CHANGED
@@ -63,6 +63,17 @@ class CollectionTest < Test::Unit::TestCase
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
context "collection is empty" do
|
67
|
+
setup do
|
68
|
+
@collection = []
|
69
|
+
@paginated_collection = paginate_collection(@collection, 1, 1)
|
70
|
+
end
|
71
|
+
|
72
|
+
should "return total entries equal 0" do
|
73
|
+
assert_equal @paginated_collection.total_entries, 0
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
66
77
|
context "having already paginated collection" do
|
67
78
|
setup do
|
68
79
|
@collection = (11..20).to_a
|