Browse files

Merge pull request #129 from pcg79/master

Added ability to change PaginatedCollection's total_count/total_entries
  • Loading branch information...
2 parents e7a2dad + 5411a56 commit e3b4b20ba6f8559b74b34775ca669e0952299d75 @alindeman alindeman committed Nov 28, 2011
View
8 sunspot/lib/sunspot/search/paginated_collection.rb
@@ -4,8 +4,10 @@ module Search
class PaginatedCollection
instance_methods.each { |m| undef_method m unless m =~ /^__|instance_eval|object_id/ }
- attr_reader :total_count, :current_page, :per_page
+ attr_reader :current_page, :per_page
+ attr_accessor :total_count
alias :total_entries :total_count
+ alias :total_entries= :total_count=
alias :limit_value :per_page
def initialize(collection, page, per_page, total)
@@ -34,12 +36,12 @@ def previous_page
def next_page
current_page < total_pages ? (current_page + 1) : nil
- end
+ end
def out_of_bounds?
current_page > total_pages
end
-
+
def offset
(current_page - 1) * per_page
end
View
10 sunspot/spec/api/search/paginated_collection_spec.rb
@@ -14,6 +14,16 @@
it { subject.next_page.should eql(2) }
it { subject.out_of_bounds?.should_not be_true }
it { subject.offset.should eql(0) }
+
+ it 'should allow setting total_count' do
+ subject.total_count = 1
+ subject.total_count.should eql(1)
+ end
+
+ it 'should allow setting total_entries' do
+ subject.total_entries = 1
+ subject.total_entries.should eql(1)
+ end
end
context "behaves like Kaminari" do

0 comments on commit e3b4b20

Please sign in to comment.