mongoid_monkey 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/mongoid_monkey.rb +2 -0
- data/lib/patches/aggregate_cursor.rb +16 -0
- data/lib/patches/atomic.rb +42 -7
- data/lib/patches/write_concern.rb +10 -0
- data/lib/version.rb +1 -1
- data/spec/app/models/address.rb +1 -0
- data/spec/app/models/album.rb +14 -0
- data/spec/app/models/animal.rb +25 -0
- data/spec/app/models/appointment.rb +7 -0
- data/spec/app/models/artist.rb +66 -0
- data/spec/app/models/circus.rb +7 -0
- data/spec/app/models/country_code.rb +8 -0
- data/spec/app/models/label.rb +39 -0
- data/spec/app/models/location.rb +8 -0
- data/spec/app/models/page.rb +2 -1
- data/spec/app/models/page_question.rb +4 -0
- data/spec/app/models/person.rb +5 -0
- data/spec/app/models/phone.rb +11 -0
- data/spec/app/models/quiz.rb +10 -0
- data/spec/app/models/role.rb +7 -0
- data/spec/app/models/song.rb +8 -0
- data/spec/app/models/symptom.rb +6 -0
- data/spec/app/models/user.rb +1 -0
- data/spec/app/models/video.rb +17 -0
- data/spec/unit/aggregate_cursor_spec.rb +495 -0
- data/spec/unit/atomic/mongoid3_style/atomic/embedded_insert_spec.rb +1213 -0
- data/spec/unit/only_pluck_localized_spec.rb +2 -2
- data/spec/unit/write_concern_spec.rb +29 -0
- metadata +41 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f08602871ad1f23178fbcdb229ec18d40f385e70
|
4
|
+
data.tar.gz: 65f0267dc96fdec8fb505754097e9fd0a447df63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69ae75a8d969b6a215b65f51b1a42cc32712d3a80a86b605d1c1040190702240f78be792488774864e02c389814d4daf7f347e66cc10d9965c269d88820cd3ab
|
7
|
+
data.tar.gz: 6999c691a45888d763881006dc1d2674521671fac1fee6fa0d95390f4bc7f5807f671a601b45e7033ecef1ac4aa3fdf5f05b45faa72e42dae68ee333c31be33e
|
data/README.md
CHANGED
@@ -31,7 +31,8 @@ If you would only like some of the patches, please copy and paste the code to yo
|
|
31
31
|
|
32
32
|
| File | Description | 3 | 4 | 5 |
|
33
33
|
| --- | --- | --- | --- | --- |
|
34
|
-
| `
|
34
|
+
| `aggregate_cursor.rb` | Aggregate methods (`max`, `sum`, etc) must use cursor in MongoDB 3.6+ | ● | ○ | ○ |
|
35
|
+
| `atomic.rb` | Backport syntax change of atomic query methods. Replace `$pushAll` with `$push + $each`. | ● | ○ | ○ |
|
35
36
|
| `big_decimal.rb` | Fixes buggy BigDecimal behavior. | ● | ● | ● |
|
36
37
|
| `db_commands.rb` | Use MongoDB 3.0+ command syntax; required for WiredTiger. | ● | ● | ○ |
|
37
38
|
| `instrument.rb` | Backport instrumentation change to Moped 1. | ● | ○ | ○ |
|
@@ -40,6 +41,7 @@ If you would only like some of the patches, please copy and paste the code to yo
|
|
40
41
|
| `embedded_touch.rb` (1) | Backport [Issue #3310](https://github.com/mongodb/mongoid/commit/a94c2f43573e58f973913c881ad9d11d62bf857c) from Mongoid 4 to add `:touch` option to `embedded_in`. | ● | ○ | ○ |
|
41
42
|
| `embedded_touch.rb` (2) | Backport [PR #4392](https://github.com/mongodb/mongoid/pull/4392) from Mongoid 6 to fix an infinite loop issue related to `:touch` callbacks. | ● | ● | ● |
|
42
43
|
| `index_options.rb` | Backport latest index valid index options from Mongoid 6. | ● | ● | ○ |
|
44
|
+
| `write_concern.rb` | Config `safe: true` should send WriteConcern: Acknowledged `w: 1` to database (and not `safe: true`). | ● | ○ | ○ |
|
43
45
|
|
44
46
|
### License
|
45
47
|
|
data/lib/mongoid_monkey.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'version'
|
2
2
|
|
3
|
+
require 'patches/aggregate_cursor'
|
3
4
|
require 'patches/atomic'
|
4
5
|
require 'patches/big_decimal'
|
5
6
|
require 'patches/db_commands'
|
@@ -8,3 +9,4 @@ require 'patches/instrument'
|
|
8
9
|
require 'patches/reorder'
|
9
10
|
require 'patches/only_pluck_localized'
|
10
11
|
require 'patches/embedded_touch'
|
12
|
+
require 'patches/write_concern'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Use cursor for aggregation methods in Mongoid 3 in order to support MongoDB 3.6+
|
2
|
+
|
3
|
+
if Mongoid::VERSION =~ /\A3\./
|
4
|
+
|
5
|
+
module Moped
|
6
|
+
class Collection
|
7
|
+
def aggregate(*pipeline)
|
8
|
+
pipeline.flatten!
|
9
|
+
command = { aggregate: name.to_s, pipeline: pipeline, cursor: {} }
|
10
|
+
result = database.session.command(command)['cursor']
|
11
|
+
result = result['firstBatch'] if result
|
12
|
+
result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/patches/atomic.rb
CHANGED
@@ -69,14 +69,14 @@ module Atomic
|
|
69
69
|
end
|
70
70
|
alias_method_chain :push, :mongoid4
|
71
71
|
|
72
|
-
|
72
|
+
# Uses $push + $each rather than $pushAll
|
73
|
+
def push_all(*args)
|
73
74
|
if args.length == 1 && args.first.is_a?(Hash)
|
74
|
-
query.update_all("$
|
75
|
+
query.update_all("$push" => collect_operations(args.first, true))
|
75
76
|
else
|
76
|
-
|
77
|
+
query.update_all("$push" => { database_field_name(args[0]) => { "$each" => args[1] } })
|
77
78
|
end
|
78
79
|
end
|
79
|
-
alias_method_chain :push_all, :mongoid4
|
80
80
|
|
81
81
|
def rename_with_mongoid4(*args)
|
82
82
|
if args.length == 1 && args.first.is_a?(Hash)
|
@@ -102,9 +102,9 @@ module Atomic
|
|
102
102
|
|
103
103
|
private
|
104
104
|
|
105
|
-
def collect_operations(ops)
|
105
|
+
def collect_operations(ops, use_each = false)
|
106
106
|
ops.inject({}) do |operations, (field, value)|
|
107
|
-
operations[database_field_name(field)] = value.mongoize
|
107
|
+
operations[database_field_name(field)] = use_each ? { '$each' => value.mongoize } : value.mongoize
|
108
108
|
operations
|
109
109
|
end
|
110
110
|
end
|
@@ -116,7 +116,16 @@ module Mongoid
|
|
116
116
|
module Persistence
|
117
117
|
module Atomic
|
118
118
|
|
119
|
-
#
|
119
|
+
# Replace usage of $pushAll with $push + $each
|
120
|
+
class PushAll
|
121
|
+
def persist
|
122
|
+
append_with("$push")
|
123
|
+
end
|
124
|
+
|
125
|
+
def operation(modifier)
|
126
|
+
{ modifier => { path => value.is_a?(Array) ? { "$each" => value } : value}}
|
127
|
+
end
|
128
|
+
end
|
120
129
|
|
121
130
|
def add_to_set_with_mongoid4(*args)
|
122
131
|
if args.length == 1 && args.first.is_a?(Hash)
|
@@ -335,4 +344,30 @@ end
|
|
335
344
|
end
|
336
345
|
end
|
337
346
|
|
347
|
+
# Replace usage of $pushAll with $push + $each
|
348
|
+
module Mongoid
|
349
|
+
module Relations
|
350
|
+
module Embedded
|
351
|
+
module Batchable
|
352
|
+
|
353
|
+
def batch_insert(docs)
|
354
|
+
execute_batch_insert(docs, "$push", true)
|
355
|
+
end
|
356
|
+
|
357
|
+
def execute_batch_insert(docs, operation, use_each = false)
|
358
|
+
self.inserts_valid = true
|
359
|
+
inserts = pre_process_batch_insert(docs)
|
360
|
+
if insertable?
|
361
|
+
collection.find(selector).update(
|
362
|
+
positionally(selector, operation => { path => use_each ? { '$each' => inserts } : inserts })
|
363
|
+
)
|
364
|
+
post_process_batch_insert(docs)
|
365
|
+
end
|
366
|
+
inserts
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
338
373
|
end
|
data/lib/version.rb
CHANGED
data/spec/app/models/address.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
class Animal
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
field :_id, type: String, default: ->{ name.try(:parameterize) }
|
5
|
+
|
6
|
+
field :name
|
7
|
+
field :height, type: Integer
|
8
|
+
field :weight, type: Integer
|
9
|
+
field :tags, type: Array
|
10
|
+
|
11
|
+
embedded_in :person
|
12
|
+
embedded_in :circus
|
13
|
+
|
14
|
+
validates_format_of :name, without: /\$\$\$/
|
15
|
+
|
16
|
+
accepts_nested_attributes_for :person
|
17
|
+
|
18
|
+
def tag_list
|
19
|
+
tags.join(", ")
|
20
|
+
end
|
21
|
+
|
22
|
+
def tag_list=(_tag_list)
|
23
|
+
self.tags = _tag_list.split(",").map(&:strip)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class Artist
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
attr_accessor :before_add_called, :after_add_called, :before_add_referenced_called, :after_add_referenced_called, :before_remove_embedded_called, :after_remove_embedded_called, :before_remove_referenced_called, :after_remove_referenced_called
|
5
|
+
|
6
|
+
field :name, type: String
|
7
|
+
|
8
|
+
embeds_many :songs, before_add: [ :before_add_song, Proc.new { |artist, song| song.before_add_called = true } ], before_remove: :before_remove_song
|
9
|
+
embeds_many :labels, after_add: :after_add_label, after_remove: :after_remove_label
|
10
|
+
has_many :albums, dependent: :destroy, before_add: [:before_add_album, Proc.new { |artist, album| album.before_add_called = true} ], after_add: :after_add_album, before_remove: :before_remove_album, after_remove: :after_remove_album
|
11
|
+
|
12
|
+
before_create :before_create_stub
|
13
|
+
after_create :create_songs
|
14
|
+
before_save :before_save_stub
|
15
|
+
before_destroy :before_destroy_stub
|
16
|
+
|
17
|
+
protected
|
18
|
+
def before_create_stub
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def before_save_stub
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def before_destroy_stub
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_songs
|
31
|
+
2.times { |n| songs.create!(title: "#{n}") }
|
32
|
+
end
|
33
|
+
|
34
|
+
def before_add_song(song)
|
35
|
+
@before_add_called = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def after_add_label(label)
|
39
|
+
@after_add_called = true
|
40
|
+
end
|
41
|
+
|
42
|
+
def before_add_album(album)
|
43
|
+
@before_add_referenced_called = true
|
44
|
+
end
|
45
|
+
|
46
|
+
def after_add_album(album)
|
47
|
+
@after_add_referenced_called = true
|
48
|
+
end
|
49
|
+
|
50
|
+
def before_remove_song(song)
|
51
|
+
@before_remove_embedded_called = true
|
52
|
+
end
|
53
|
+
|
54
|
+
def after_remove_label(label)
|
55
|
+
@after_remove_embedded_called = true
|
56
|
+
end
|
57
|
+
|
58
|
+
def before_remove_album(album)
|
59
|
+
@before_remove_referenced_called = true
|
60
|
+
end
|
61
|
+
|
62
|
+
def after_remove_album(album)
|
63
|
+
@after_remove_referenced_called = true
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Label
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps::Updated::Short
|
4
|
+
|
5
|
+
field :name, type: String
|
6
|
+
field :after_create_called, type: Boolean, default: false
|
7
|
+
field :after_save_called, type: Boolean, default: false
|
8
|
+
field :after_update_called, type: Boolean, default: false
|
9
|
+
field :after_validation_called, type: Boolean, default: false
|
10
|
+
|
11
|
+
embedded_in :artist
|
12
|
+
|
13
|
+
after_create :after_create_stub
|
14
|
+
after_save :after_save_stub
|
15
|
+
after_update :after_update_stub
|
16
|
+
after_validation :after_validation_stub
|
17
|
+
before_validation :cleanup
|
18
|
+
|
19
|
+
def after_create_stub
|
20
|
+
self.after_create_called = true
|
21
|
+
end
|
22
|
+
|
23
|
+
def after_save_stub
|
24
|
+
self.after_save_called = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def after_update_stub
|
28
|
+
self.after_update_called = true
|
29
|
+
end
|
30
|
+
|
31
|
+
def after_validation_stub
|
32
|
+
self.after_validation_called = true
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def cleanup
|
37
|
+
self.name = self.name.downcase.capitalize
|
38
|
+
end
|
39
|
+
end
|
data/spec/app/models/page.rb
CHANGED
data/spec/app/models/person.rb
CHANGED
@@ -39,6 +39,11 @@ class Person
|
|
39
39
|
field :range, type: Range
|
40
40
|
|
41
41
|
embeds_many :addresses, as: :addressable, validate: false
|
42
|
+
embeds_many :videos, order: [[ :title, :asc ]], validate: false
|
43
|
+
embeds_many :appointments, validate: false
|
44
|
+
embeds_many :symptoms, validate: false
|
45
|
+
embeds_many :phone_numbers, class_name: "Phone", validate: false
|
46
|
+
embeds_many :phones, store_as: :mobile_phones, validate: false
|
42
47
|
embeds_one :name, as: :namable, validate: false do
|
43
48
|
def extension
|
44
49
|
"Testing"
|