objectreload-pagination 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
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(:distinct => true, :select => :id)
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
@@ -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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 6
9
- version: 0.1.6
8
+ - 7
9
+ version: 0.1.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mateusz Drozdzynski