mongoid-scroll 0.3.1 → 0.3.2

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: b18caa6adcba10267216ab4c06890232de3ec0cd
4
- data.tar.gz: b05d520e679bb1d49806470546a546624f0574bf
3
+ metadata.gz: 49f6957fe1cfab726fa346c141eb979487590912
4
+ data.tar.gz: e791fd49a8bf4aa187aaccb5222ada9f1e0dcf89
5
5
  SHA512:
6
- metadata.gz: 7c4c3bbe7deeb838e893f3c19de0160b64b9e4ee66d7c12dbca872181e56c51416c0355d87acb3dd5a33db0d504b11f396c4a59559c2592bf78c74437e9fba66
7
- data.tar.gz: b5a55c6f00c90ae8eed3f3ee3153d07b17159d8c7129b4e5dab3d4719a9d6147804ba20cd00e2c6b8825638f3d77102dafd3556557b6deb92664c79cd4002911
6
+ metadata.gz: 5cdf23a3ee65c76874d71ff8d78cb948c478e8f75b53cc930717493d2bc7ebc13b3787c06c4527eec197bd241b7b7ac4f62ca4ce5eb01cf67f56e54b2438a17b
7
+ data.tar.gz: 9606b19764c8aa3a578e1f7b7f278d9cc4f1ce1849aaa5de5804024dd9a7399b9a4d337febe88dea7f415692268ea1c171091ca6eff0bcc467f15f3f1799d7e3
data/.rubocop_todo.yml CHANGED
@@ -1,11 +1,12 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-07-07 10:17:35 -0400 using RuboCop version 0.32.1.
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-08-08 11:38:01 -0400 using RuboCop version 0.33.0.
3
4
  # The point is for the user to remove these configuration records
4
5
  # one by one as the offenses are removed from the code base.
5
6
  # Note that changes in the inspected code, or installation of new
6
7
  # versions of RuboCop, may require this file to be generated again.
7
8
 
8
- # Offense count: 4
9
+ # Offense count: 5
9
10
  Metrics/AbcSize:
10
11
  Max: 70
11
12
 
@@ -13,7 +14,7 @@ Metrics/AbcSize:
13
14
  Metrics/CyclomaticComplexity:
14
15
  Max: 11
15
16
 
16
- # Offense count: 78
17
+ # Offense count: 83
17
18
  # Configuration parameters: AllowURI, URISchemes.
18
19
  Metrics/LineLength:
19
20
  Max: 170
@@ -27,14 +28,28 @@ Metrics/MethodLength:
27
28
  Metrics/PerceivedComplexity:
28
29
  Max: 12
29
30
 
30
- # Offense count: 12
31
+ # Offense count: 13
31
32
  Style/Documentation:
32
- Enabled: false
33
+ Exclude:
34
+ - 'examples/mongoid_scroll_feed.rb'
35
+ - 'lib/mongoid/criterion/scrollable.rb'
36
+ - 'lib/mongoid/scroll/cursor.rb'
37
+ - 'lib/mongoid/scroll/errors/base.rb'
38
+ - 'lib/mongoid/scroll/errors/invalid_cursor_error.rb'
39
+ - 'lib/mongoid/scroll/errors/multiple_sort_fields_error.rb'
40
+ - 'lib/mongoid/scroll/errors/no_such_field_error.rb'
41
+ - 'lib/mongoid/scroll/errors/unsupported_field_type_error.rb'
42
+ - 'lib/mongoid/scroll/mongoid.rb'
43
+ - 'lib/mongoid/scroll/version.rb'
44
+ - 'lib/moped/scrollable.rb'
45
+ - 'spec/support/feed/embedded_item.rb'
46
+ - 'spec/support/feed/item.rb'
33
47
 
34
48
  # Offense count: 1
35
49
  # Configuration parameters: Exclude.
36
50
  Style/FileName:
37
- Enabled: false
51
+ Exclude:
52
+ - 'lib/mongoid-scroll.rb'
38
53
 
39
54
  # Offense count: 6
40
55
  # Configuration parameters: SupportedStyles.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
+ 0.3.2 (8/8/2015)
2
+ ----------------
3
+
4
+ * [#7](https://github.com/dblock/mongoid-scroll/pull/7): Fix: pre-merge cursor criteria fields - [@sweir27](https://github.com/sweir27).
5
+
1
6
  0.3.1 (7/27/2015)
2
- ------------
7
+ -----------------
3
8
 
4
9
  * Compatibility with Mongoid 5.x beta - [@dblock](https://github.com/dblock).
5
10
  * [#4](https://github.com/dblock/mongoid-scroll/pull/4): Fix: support chaining `$or` criteria - [@sweir27](https://github.com/sweir27).
data/Gemfile CHANGED
@@ -17,5 +17,5 @@ group :development, :test do
17
17
  gem 'rspec', '~> 3.0'
18
18
  gem 'rspec-its'
19
19
  gem 'faker'
20
- gem 'rubocop', '0.32.1'
20
+ gem 'rubocop', '0.33.0'
21
21
  end
@@ -28,7 +28,7 @@ next_cursor = nil
28
28
  loop do
29
29
  current_cursor = next_cursor
30
30
  next_cursor = nil
31
- Mongoid.default_session['feed_items'].find.limit(scroll_by).sort(position: 1).scroll(current_cursor, field_type: Integer, field_name: 'position') do |item, cursor|
31
+ Mongoid.default_session['feed_items'].find.limit(scroll_by).sort(position: 1).scroll(current_cursor, field_type: Integer, field_name: 'position') do |item, cursor|
32
32
  puts "#{item['position']}: #{item['title']}"
33
33
  next_cursor = cursor
34
34
  total_shown += 1
@@ -14,7 +14,9 @@ module Mongoid
14
14
  compare_direction = direction == 1 ? '$gt' : '$lt'
15
15
  cursor_criteria = { field_name => { compare_direction => mongo_value } } if mongo_value
16
16
  tiebreak_criteria = { field_name => mongo_value, :_id => { compare_direction => tiebreak_id } } if mongo_value && tiebreak_id
17
- cursor_criteria || tiebreak_criteria ? { '$or' => [cursor_criteria, tiebreak_criteria].compact } : {}
17
+ cursor_selector = Origin::Selector.new
18
+ cursor_selector.merge!('$or' => [cursor_criteria, tiebreak_criteria].compact) if cursor_criteria || tiebreak_criteria
19
+ cursor_selector.__evolve_object_id__
18
20
  end
19
21
 
20
22
  class << self
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Scroll
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
5
5
  end
@@ -130,6 +130,20 @@ describe Mongoid::Criteria do
130
130
  expect(records.size).to eq 1
131
131
  expect(records.map(&:name)).to eq ['Feed Item 2']
132
132
  end
133
+ it 'merges cursor criteria when no sort field is given' do
134
+ criteria = Feed::Item.where(:a_time.gt => Time.new(2013, 7, 22, 1, 2, 3))
135
+ feed_item_1 = Feed::Item.where(name: 'Feed Item 1').first
136
+ cursor_input = "#{feed_item_1.id}:#{feed_item_1.id}"
137
+ field_type = Mongoid::Scroll.mongoid3? ? Moped::BSON::ObjectId : BSON::ObjectId
138
+ cursor_options = { field_type: field_type, field_name: '_id', direction: 1 }
139
+ cursor = Mongoid::Scroll::Cursor.new(cursor_input, cursor_options)
140
+ records = []
141
+ criteria.limit(2).scroll(cursor) do |record, next_cursor|
142
+ records << record
143
+ cursor = next_cursor
144
+ end
145
+ expect(records.size).to eq 2
146
+ end
133
147
  end
134
148
  context 'with embeddable objects' do
135
149
  before do
@@ -15,6 +15,26 @@ describe Mongoid::Scroll::Cursor do
15
15
  /The cursor supplied is invalid: invalid./
16
16
  end
17
17
  end
18
+ context 'an id field cursor' do
19
+ let(:feed_item) { Feed::Item.create!(a_string: 'astring') }
20
+ field_type = Mongoid::Scroll.mongoid3? ? Moped::BSON::ObjectId : BSON::ObjectId
21
+ subject do
22
+ Mongoid::Scroll::Cursor.new "#{feed_item.id}:#{feed_item.id}", field_name: '_id', field_type: field_type, direction: 1
23
+ end
24
+ its(:value) { should eq feed_item.id.to_s }
25
+ its(:tiebreak_id) { should eq feed_item.id }
26
+ its(:criteria) do
27
+ if Mongoid::Scroll.mongoid3?
28
+ should eq('$or' => [
29
+ { '_id' => { '$gt' => Moped::BSON::ObjectId("#{feed_item.id}") } }
30
+ ])
31
+ else
32
+ should eq('$or' => [
33
+ { '_id' => { '$gt' => BSON::ObjectId("#{feed_item.id}") } }
34
+ ])
35
+ end
36
+ end
37
+ end
18
38
  context 'a string field cursor' do
19
39
  let(:feed_item) { Feed::Item.create!(a_string: 'astring') }
20
40
  subject do
@@ -25,7 +45,7 @@ describe Mongoid::Scroll::Cursor do
25
45
  its(:criteria) do
26
46
  should eq('$or' => [
27
47
  { 'a_string' => { '$gt' => feed_item.a_string } },
28
- { 'a_string' => feed_item.a_string, :_id => { '$gt' => feed_item.id } }
48
+ { 'a_string' => feed_item.a_string, '_id' => { '$gt' => feed_item.id } }
29
49
  ])
30
50
  end
31
51
  end
@@ -39,7 +59,7 @@ describe Mongoid::Scroll::Cursor do
39
59
  its(:criteria) do
40
60
  should eq('$or' => [
41
61
  { 'a_integer' => { '$gt' => feed_item.a_integer } },
42
- { 'a_integer' => feed_item.a_integer, :_id => { '$gt' => feed_item.id } }
62
+ { 'a_integer' => feed_item.a_integer, '_id' => { '$gt' => feed_item.id } }
43
63
  ])
44
64
  end
45
65
  end
@@ -54,7 +74,7 @@ describe Mongoid::Scroll::Cursor do
54
74
  its(:criteria) do
55
75
  should eq('$or' => [
56
76
  { 'a_datetime' => { '$gt' => feed_item.a_datetime } },
57
- { 'a_datetime' => feed_item.a_datetime, :_id => { '$gt' => feed_item.id } }
77
+ { 'a_datetime' => feed_item.a_datetime, '_id' => { '$gt' => feed_item.id } }
58
78
  ])
59
79
  end
60
80
  end
@@ -69,7 +89,7 @@ describe Mongoid::Scroll::Cursor do
69
89
  its(:criteria) do
70
90
  should eq('$or' => [
71
91
  { 'a_date' => { '$gt' => feed_item.a_date.to_datetime } },
72
- { 'a_date' => feed_item.a_date.to_datetime, :_id => { '$gt' => feed_item.id } }
92
+ { 'a_date' => feed_item.a_date.to_datetime, '_id' => { '$gt' => feed_item.id } }
73
93
  ])
74
94
  end
75
95
  end
@@ -84,7 +104,7 @@ describe Mongoid::Scroll::Cursor do
84
104
  its(:criteria) do
85
105
  should eq('$or' => [
86
106
  { 'a_time' => { '$gt' => feed_item.a_time } },
87
- { 'a_time' => feed_item.a_time, :_id => { '$gt' => feed_item.id } }
107
+ { 'a_time' => feed_item.a_time, '_id' => { '$gt' => feed_item.id } }
88
108
  ])
89
109
  end
90
110
  end
@@ -99,7 +119,7 @@ describe Mongoid::Scroll::Cursor do
99
119
  its(:criteria) do
100
120
  should eq('$or' => [
101
121
  { 'a_time' => { '$gt' => feed_item.a_time } },
102
- { 'a_time' => feed_item.a_time, :_id => { '$gt' => feed_item.id } }
122
+ { 'a_time' => feed_item.a_time, '_id' => { '$gt' => feed_item.id } }
103
123
  ])
104
124
  end
105
125
  end
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: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
@@ -9,34 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-27 00:00:00.000000000 Z
12
+ date: 2015-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '3.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '3.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: i18n
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  description:
@@ -45,11 +45,11 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
49
- - .rspec
50
- - .rubocop.yml
51
- - .rubocop_todo.yml
52
- - .travis.yml
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - ".rubocop_todo.yml"
52
+ - ".travis.yml"
53
53
  - CHANGELOG.md
54
54
  - Gemfile
55
55
  - LICENSE.md
@@ -89,12 +89,12 @@ require_paths:
89
89
  - lib
90
90
  required_ruby_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - '>='
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - '>='
97
+ - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: 1.3.6
100
100
  requirements: []