Skip to content

Commit

Permalink
keep the whole Array if total_count is given
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Aug 25, 2011
1 parent 6c0d1b6 commit b5e16c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/kaminari/models/array_extension.rb
Expand Up @@ -11,7 +11,12 @@ class PaginatableArray < Array
# * <tt>:total_count</tt> - total_count
def initialize(original_array, options = {})
@_original_array, @_limit_value, @_offset_value, @_total_count = original_array, (options[:limit] || default_per_page).to_i, options[:offset].to_i, options[:total_count]
super(original_array[@_offset_value, @_limit_value] || [])

if options[:total_count]
super original_array
else
super(original_array[@_offset_value, @_limit_value] || [])
end
end

# items at the specified "page"
Expand Down
4 changes: 2 additions & 2 deletions spec/models/array_spec.rb
Expand Up @@ -106,9 +106,9 @@
end

context 'when setting total count explicitly' do
subject { Kaminari::PaginatableArray.new((1..100).to_a, :total_count => 9999).page(5).per(10) }
subject { Kaminari::PaginatableArray.new((1..10).to_a, :total_count => 9999).page(5).per(10) }
it { should have(10).items }
its(:first) { should == 41 }
its(:first) { should == 1 }
its(:total_count) { should == 9999 }
end
end

0 comments on commit b5e16c0

Please sign in to comment.