mongoid 7.0.11 → 7.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Rakefile +2 -7
- data/lib/mongoid/document.rb +3 -2
- data/lib/mongoid/interceptable.rb +3 -1
- data/lib/mongoid/version.rb +1 -1
- data/spec/app/models/customer.rb +11 -0
- data/spec/app/models/customer_address.rb +12 -0
- data/spec/integration/callbacks_models.rb +49 -0
- data/spec/integration/callbacks_spec.rb +216 -0
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +50 -0
- data/spec/mongoid/atomic/paths_spec.rb +41 -0
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +211 -0
- data/spec/shared/lib/mrss/constraints.rb +330 -0
- data/spec/shared/lib/mrss/docker_runner.rb +262 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +175 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +69 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +149 -0
- data/spec/shared/share/Dockerfile.erb +229 -0
- data/spec/shared/shlib/distro.sh +73 -0
- data/spec/shared/shlib/server.sh +270 -0
- data/spec/shared/shlib/set_env.sh +128 -0
- metadata +479 -446
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08107532375c756a9a063a167169b570fa9d5f195e753a4f19a70ee7778eff1c'
|
4
|
+
data.tar.gz: addbf1ebd6dc0edc11a2604b4e3c1bf7297d67ad12739dcd44e981d2a8949cac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77dbc0a24838853d496fd5957770ef250c952cf57a126b36845540e6421888aa3abc9465ecb64d0a55940324c02a7e22a37935729deec400b6d2f0510138930a
|
7
|
+
data.tar.gz: 0b78a7bbe3049aff86657a02e88f61ef4b8281f5cd198567bbe153d44f7f56d74eca7b0119a40d9b8188ffb0b78f73847abbba82b39b601220f177ef7ac80a61
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Rakefile
CHANGED
@@ -20,11 +20,8 @@ task :install => :build do
|
|
20
20
|
system "sudo gem install mongoid-#{Mongoid::VERSION}.gem"
|
21
21
|
end
|
22
22
|
|
23
|
-
task :release
|
24
|
-
|
25
|
-
system "git push --tags"
|
26
|
-
system "gem push mongoid-#{Mongoid::VERSION}.gem"
|
27
|
-
system "rm mongoid-#{Mongoid::VERSION}.gem"
|
23
|
+
task :release do
|
24
|
+
raise "Please use ./release.sh to release"
|
28
25
|
end
|
29
26
|
|
30
27
|
RSpec::Core::RakeTask.new("spec") do |spec|
|
@@ -57,5 +54,3 @@ namespace :release do
|
|
57
54
|
end
|
58
55
|
end
|
59
56
|
end
|
60
|
-
|
61
|
-
task :release => ['release:check_private_key', 'release:do']
|
data/lib/mongoid/document.rb
CHANGED
@@ -227,8 +227,9 @@ module Mongoid
|
|
227
227
|
became = klass.new(clone_document)
|
228
228
|
became._id = _id
|
229
229
|
became.instance_variable_set(:@changed_attributes, changed_attributes)
|
230
|
-
|
231
|
-
|
230
|
+
new_errors = ActiveModel::Errors.new(became)
|
231
|
+
new_errors.copy!(errors)
|
232
|
+
became.instance_variable_set(:@errors, new_errors)
|
232
233
|
became.instance_variable_set(:@new_record, new_record?)
|
233
234
|
became.instance_variable_set(:@destroyed, destroyed?)
|
234
235
|
became.changed_attributes["_type"] = self.class.to_s
|
@@ -228,9 +228,11 @@ module Mongoid
|
|
228
228
|
# document.halted_callback_hook(filter)
|
229
229
|
#
|
230
230
|
# @param [ Symbol ] filter The callback that halted.
|
231
|
+
# @param [ Symbol ] name The name of the callback that was halted
|
232
|
+
# (requires Rails 6.1+)
|
231
233
|
#
|
232
234
|
# @since 3.0.3
|
233
|
-
def halted_callback_hook(filter)
|
235
|
+
def halted_callback_hook(filter, name = nil)
|
234
236
|
@before_callback_halted = true
|
235
237
|
end
|
236
238
|
|
data/lib/mongoid/version.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
class Customer
|
5
|
+
include Mongoid::Document
|
6
|
+
|
7
|
+
field :name
|
8
|
+
|
9
|
+
embeds_one :home_address, class_name: 'CustomerAddress', as: :addressable
|
10
|
+
embeds_one :work_address, class_name: 'CustomerAddress', as: :addressable
|
11
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Galaxy
|
2
|
+
include Mongoid::Document
|
3
|
+
|
4
|
+
field :age, type: Integer
|
5
|
+
|
6
|
+
before_validation :set_age
|
7
|
+
|
8
|
+
embeds_many :stars
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def set_age
|
13
|
+
self.age ||= 100_000
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Star
|
18
|
+
include Mongoid::Document
|
19
|
+
|
20
|
+
embedded_in :galaxy
|
21
|
+
|
22
|
+
field :age, type: Integer
|
23
|
+
|
24
|
+
before_validation :set_age
|
25
|
+
|
26
|
+
embeds_many :planets
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def set_age
|
31
|
+
self.age ||= 42_000
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Planet
|
36
|
+
include Mongoid::Document
|
37
|
+
|
38
|
+
embedded_in :star
|
39
|
+
|
40
|
+
field :age, type: Integer
|
41
|
+
|
42
|
+
before_validation :set_age
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def set_age
|
47
|
+
self.age ||= 2_000
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
require_relative './callbacks_models'
|
6
|
+
|
7
|
+
describe 'callbacks integration tests' do
|
8
|
+
context 'when modifying attributes in a callback' do
|
9
|
+
|
10
|
+
context 'when creating top-level document' do
|
11
|
+
context 'top level document' do
|
12
|
+
let(:instance) do
|
13
|
+
Galaxy.create!
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'writes the attribute value into the model' do
|
17
|
+
instance.age.should == 100_000
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'persists the attribute value' do
|
21
|
+
Galaxy.find(instance.id).age.should == 100_000
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'embedded document' do
|
26
|
+
shared_examples 'persists the attribute value' do
|
27
|
+
it 'writes the attribute value into the model' do
|
28
|
+
instance.stars.first.age.should == 42_000
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'persists the attribute value' do
|
32
|
+
Galaxy.find(instance.id).stars.first.age.should == 42_000
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'set as a document instance' do
|
37
|
+
let(:instance) do
|
38
|
+
Galaxy.create!(stars: [Star.new])
|
39
|
+
end
|
40
|
+
|
41
|
+
include_examples 'persists the attribute value'
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'set as attributes on parent' do
|
45
|
+
let(:instance) do
|
46
|
+
Galaxy.create!(stars: [{}])
|
47
|
+
end
|
48
|
+
|
49
|
+
include_examples 'persists the attribute value'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'nested embedded document' do
|
54
|
+
shared_examples 'persists the attribute value' do
|
55
|
+
it 'writes the attribute value into the model' do
|
56
|
+
instance.stars.first.planets.first.age.should == 2_000
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'persists the attribute value' do
|
60
|
+
Galaxy.find(instance.id).stars.first.planets.first.age.should == 2_000
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'set as a document instance' do
|
65
|
+
let(:instance) do
|
66
|
+
Galaxy.create!(stars: [Star.new(
|
67
|
+
planets: [Planet.new],
|
68
|
+
)])
|
69
|
+
end
|
70
|
+
|
71
|
+
include_examples 'persists the attribute value'
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'set as attributes on parent' do
|
75
|
+
let(:instance) do
|
76
|
+
Galaxy.create!(stars: [
|
77
|
+
planets: [{}],
|
78
|
+
])
|
79
|
+
end
|
80
|
+
|
81
|
+
include_examples 'persists the attribute value'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when updating top-level document via #save' do
|
87
|
+
let!(:instance) do
|
88
|
+
Galaxy.create!
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'embedded document' do
|
92
|
+
shared_examples 'persists the attribute value' do
|
93
|
+
it 'writes the attribute value into the model' do
|
94
|
+
instance.stars.first.age.should == 42_000
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'persists the attribute value' do
|
98
|
+
Galaxy.find(instance.id).stars.first.age.should == 42_000
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'set as a document instance' do
|
103
|
+
before do
|
104
|
+
instance.stars = [Star.new]
|
105
|
+
instance.save!
|
106
|
+
end
|
107
|
+
|
108
|
+
include_examples 'persists the attribute value'
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'set as attributes on parent' do
|
112
|
+
before do
|
113
|
+
instance.stars = [{}]
|
114
|
+
instance.save!
|
115
|
+
end
|
116
|
+
|
117
|
+
include_examples 'persists the attribute value'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'nested embedded document' do
|
122
|
+
shared_examples 'persists the attribute value' do
|
123
|
+
it 'writes the attribute value into the model' do
|
124
|
+
instance.stars.first.planets.first.age.should == 2_000
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'persists the attribute value' do
|
128
|
+
Galaxy.find(instance.id).stars.first.planets.first.age.should == 2_000
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'set as a document instance' do
|
133
|
+
before do
|
134
|
+
instance.stars = [Star.new(planets: [Planet.new])]
|
135
|
+
instance.save!
|
136
|
+
end
|
137
|
+
|
138
|
+
include_examples 'persists the attribute value'
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'set as attributes on parent' do
|
142
|
+
before do
|
143
|
+
instance.stars = [planets: [{}]]
|
144
|
+
instance.save!
|
145
|
+
end
|
146
|
+
|
147
|
+
include_examples 'persists the attribute value'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'when updating top-level document via #update_attributes' do
|
153
|
+
let!(:instance) do
|
154
|
+
Galaxy.create!
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'embedded document' do
|
158
|
+
shared_examples 'persists the attribute value' do
|
159
|
+
it 'writes the attribute value into the model' do
|
160
|
+
instance.stars.first.age.should == 42_000
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'persists the attribute value' do
|
164
|
+
Galaxy.find(instance.id).stars.first.age.should == 42_000
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'set as a document instance' do
|
169
|
+
before do
|
170
|
+
instance.update_attributes(stars: [Star.new])
|
171
|
+
end
|
172
|
+
|
173
|
+
include_examples 'persists the attribute value'
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'set as attributes on parent' do
|
177
|
+
before do
|
178
|
+
instance.update_attributes(stars: [{}])
|
179
|
+
end
|
180
|
+
|
181
|
+
include_examples 'persists the attribute value'
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'nested embedded document' do
|
186
|
+
shared_examples 'persists the attribute value' do
|
187
|
+
it 'writes the attribute value into the model' do
|
188
|
+
instance.stars.first.planets.first.age.should == 2_000
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'persists the attribute value' do
|
192
|
+
pending 'MONGOID-4476'
|
193
|
+
|
194
|
+
Galaxy.find(instance.id).stars.first.planets.first.age.should == 2_000
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'set as a document instance' do
|
199
|
+
before do
|
200
|
+
instance.update_attributes(stars: [Star.new(planets: [Planet.new])])
|
201
|
+
end
|
202
|
+
|
203
|
+
include_examples 'persists the attribute value'
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'set as attributes on parent' do
|
207
|
+
before do
|
208
|
+
instance.update_attributes(stars: [planets: [{}]])
|
209
|
+
end
|
210
|
+
|
211
|
+
include_examples 'persists the attribute value'
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
@@ -504,4 +504,54 @@ describe Mongoid::Association::Embedded::EmbeddedIn::Proxy do
|
|
504
504
|
end
|
505
505
|
end
|
506
506
|
end
|
507
|
+
|
508
|
+
context "when the same class is embedded multiple times" do
|
509
|
+
|
510
|
+
let(:customer) do
|
511
|
+
Customer.new
|
512
|
+
end
|
513
|
+
|
514
|
+
context "assignment after saving" do
|
515
|
+
|
516
|
+
it "correctly sets the association for the embedded class" do
|
517
|
+
pending 'MONGOID-5039'
|
518
|
+
|
519
|
+
customer.home_address = CustomerAddress.new
|
520
|
+
customer.work_address = CustomerAddress.new
|
521
|
+
|
522
|
+
expect(customer.home_address._association.store_as).to eq("home_address")
|
523
|
+
expect(customer.work_address._association.store_as).to eq("work_address")
|
524
|
+
|
525
|
+
expect(customer.home_address.instance_eval { _association.store_as }).to eq("home_address")
|
526
|
+
expect(customer.work_address.instance_eval { _association.store_as }).to eq("work_address")
|
527
|
+
|
528
|
+
customer.save!
|
529
|
+
|
530
|
+
customer.home_address = CustomerAddress.new
|
531
|
+
customer.work_address = CustomerAddress.new
|
532
|
+
|
533
|
+
expect(customer.home_address._association.store_as).to eq("home_address")
|
534
|
+
expect(customer.work_address._association.store_as).to eq("work_address")
|
535
|
+
|
536
|
+
expect(customer.home_address.instance_eval { _association.store_as }).to eq("home_address")
|
537
|
+
expect(customer.work_address.instance_eval { _association.store_as }).to eq("work_address")
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
context "inverse assignment" do
|
542
|
+
|
543
|
+
it "correctly sets the association for the embedded class" do
|
544
|
+
pending 'MONGOID-5039'
|
545
|
+
|
546
|
+
customer.work_address = CustomerAddress.new
|
547
|
+
customer.work_address.addressable = customer
|
548
|
+
|
549
|
+
expect(customer.home_address._association.store_as).to eq("home_address")
|
550
|
+
expect(customer.work_address._association.store_as).to eq("work_address")
|
551
|
+
|
552
|
+
expect(customer.home_address.instance_eval { _association.store_as }).to eq("home_address")
|
553
|
+
expect(customer.work_address.instance_eval { _association.store_as }).to eq("work_address")
|
554
|
+
end
|
555
|
+
end
|
556
|
+
end
|
507
557
|
end
|
@@ -265,5 +265,46 @@ describe Mongoid::Atomic::Paths do
|
|
265
265
|
end
|
266
266
|
end
|
267
267
|
end
|
268
|
+
|
269
|
+
context "when the same class is embedded in multiple associations" do
|
270
|
+
|
271
|
+
let(:customer) do
|
272
|
+
Customer.new
|
273
|
+
end
|
274
|
+
|
275
|
+
context "assignment after saving" do
|
276
|
+
|
277
|
+
it "correctly sets the association for the embedded class" do
|
278
|
+
pending 'MONGOID-5039'
|
279
|
+
|
280
|
+
customer.home_address = CustomerAddress.new
|
281
|
+
customer.work_address = CustomerAddress.new
|
282
|
+
|
283
|
+
expect(customer.home_address.atomic_path).to eq("home_address")
|
284
|
+
expect(customer.work_address.atomic_path).to eq("work_address")
|
285
|
+
|
286
|
+
customer.save!
|
287
|
+
|
288
|
+
customer.home_address = CustomerAddress.new
|
289
|
+
customer.work_address = CustomerAddress.new
|
290
|
+
|
291
|
+
expect(customer.home_address.atomic_path).to eq("home_address")
|
292
|
+
expect(customer.work_address.atomic_path).to eq("work_address")
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
context "inverse assignment" do
|
297
|
+
|
298
|
+
it "correctly returns the path for each embedded class" do
|
299
|
+
pending 'MONGOID-5039'
|
300
|
+
|
301
|
+
customer.work_address = CustomerAddress.new
|
302
|
+
customer.work_address.addressable = customer
|
303
|
+
|
304
|
+
expect(customer.home_address.atomic_path).to eq("home_address")
|
305
|
+
expect(customer.work_address.atomic_path).to eq("work_address")
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
268
309
|
end
|
269
310
|
end
|