Commit 6e62e02986afc071095dcc3b518b172869957f0b

Authored by Andrew Kane
1 parent d5a5e16d

Added offset method [skip ci]

lib/searchkick/relation.rb
... ... @@ -38,6 +38,16 @@ module Searchkick
38 38 self
39 39 end
40 40  
  41 + def offset(value)
  42 + clone.offset!(value)
  43 + end
  44 +
  45 + def offset!(value)
  46 + check_loaded
  47 + @options[:offset] = value
  48 + self
  49 + end
  50 +
41 51 def loaded?
42 52 !@execute.nil?
43 53 end
... ...
test/pagination_test.rb
... ... @@ -34,6 +34,11 @@ class PaginationTest < Minitest::Test
34 34 assert_order "product", ["Product C", "Product D"], order: {name: :asc}, offset: 2, limit: 100
35 35 end
36 36  
  37 + def test_offset_relation
  38 + store_names ["Product A", "Product B", "Product C", "Product D"]
  39 + assert_equal ["Product C", "Product D"], Product.search("product", order: {name: :asc}).offset(2).limit(100).map(&:name)
  40 + end
  41 +
37 42 def test_pagination
38 43 store_names ["Product A", "Product B", "Product C", "Product D", "Product E", "Product F"]
39 44 products = Product.search("product", order: {name: :asc}, page: 2, per_page: 2, padding: 1)
... ...