mongoid 7.1.6 → 7.1.7
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/mongoid/criteria/queryable/selector.rb +0 -4
- 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/app/models/dictionary.rb +6 -0
- data/spec/integration/app_spec.rb +35 -2
- data/spec/integration/callbacks_models.rb +49 -0
- data/spec/integration/callbacks_spec.rb +216 -0
- data/spec/lite_spec_helper.rb +1 -1
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +50 -0
- data/spec/mongoid/atomic/paths_spec.rb +41 -0
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +36 -0
- data/spec/shared/lib/mrss/constraints.rb +18 -0
- data/spec/shared/lib/mrss/docker_runner.rb +262 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +69 -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
- data.tar.gz.sig +0 -0
- metadata +32 -12
- 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: 93d8b658e53d12f1deb7a131e3d58155fead7576955078187f3b3181072c193f
|
4
|
+
data.tar.gz: 35e629224f7495969e5a695a9641043ad61b92d61b57926b1d1956bd2f5e1d7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33920733722a4da26c23190788ef198d86d0d3edfcedc3d53bc7364d9abfbda7c54634af875c678757745c1d18b225457ef8e0a5b5711db7e76b93350548d14b
|
7
|
+
data.tar.gz: cb0acea4219ce1972fe67b63f988b0f31197ab44142288e5af4fe84e63f602dbc9b7dcc23edbf54cc5e465288c23346f62d3cf0632e0b37a59fabc6acb1c6925
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -123,10 +123,6 @@ module Mongoid
|
|
123
123
|
# {'foo' => {'$lt' => 5}}. This step should be done after all
|
124
124
|
# value-based processing is complete.
|
125
125
|
if key.is_a?(Key)
|
126
|
-
if serializer && evolved_value != value
|
127
|
-
raise NotImplementedError, "This method is not prepared to handle key being a Key and serializer being not nil"
|
128
|
-
end
|
129
|
-
|
130
126
|
evolved_value = key.transform_value(evolved_value)
|
131
127
|
end
|
132
128
|
|
data/lib/mongoid/document.rb
CHANGED
@@ -229,8 +229,9 @@ module Mongoid
|
|
229
229
|
became = klass.new(clone_document)
|
230
230
|
became._id = _id
|
231
231
|
became.instance_variable_set(:@changed_attributes, changed_attributes)
|
232
|
-
|
233
|
-
|
232
|
+
new_errors = ActiveModel::Errors.new(became)
|
233
|
+
new_errors.copy!(errors)
|
234
|
+
became.instance_variable_set(:@errors, new_errors)
|
234
235
|
became.instance_variable_set(:@new_record, new_record?)
|
235
236
|
became.instance_variable_set(:@destroyed, destroyed?)
|
236
237
|
became.changed_attributes["_type"] = self.class.to_s
|
@@ -234,9 +234,11 @@ module Mongoid
|
|
234
234
|
# document.halted_callback_hook(filter)
|
235
235
|
#
|
236
236
|
# @param [ Symbol ] filter The callback that halted.
|
237
|
+
# @param [ Symbol ] name The name of the callback that was halted
|
238
|
+
# (requires Rails 6.1+)
|
237
239
|
#
|
238
240
|
# @since 3.0.3
|
239
|
-
def halted_callback_hook(filter)
|
241
|
+
def halted_callback_hook(filter, name = nil)
|
240
242
|
@before_callback_halted = true
|
241
243
|
end
|
242
244
|
|
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
|
@@ -6,7 +6,13 @@ class Dictionary
|
|
6
6
|
field :name, type: String
|
7
7
|
field :publisher, type: String
|
8
8
|
field :year, type: Integer
|
9
|
+
|
10
|
+
# This field must be a Time
|
9
11
|
field :published, type: Time
|
12
|
+
|
13
|
+
# This field must be a Date
|
14
|
+
field :submitted_on, type: Date
|
15
|
+
|
10
16
|
field :description, type: String, localize: true
|
11
17
|
field :l, type: String, as: :language
|
12
18
|
has_many :words, validate: false
|
@@ -150,7 +150,7 @@ describe 'Mongoid application tests' do
|
|
150
150
|
end
|
151
151
|
index.should be nil
|
152
152
|
|
153
|
-
ChildProcessHelper.check_call(%w(rake db:mongoid:create_indexes),
|
153
|
+
ChildProcessHelper.check_call(%w(bundle exec rake db:mongoid:create_indexes),
|
154
154
|
cwd: APP_PATH, env: env)
|
155
155
|
|
156
156
|
index = client['posts'].indexes.detect do |index|
|
@@ -181,11 +181,44 @@ describe 'Mongoid application tests' do
|
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
184
|
+
def parse_mongodb_uri(uri)
|
185
|
+
pre, query = uri.split('?', 2)
|
186
|
+
if pre =~ %r,\A(mongodb(?:.*?))://([^/]+)(?:/(.*))?\z,
|
187
|
+
protocol = $1
|
188
|
+
hosts = $2
|
189
|
+
database = $3
|
190
|
+
if database == ''
|
191
|
+
database = nil
|
192
|
+
end
|
193
|
+
else
|
194
|
+
raise ArgumentError, "Invalid MongoDB URI: #{uri}"
|
195
|
+
end
|
196
|
+
if query == ''
|
197
|
+
query = nil
|
198
|
+
end
|
199
|
+
{
|
200
|
+
protocol: protocol,
|
201
|
+
hosts: hosts,
|
202
|
+
database: database,
|
203
|
+
query: query,
|
204
|
+
}
|
205
|
+
end
|
206
|
+
|
207
|
+
def build_mongodb_uri(parts)
|
208
|
+
"#{parts.fetch(:protocol)}://#{parts.fetch(:hosts)}/#{parts[:database]}?#{parts[:query]}"
|
209
|
+
end
|
210
|
+
|
184
211
|
def write_mongoid_yml
|
212
|
+
# HACK: the driver does not provide a MongoDB URI parser and assembler,
|
213
|
+
# and the Ruby standard library URI module doesn't handle multiple hosts.
|
214
|
+
parts = parse_mongodb_uri(SpecConfig.instance.uri_str)
|
215
|
+
parts[:database] = 'mongoid_test'
|
216
|
+
uri = build_mongodb_uri(parts)
|
217
|
+
p uri
|
185
218
|
env_config = {'clients' => {'default' => {
|
186
219
|
# TODO massive hack, will fail if uri specifies a database name or
|
187
220
|
# any uri options
|
188
|
-
'uri' =>
|
221
|
+
'uri' => uri,
|
189
222
|
}}}
|
190
223
|
config = {'development' => env_config, 'production' => env_config}
|
191
224
|
File.open('config/mongoid.yml', 'w') do |f|
|
@@ -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
|
data/spec/lite_spec_helper.rb
CHANGED
@@ -50,7 +50,7 @@ RSpec.configure do |config|
|
|
50
50
|
config.add_formatter(RSpec::Core::Formatters::JsonFormatter, File.join(File.dirname(__FILE__), '../tmp/rspec.json'))
|
51
51
|
end
|
52
52
|
|
53
|
-
if SpecConfig.instance.ci?
|
53
|
+
if SpecConfig.instance.ci? && !%w(1 true yes).include?(ENV['INTERACTIVE']&.downcase)
|
54
54
|
timeout = if SpecConfig.instance.app_tests?
|
55
55
|
# Allow 5 minutes per test for the app tests, since they install
|
56
56
|
# gems for Rails applications which can take a long time.
|
@@ -507,4 +507,54 @@ describe Mongoid::Association::Embedded::EmbeddedIn::Proxy do
|
|
507
507
|
end
|
508
508
|
end
|
509
509
|
end
|
510
|
+
|
511
|
+
context "when the same class is embedded multiple times" do
|
512
|
+
|
513
|
+
let(:customer) do
|
514
|
+
Customer.new
|
515
|
+
end
|
516
|
+
|
517
|
+
context "assignment after saving" do
|
518
|
+
|
519
|
+
it "correctly sets the association for the embedded class" do
|
520
|
+
pending 'MONGOID-5039'
|
521
|
+
|
522
|
+
customer.home_address = CustomerAddress.new
|
523
|
+
customer.work_address = CustomerAddress.new
|
524
|
+
|
525
|
+
expect(customer.home_address._association.store_as).to eq("home_address")
|
526
|
+
expect(customer.work_address._association.store_as).to eq("work_address")
|
527
|
+
|
528
|
+
expect(customer.home_address.instance_eval { _association.store_as }).to eq("home_address")
|
529
|
+
expect(customer.work_address.instance_eval { _association.store_as }).to eq("work_address")
|
530
|
+
|
531
|
+
customer.save!
|
532
|
+
|
533
|
+
customer.home_address = CustomerAddress.new
|
534
|
+
customer.work_address = CustomerAddress.new
|
535
|
+
|
536
|
+
expect(customer.home_address._association.store_as).to eq("home_address")
|
537
|
+
expect(customer.work_address._association.store_as).to eq("work_address")
|
538
|
+
|
539
|
+
expect(customer.home_address.instance_eval { _association.store_as }).to eq("home_address")
|
540
|
+
expect(customer.work_address.instance_eval { _association.store_as }).to eq("work_address")
|
541
|
+
end
|
542
|
+
end
|
543
|
+
|
544
|
+
context "inverse assignment" do
|
545
|
+
|
546
|
+
it "correctly sets the association for the embedded class" do
|
547
|
+
pending 'MONGOID-5039'
|
548
|
+
|
549
|
+
customer.work_address = CustomerAddress.new
|
550
|
+
customer.work_address.addressable = customer
|
551
|
+
|
552
|
+
expect(customer.home_address._association.store_as).to eq("home_address")
|
553
|
+
expect(customer.work_address._association.store_as).to eq("work_address")
|
554
|
+
|
555
|
+
expect(customer.home_address.instance_eval { _association.store_as }).to eq("home_address")
|
556
|
+
expect(customer.work_address.instance_eval { _association.store_as }).to eq("work_address")
|
557
|
+
end
|
558
|
+
end
|
559
|
+
end
|
510
560
|
end
|