mongoid-scroll 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73c44f9f9dcdc554e3f0ab2701cb4c87822bdf905bd7212e6bb59ea66e6a454d
4
- data.tar.gz: 6e2abaa7d08e7bf0dfb914fc26b51b1d835526c8d0b1bc75fb0577adf06edb8d
3
+ metadata.gz: 26aa74f5571582e25321e096612b63056c8ac9839299434ee2007ba778042421
4
+ data.tar.gz: 95b7d7739e45b8a38b15ff74af68be5f25bc8c346dd291c0f062d14c46439c71
5
5
  SHA512:
6
- metadata.gz: ea72567b1edb2d8df27dc309d685804a8f199ff060ad93cb64ef01b6fd098a4ae7f677242375a89875bbdb8f8104f238cb6d79fb667799b5e90c297ce96d0e6f
7
- data.tar.gz: ab22160efc873bf42430292047661de3b532a0629326dbfdc93a2ef49bc64207725b405472410171e96e6f997e5a23fc5914698b488a4fd1cacb29021bd70261
6
+ metadata.gz: 886b6450b7aa4d0d0ee768ba59752464ba8e3743649990e99349bc03540c1715ba10ecbe845cfaa9a27a9e7082d3d205e99ae1d6651bd8f3a403ba02615bbee7
7
+ data.tar.gz: f16fad09019d31f73d436352efd83fb7278a716d61d25c055ceae678c8cd3bfec2815e408861ff578039c6f20fcba230a0e1695522bcf523acf06d269317ddb8
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2023-03-07 08:58:13 -0500 using RuboCop version 0.49.1.
3
+ # on 2023-03-09 01:14:57 +0100 using RuboCop version 0.49.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -20,7 +20,7 @@ Metrics/AbcSize:
20
20
  # Offense count: 18
21
21
  # Configuration parameters: CountComments, ExcludedMethods.
22
22
  Metrics/BlockLength:
23
- Max: 258
23
+ Max: 274
24
24
 
25
25
  # Offense count: 1
26
26
  # Configuration parameters: CountComments.
@@ -31,7 +31,7 @@ Metrics/ClassLength:
31
31
  Metrics/CyclomaticComplexity:
32
32
  Max: 13
33
33
 
34
- # Offense count: 146
34
+ # Offense count: 153
35
35
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
36
36
  # URISchemes: http, https
37
37
  Metrics/LineLength:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 1.0.1 (2023/03/15)
2
+
3
+ * [#36](https://github.com/mongoid/mongoid-scroll/pull/36): Keep millisecond precision on time fields - [@FabienChaynes](https://github.com/FabienChaynes).
4
+
1
5
  ### 1.0.0 (2023/03/08)
2
6
 
3
7
  * [#25](https://github.com/mongoid/mongoid-scroll/pull/25): Compatibility with Ruby 3 - [@leamotta](https://github.com/leamotta).
@@ -55,8 +55,8 @@ module Mongoid
55
55
  case field_type.to_s
56
56
  when 'BSON::ObjectId' then BSON::ObjectId.from_string(value)
57
57
  when 'String' then value.to_s == '' ? nil : value.to_s
58
- when 'DateTime' then value.is_a?(DateTime) ? value : Time.at(value.to_i).to_datetime
59
- when 'Time' then value.is_a?(Time) ? value : Time.at(value.to_i)
58
+ when 'DateTime' then value.is_a?(DateTime) ? value : Time.at(value.to_f).to_datetime
59
+ when 'Time' then value.is_a?(Time) ? value : Time.at(value.to_f)
60
60
  when 'Date' then value.is_a?(Date) ? value : Time.at(value.to_i).utc.to_date
61
61
  when 'Float' then value.to_f
62
62
  when 'Integer' then value.to_i
@@ -72,7 +72,7 @@ module Mongoid
72
72
  when 'BSON::ObjectId' then value.to_s
73
73
  when 'String' then value.to_s
74
74
  when 'Date' then Time.utc(value.year, value.month, value.day).to_i
75
- when 'DateTime', 'Time' then value.utc.to_i
75
+ when 'DateTime', 'Time' then value.utc.to_f.round(3)
76
76
  when 'Float' then value.to_f
77
77
  when 'Integer' then value.to_i
78
78
  else
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Scroll
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '1.0.1'.freeze
4
4
  end
5
5
  end
@@ -77,7 +77,7 @@ describe Mongoid::Scroll::Base64EncodedCursor do
77
77
  its(:to_s) { should eq(base64_string) }
78
78
  end
79
79
  context 'a date/time field cursor' do
80
- let(:base64_string) { 'eyJ2YWx1ZSI6MTM4NzU5MDEyMywiZmllbGRfdHlwZSI6IkRhdGVUaW1lIiwiZmllbGRfbmFtZSI6ImFfZGF0ZXRpbWUiLCJkaXJlY3Rpb24iOjEsImluY2x1ZGVfY3VycmVudCI6ZmFsc2UsInRpZWJyZWFrX2lkIjoiNjQwNjQzYTcwOTQ0MzQyMzlmMmRiZjg2In0=' }
80
+ let(:base64_string) { 'eyJ2YWx1ZSI6MTM4NzU5MDEyMy4wLCJmaWVsZF90eXBlIjoiRGF0ZVRpbWUiLCJmaWVsZF9uYW1lIjoiYV9kYXRldGltZSIsImRpcmVjdGlvbiI6MSwiaW5jbHVkZV9jdXJyZW50IjpmYWxzZSwidGllYnJlYWtfaWQiOiI2NDA2NDNhNzA5NDQzNDIzOWYyZGJmODYifQ==' }
81
81
  let(:a_value) { DateTime.new(2013, 12, 21, 1, 42, 3, 'UTC') }
82
82
  let(:tiebreak_id) { BSON::ObjectId('640643a7094434239f2dbf86') }
83
83
  let(:criteria) do
@@ -117,7 +117,7 @@ describe Mongoid::Scroll::Base64EncodedCursor do
117
117
  its(:to_s) { should eq(base64_string) }
118
118
  end
119
119
  context 'a time field cursor' do
120
- let(:base64_string) { 'eyJ2YWx1ZSI6MTM4NzYwNTcyMywiZmllbGRfdHlwZSI6IlRpbWUiLCJmaWVsZF9uYW1lIjoiYV90aW1lIiwiZGlyZWN0aW9uIjoxLCJpbmNsdWRlX2N1cnJlbnQiOmZhbHNlLCJ0aWVicmVha19pZCI6IjY0MDYzZDRhMDk0NDM0MTY2YmQwNTNlZCJ9' }
120
+ let(:base64_string) { 'eyJ2YWx1ZSI6MTM4NzYwNTcyMy4wLCJmaWVsZF90eXBlIjoiVGltZSIsImZpZWxkX25hbWUiOiJhX3RpbWUiLCJkaXJlY3Rpb24iOjEsImluY2x1ZGVfY3VycmVudCI6ZmFsc2UsInRpZWJyZWFrX2lkIjoiNjQwNjNkNGEwOTQ0MzQxNjZiZDA1M2VkIn0=' }
121
121
  let(:item_id) { BSON::ObjectId('640636f209443407333b46d4') }
122
122
  let(:a_value) { Time.new(2013, 12, 21, 6, 2, 3, '+00:00').utc }
123
123
  let(:tiebreak_id) { BSON::ObjectId('64063d4a094434166bd053ed') }
@@ -260,6 +260,23 @@ describe Mongoid::Criteria do
260
260
  expect(items).to eq([second_item, third_item])
261
261
  end
262
262
  end
263
+ context 'with DateTime with a milisecond precision' do
264
+ let!(:item_1) { Feed::Item.create!(a_datetime: DateTime.new(2013, 1, 21, 1, 42, 3.1, 'UTC')) }
265
+ let!(:item_2) { Feed::Item.create!(a_datetime: DateTime.new(2013, 1, 21, 1, 42, 3.2, 'UTC')) }
266
+ let!(:item_3) { Feed::Item.create!(a_datetime: DateTime.new(2013, 1, 21, 1, 42, 3.3, 'UTC')) }
267
+
268
+ it 'doesn\'t lose the precision when rebuilding the cursor' do
269
+ records = []
270
+ cursor = nil
271
+ Feed::Item.order_by(a_datetime: 1).limit(2).scroll(cursor_type) do |record, next_cursor|
272
+ records << record
273
+ cursor = next_cursor
274
+ end
275
+ expect(records).to eq [item_1, item_2]
276
+ cursor = cursor_type.new(cursor.to_s, field: Feed::Item.fields['a_datetime'])
277
+ expect(Feed::Item.order_by(a_datetime: 1).limit(2).scroll(cursor).to_a).to eq([item_3])
278
+ end
279
+ end
263
280
  end
264
281
  end
265
282
  end
@@ -59,11 +59,11 @@ describe Mongoid::Scroll::Cursor do
59
59
  context 'a date/time field cursor' do
60
60
  let(:feed_item) { Feed::Item.create!(a_datetime: DateTime.new(2013, 12, 21, 1, 42, 3, 'UTC')) }
61
61
  subject do
62
- Mongoid::Scroll::Cursor.new "#{feed_item.a_datetime.utc.to_i}:#{feed_item.id}", field_name: 'a_datetime', field_type: DateTime
62
+ Mongoid::Scroll::Cursor.new "#{feed_item.a_datetime.utc.to_f.round(3)}:#{feed_item.id}", field_name: 'a_datetime', field_type: DateTime
63
63
  end
64
64
  its(:value) { should eq feed_item.a_datetime }
65
65
  its(:tiebreak_id) { should eq feed_item.id }
66
- its(:to_s) { should eq "#{feed_item.a_datetime.utc.to_i}:#{feed_item.id}" }
66
+ its(:to_s) { should eq "#{feed_item.a_datetime.utc.to_f.round(3)}:#{feed_item.id}" }
67
67
  its(:criteria) do
68
68
  should eq('$or' => [
69
69
  { 'a_datetime' => { '$gt' => feed_item.a_datetime } },
@@ -89,11 +89,11 @@ describe Mongoid::Scroll::Cursor do
89
89
  context 'a time field cursor' do
90
90
  let(:feed_item) { Feed::Item.create!(a_time: Time.new(2013, 12, 21, 1, 2, 3)) }
91
91
  subject do
92
- Mongoid::Scroll::Cursor.new "#{feed_item.a_time.to_i}:#{feed_item.id}", field_name: 'a_time', field_type: Time
92
+ Mongoid::Scroll::Cursor.new "#{feed_item.a_time.to_f.round(3)}:#{feed_item.id}", field_name: 'a_time', field_type: Time
93
93
  end
94
94
  its(:value) { should eq feed_item.a_time }
95
95
  its(:tiebreak_id) { should eq feed_item.id }
96
- its(:to_s) { should eq "#{feed_item.a_time.to_i}:#{feed_item.id}" }
96
+ its(:to_s) { should eq "#{feed_item.a_time.to_f.round(3)}:#{feed_item.id}" }
97
97
  its(:criteria) do
98
98
  should eq('$or' => [
99
99
  { 'a_time' => { '$gt' => feed_item.a_time } },
@@ -104,11 +104,11 @@ describe Mongoid::Scroll::Cursor do
104
104
  context 'a time field cursor with a field option' do
105
105
  let(:feed_item) { Feed::Item.create!(a_time: Time.new(2013, 12, 21, 1, 2, 3)) }
106
106
  subject do
107
- Mongoid::Scroll::Cursor.new "#{feed_item.a_time.to_i}:#{feed_item.id}", field: Feed::Item.fields['a_time']
107
+ Mongoid::Scroll::Cursor.new "#{feed_item.a_time.to_f.round(3)}:#{feed_item.id}", field: Feed::Item.fields['a_time']
108
108
  end
109
109
  its(:value) { should eq feed_item.a_time }
110
110
  its(:tiebreak_id) { should eq feed_item.id }
111
- its(:to_s) { should eq "#{feed_item.a_time.to_i}:#{feed_item.id}" }
111
+ its(:to_s) { should eq "#{feed_item.a_time.to_f.round(3)}:#{feed_item.id}" }
112
112
  its(:criteria) do
113
113
  should eq('$or' => [
114
114
  { 'a_time' => { '$gt' => feed_item.a_time } },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-scroll
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-03-08 00:00:00.000000000 Z
12
+ date: 2023-03-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid