sequel-seek-pagination 0.2.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f9206a9a384b1cdf9e934dc6e414c7e31a7572b
4
- data.tar.gz: e717fb468e5a8224e5c7cd48e1b40b91bffb318f
3
+ metadata.gz: e681598557874a5b7102fd630deef04e48dd08ec
4
+ data.tar.gz: 176755ad95e8e78978dac323661a9b9f55762a0d
5
5
  SHA512:
6
- metadata.gz: e358d7edefd328fa41a0378f52f25c4c3e05b98b0da49a74742241a2f487ef8eb383dd615f67c678a4b8ed54c11e4d6e917baa3560a6787ac7d4cd835430c16d
7
- data.tar.gz: 96b6e87a78cd4c93113d385f53ec37062f56fc031e1e563ca6f0b0fd67b4c95e1432a35f3dd4bc49b272470091179dc428c17b76b8b11da37e072e05e5275f22
6
+ metadata.gz: 4581a836e385d1f061b984fbc14a94d7225d3010d67efb8b1e169f76ff80445044ec1d727bfe28c38761272e68629b1023cea8f683bf87be9c86d42c1bcca124
7
+ data.tar.gz: 7c191afc86655d078da0d2c49b2aab2b6bbb42f21af9558c3ada83a8053ad45f60e3c4e39a2eeb8f251f4e0b9c952b1aacc01fc66c701fb0e7afbcf2de91dc5a
@@ -1,5 +1,5 @@
1
1
  module Sequel
2
2
  module SeekPagination
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
5
5
  end
@@ -26,16 +26,21 @@ module Sequel
26
26
  raise Error, "passed the wrong number of values in the :#{from ? 'from' : 'after'} option to seek_paginate"
27
27
  end
28
28
  elsif pk = from_pk || after_pk
29
- # Need to load the values to order from for that pk from the DB, so we
30
- # need to fetch the actual expressions being ordered by.
31
- expressions = order.map { |o| Sequel::SQL::OrderedExpression === o ? o.expression : o }
29
+ target_ds = where(model.qualified_primary_key_hash(pk))
32
30
 
31
+ # Need to load the values to order from for that pk from the DB, so we
32
+ # need to fetch the actual expressions being ordered by. Also,
33
33
  # Dataset#get won't like it if we pass it expressions that aren't
34
- # simple columns, so give it aliases for everything.
34
+ # simple columns, so we need to give it aliases for everything.
35
35
  al = :a
36
- gettable = expressions.map.with_index{|s,i| Sequel.as(s, (al = al.next))}
36
+ gettable = order.map do |o, i|
37
+ expression = Sequel::SQL::OrderedExpression === o ? o.expression : o
38
+ Sequel.as(expression, (al = al.next))
39
+ end
37
40
 
38
- values = where(model.qualified_primary_key_hash(pk)).get(gettable)
41
+ unless values = target_ds.get(gettable)
42
+ raise NoMatchingRow.new(target_ds)
43
+ end
39
44
  end
40
45
 
41
46
  if values
@@ -211,5 +211,10 @@ class SeekPaginationSpec < Minitest::Spec
211
211
  assert_equal %(SELECT * FROM "seek" WHERE (("not_nullable_1", "not_nullable_2", "id") > (1, 2, 3)) ORDER BY "not_nullable_1", "not_nullable_2", "id" LIMIT 5),
212
212
  SeekModel.order(:not_nullable_1, :not_nullable_2, :id).seek_paginate(5, after: [1, 2, 3]).sql
213
213
  end
214
+
215
+ it "should raise an error when passed a pk for a record that doesn't exist in the dataset" do
216
+ assert_raises(Sequel::NoMatchingRow) { SeekModel.order(:id).seek_paginate(5, after_pk: -45) }
217
+ assert_raises(Sequel::NoMatchingRow) { SeekModel.order(:id).seek_paginate(5, from_pk: -45) }
218
+ end
214
219
  end
215
220
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-seek-pagination
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hanks