mongoid 7.2.6 → 7.3.3
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/Rakefile +16 -0
- data/lib/config/locales/en.yml +2 -2
- data/lib/mongoid/association/accessors.rb +13 -1
- data/lib/mongoid/association/constrainable.rb +1 -1
- data/lib/mongoid/association/depending.rb +4 -4
- data/lib/mongoid/association/embedded/batchable.rb +1 -1
- data/lib/mongoid/association/embedded/embedded_in.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +10 -3
- data/lib/mongoid/association/nested/many.rb +1 -1
- data/lib/mongoid/association/nested/one.rb +4 -2
- data/lib/mongoid/association/proxy.rb +6 -1
- data/lib/mongoid/association/referenced/auto_save.rb +2 -2
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +490 -496
- data/lib/mongoid/association/referenced/has_many/proxy.rb +2 -2
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +2 -2
- data/lib/mongoid/atomic.rb +26 -2
- data/lib/mongoid/attributes/projector.rb +120 -0
- data/lib/mongoid/attributes.rb +24 -13
- data/lib/mongoid/cacheable.rb +2 -2
- data/lib/mongoid/clients/factory.rb +22 -8
- data/lib/mongoid/clients.rb +1 -1
- data/lib/mongoid/config.rb +19 -2
- data/lib/mongoid/contextual/aggregable/mongo.rb +10 -8
- data/lib/mongoid/copyable.rb +1 -1
- data/lib/mongoid/criteria/findable.rb +1 -1
- data/lib/mongoid/criteria/queryable/expandable.rb +0 -24
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions.rb +0 -4
- data/lib/mongoid/criteria/queryable/mergeable.rb +46 -20
- data/lib/mongoid/criteria/queryable/selectable.rb +8 -8
- data/lib/mongoid/criteria.rb +4 -5
- data/lib/mongoid/document.rb +1 -15
- data/lib/mongoid/errors/delete_restriction.rb +8 -9
- data/lib/mongoid/evolvable.rb +1 -1
- data/lib/mongoid/extensions/boolean.rb +1 -2
- data/lib/mongoid/extensions/false_class.rb +1 -1
- data/lib/mongoid/extensions/hash.rb +2 -2
- data/lib/mongoid/extensions/true_class.rb +1 -1
- data/lib/mongoid/fields.rb +43 -5
- data/lib/mongoid/inspectable.rb +1 -1
- data/lib/mongoid/matcher/bits.rb +41 -0
- data/lib/mongoid/matcher/bits_all_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_all_set.rb +20 -0
- data/lib/mongoid/matcher/bits_any_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_any_set.rb +20 -0
- data/lib/mongoid/matcher/expression.rb +4 -0
- data/lib/mongoid/matcher/field_operator.rb +6 -0
- data/lib/mongoid/matcher/mod.rb +17 -0
- data/lib/mongoid/matcher/type.rb +99 -0
- data/lib/mongoid/matcher.rb +7 -0
- data/lib/mongoid/persistable/deletable.rb +1 -2
- data/lib/mongoid/persistable/destroyable.rb +8 -2
- data/lib/mongoid/persistable/updatable.rb +27 -2
- data/lib/mongoid/query_cache.rb +35 -29
- data/lib/mongoid/selectable.rb +5 -7
- data/lib/mongoid/shardable.rb +21 -5
- data/lib/mongoid/touchable.rb +33 -4
- data/lib/mongoid/version.rb +1 -1
- data/spec/integration/associations/embeds_many_spec.rb +44 -0
- data/spec/integration/associations/has_one_spec.rb +48 -0
- data/spec/integration/criteria/date_field_spec.rb +1 -1
- data/spec/integration/document_spec.rb +9 -0
- data/spec/integration/matcher_operator_data/bits_all_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -0
- data/spec/integration/matcher_operator_data/comment.yml +22 -0
- data/spec/integration/matcher_operator_data/in.yml +16 -0
- data/spec/integration/matcher_operator_data/mod.yml +55 -0
- data/spec/integration/matcher_operator_data/type.yml +70 -0
- data/spec/integration/matcher_operator_data/type_array.yml +16 -0
- data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
- data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
- data/spec/integration/matcher_operator_data/type_code.yml +26 -0
- data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
- data/spec/integration/matcher_operator_data/type_date.yml +39 -0
- data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
- data/spec/integration/matcher_operator_data/type_decimal.yml +40 -0
- data/spec/integration/matcher_operator_data/type_double.yml +15 -0
- data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
- data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
- data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_null.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
- data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
- data/spec/integration/matcher_operator_data/type_string.yml +15 -0
- data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
- data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
- data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
- data/spec/lite_spec_helper.rb +2 -0
- data/spec/mongoid/association/depending_spec.rb +391 -352
- data/spec/mongoid/association/nested/one_spec.rb +18 -14
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +25 -8
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +1 -1
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +1 -1
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +245 -93
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +6 -6
- data/spec/mongoid/association/referenced/has_one_models.rb +8 -0
- data/spec/mongoid/atomic/paths_spec.rb +64 -12
- data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
- data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
- data/spec/mongoid/attributes/projector_spec.rb +41 -0
- data/spec/mongoid/attributes_spec.rb +98 -6
- data/spec/mongoid/clients/factory_spec.rb +48 -0
- data/spec/mongoid/config_spec.rb +106 -1
- data/spec/mongoid/contextual/mongo_spec.rb +2 -2
- data/spec/mongoid/criteria/modifiable_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +0 -73
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +105 -7
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +229 -24
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +39 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -565
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +590 -0
- data/spec/mongoid/criteria_projection_spec.rb +411 -0
- data/spec/mongoid/criteria_spec.rb +0 -275
- data/spec/mongoid/document_spec.rb +13 -13
- data/spec/mongoid/errors/delete_restriction_spec.rb +1 -1
- data/spec/mongoid/extensions/false_class_spec.rb +1 -1
- data/spec/mongoid/extensions/string_spec.rb +5 -5
- data/spec/mongoid/extensions/true_class_spec.rb +1 -1
- data/spec/mongoid/fields/localized_spec.rb +4 -4
- data/spec/mongoid/fields_spec.rb +4 -4
- data/spec/mongoid/inspectable_spec.rb +12 -4
- data/spec/mongoid/persistable/deletable_spec.rb +175 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +191 -3
- data/spec/mongoid/persistable/savable_spec.rb +3 -5
- data/spec/mongoid/persistable/upsertable_spec.rb +1 -1
- data/spec/mongoid/query_cache_middleware_spec.rb +8 -0
- data/spec/mongoid/reloadable_spec.rb +18 -1
- data/spec/mongoid/shardable_spec.rb +44 -0
- data/spec/mongoid/touchable_spec.rb +122 -16
- data/spec/mongoid/touchable_spec_models.rb +54 -0
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -2
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/models/bolt.rb +8 -0
- data/spec/support/models/hole.rb +13 -0
- data/spec/support/models/mop.rb +0 -1
- data/spec/support/models/nut.rb +8 -0
- data/spec/support/models/person.rb +6 -0
- data/spec/support/models/sealer.rb +8 -0
- data/spec/support/models/shirt.rb +12 -0
- data/spec/support/models/spacer.rb +8 -0
- data/spec/support/models/threadlocker.rb +8 -0
- data/spec/support/models/washer.rb +8 -0
- data.tar.gz.sig +0 -0
- metadata +97 -3
- metadata.gz.sig +0 -0
- data/spec/support/cluster_config.rb +0 -158
|
@@ -293,6 +293,8 @@ describe Mongoid::Persistable::Savable do
|
|
|
293
293
|
expect(truck.crates[1].volume).to eq 0.8
|
|
294
294
|
expect(truck.crates[1].toys.size).to eq 0
|
|
295
295
|
|
|
296
|
+
# TODO: MONGOID-5026: combine the updates so that there are
|
|
297
|
+
# no conflicts.
|
|
296
298
|
#expect(truck.atomic_updates[:conflicts]).to eq nil
|
|
297
299
|
|
|
298
300
|
expect { truck.save! }.not_to raise_error
|
|
@@ -360,8 +362,6 @@ describe Mongoid::Persistable::Savable do
|
|
|
360
362
|
|
|
361
363
|
context 'when also updating first embedded top level association' do
|
|
362
364
|
it 'performs all writes' do
|
|
363
|
-
pending 'https://jira.mongodb.org/browse/MONGOID-4982'
|
|
364
|
-
|
|
365
365
|
truck.crates.first.volume = 2
|
|
366
366
|
truck.crates.first.toys.build(name: 'Bear')
|
|
367
367
|
truck.crates.build
|
|
@@ -397,8 +397,6 @@ describe Mongoid::Persistable::Savable do
|
|
|
397
397
|
|
|
398
398
|
context 'when embedded association embeds another association' do
|
|
399
399
|
it 'persists the new documents' do
|
|
400
|
-
pending 'https://jira.mongodb.org/browse/MONGOID-4982'
|
|
401
|
-
|
|
402
400
|
expect(truck.seats.size).to eq 1
|
|
403
401
|
expect(truck.seats[0].rating).to eq 1
|
|
404
402
|
|
|
@@ -409,7 +407,7 @@ describe Mongoid::Persistable::Savable do
|
|
|
409
407
|
|
|
410
408
|
_truck = Truck.find(truck.id)
|
|
411
409
|
expect(_truck.seats.size).to eq 2
|
|
412
|
-
expect(_truck.seats[0].rating).to eq
|
|
410
|
+
expect(_truck.seats[0].rating).to eq 2
|
|
413
411
|
expect(_truck.seats[0].armrests.length).to eq 1
|
|
414
412
|
expect(_truck.seats[1].rating).to eq 100
|
|
415
413
|
end
|
|
@@ -58,4 +58,12 @@ describe Mongoid::QueryCache::Middleware do
|
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
|
+
|
|
62
|
+
context 'when driver implements query cache middleware' do
|
|
63
|
+
min_driver_version '2.15'
|
|
64
|
+
|
|
65
|
+
it 'uses the driver query cache middleware' do
|
|
66
|
+
Mongoid::QueryCache::Middleware.should be Mongo::QueryCache::Middleware
|
|
67
|
+
end
|
|
68
|
+
end
|
|
61
69
|
end
|
|
@@ -110,7 +110,7 @@ describe Mongoid::Reloadable do
|
|
|
110
110
|
|
|
111
111
|
context "when document not saved" do
|
|
112
112
|
|
|
113
|
-
context "when
|
|
113
|
+
context "when there is no document matching our id" do
|
|
114
114
|
|
|
115
115
|
it "raises an error" do
|
|
116
116
|
expect {
|
|
@@ -118,6 +118,23 @@ describe Mongoid::Reloadable do
|
|
|
118
118
|
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
|
119
119
|
end
|
|
120
120
|
end
|
|
121
|
+
|
|
122
|
+
context 'when there is a document matching our id' do
|
|
123
|
+
|
|
124
|
+
let!(:previous) { Agent.create!(title: '007') }
|
|
125
|
+
|
|
126
|
+
let(:agent) { Agent.new(id: previous.id) }
|
|
127
|
+
|
|
128
|
+
it 'loads the existing document' do
|
|
129
|
+
agent.title.should be nil
|
|
130
|
+
|
|
131
|
+
lambda do
|
|
132
|
+
agent.reload
|
|
133
|
+
end.should_not raise_error
|
|
134
|
+
|
|
135
|
+
agent.title.should == '007'
|
|
136
|
+
end
|
|
137
|
+
end
|
|
121
138
|
end
|
|
122
139
|
|
|
123
140
|
context "when the document is embedded" do
|
|
@@ -128,6 +128,50 @@ describe Mongoid::Shardable do
|
|
|
128
128
|
end
|
|
129
129
|
end
|
|
130
130
|
|
|
131
|
+
context 'when record is persisted' do
|
|
132
|
+
let(:instance) { klass.create(name: value) }
|
|
133
|
+
|
|
134
|
+
it { is_expected.to eq({ 'name' => value }) }
|
|
135
|
+
|
|
136
|
+
context 'changing shard key value' do
|
|
137
|
+
let(:new_value) { 'a-new-value' }
|
|
138
|
+
|
|
139
|
+
before do
|
|
140
|
+
instance.name = new_value
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it 'uses the newly set shard key value' do
|
|
144
|
+
subject.should == { 'name' => new_value }
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
describe '#shard_key_selector_in_db' do
|
|
151
|
+
subject { instance.shard_key_selector_in_db }
|
|
152
|
+
let(:klass) { Band }
|
|
153
|
+
let(:value) { 'a-brand-name' }
|
|
154
|
+
|
|
155
|
+
before { klass.shard_key(:name) }
|
|
156
|
+
|
|
157
|
+
context 'when record is new' do
|
|
158
|
+
let(:instance) { klass.new(name: value) }
|
|
159
|
+
|
|
160
|
+
it { is_expected.to eq({ 'name' => value }) }
|
|
161
|
+
|
|
162
|
+
context 'changing shard key value' do
|
|
163
|
+
let(:new_value) { 'a-new-value' }
|
|
164
|
+
|
|
165
|
+
before do
|
|
166
|
+
instance.name = new_value
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it 'uses the existing shard key value' do
|
|
170
|
+
subject.should == { 'name' => new_value }
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
131
175
|
context 'when record is persisted' do
|
|
132
176
|
let(:instance) { klass.create(name: value) }
|
|
133
177
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
require "spec_helper"
|
|
5
|
+
require_relative './touchable_spec_models'
|
|
5
6
|
|
|
6
7
|
describe Mongoid::Touchable do
|
|
7
8
|
|
|
@@ -9,7 +10,7 @@ describe Mongoid::Touchable do
|
|
|
9
10
|
|
|
10
11
|
context "when the document has no associations" do
|
|
11
12
|
let(:updatable) do
|
|
12
|
-
Updatable.create
|
|
13
|
+
Updatable.create!
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
it "responds to #touch" do
|
|
@@ -28,30 +29,135 @@ describe Mongoid::Touchable do
|
|
|
28
29
|
end
|
|
29
30
|
end
|
|
30
31
|
|
|
31
|
-
context
|
|
32
|
+
context 'when the document has a parent association' do
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
let(:building) do
|
|
35
|
+
parent_cls.create!
|
|
35
36
|
end
|
|
36
37
|
|
|
37
|
-
let(:
|
|
38
|
-
|
|
38
|
+
let(:entrance) do
|
|
39
|
+
building.entrances.create!
|
|
39
40
|
end
|
|
40
41
|
|
|
41
|
-
let(:
|
|
42
|
-
|
|
42
|
+
let(:floor) do
|
|
43
|
+
building.floors.create!
|
|
43
44
|
end
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
let!(:start_time) { Timecop.freeze(Time.at(Time.now.to_i)) }
|
|
47
|
+
|
|
48
|
+
let(:update_time) do
|
|
49
|
+
Timecop.freeze(Time.at(Time.now.to_i) + 2)
|
|
47
50
|
end
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
after do
|
|
53
|
+
Timecop.return
|
|
51
54
|
end
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
shared_examples 'updates the child' do
|
|
57
|
+
it "updates the updated_at timestamp" do
|
|
58
|
+
entrance
|
|
59
|
+
update_time
|
|
60
|
+
entrance.touch
|
|
61
|
+
|
|
62
|
+
entrance.updated_at.should == update_time
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "persists the changes" do
|
|
66
|
+
entrance
|
|
67
|
+
update_time
|
|
68
|
+
entrance.touch
|
|
69
|
+
|
|
70
|
+
entrance.reload.updated_at.should == update_time
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
shared_examples 'updates the parent when :touch is true' do
|
|
75
|
+
|
|
76
|
+
it 'updates updated_at on parent' do
|
|
77
|
+
floor
|
|
78
|
+
update_time
|
|
79
|
+
floor.touch
|
|
80
|
+
|
|
81
|
+
building.updated_at.should == update_time
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'persists updated updated_at on parent' do
|
|
85
|
+
floor
|
|
86
|
+
update_time
|
|
87
|
+
floor.touch
|
|
88
|
+
|
|
89
|
+
building.reload.updated_at.should == update_time
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
shared_examples 'updates the parent when :touch is not set' do
|
|
94
|
+
it 'does not update updated_at on parent' do
|
|
95
|
+
entrance
|
|
96
|
+
update_time
|
|
97
|
+
entrance.touch
|
|
98
|
+
|
|
99
|
+
building.updated_at.should == update_time
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'does not persist updated updated_at on parent' do
|
|
103
|
+
entrance
|
|
104
|
+
update_time
|
|
105
|
+
entrance.touch
|
|
106
|
+
|
|
107
|
+
building.reload.updated_at.should == update_time
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
shared_examples 'does not update the parent when :touch is not set' do
|
|
112
|
+
it 'does not update updated_at on parent' do
|
|
113
|
+
entrance
|
|
114
|
+
update_time
|
|
115
|
+
entrance.touch
|
|
116
|
+
|
|
117
|
+
building.updated_at.should == start_time
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'does not persist updated updated_at on parent' do
|
|
121
|
+
entrance
|
|
122
|
+
update_time
|
|
123
|
+
entrance.touch
|
|
124
|
+
|
|
125
|
+
building.reload.updated_at.should == start_time
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
context "when the document is embedded" do
|
|
130
|
+
let(:parent_cls) { TouchableSpec::Embedded::Building }
|
|
131
|
+
|
|
132
|
+
include_examples 'updates the child'
|
|
133
|
+
include_examples 'updates the parent when :touch is true'
|
|
134
|
+
include_examples 'updates the parent when :touch is not set'
|
|
135
|
+
|
|
136
|
+
context 'when also updating an additional field' do
|
|
137
|
+
it 'persists the update to the additional field' do
|
|
138
|
+
entrance
|
|
139
|
+
update_time
|
|
140
|
+
entrance.touch(:last_used_at)
|
|
141
|
+
|
|
142
|
+
entrance.reload
|
|
143
|
+
building.reload
|
|
144
|
+
|
|
145
|
+
# This is the assertion we want.
|
|
146
|
+
entrance.last_used_at.should == update_time
|
|
147
|
+
|
|
148
|
+
# Check other timestamps for good measure.
|
|
149
|
+
entrance.updated_at.should == update_time
|
|
150
|
+
building.updated_at.should == update_time
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
context "when the document is referenced" do
|
|
156
|
+
let(:parent_cls) { TouchableSpec::Referenced::Building }
|
|
157
|
+
|
|
158
|
+
include_examples 'updates the child'
|
|
159
|
+
include_examples 'updates the parent when :touch is true'
|
|
160
|
+
include_examples 'does not update the parent when :touch is not set'
|
|
55
161
|
end
|
|
56
162
|
end
|
|
57
163
|
|
|
@@ -415,11 +521,11 @@ describe Mongoid::Touchable do
|
|
|
415
521
|
context "when modifying the child" do
|
|
416
522
|
|
|
417
523
|
let!(:agency) do
|
|
418
|
-
Agency.create
|
|
524
|
+
Agency.create!
|
|
419
525
|
end
|
|
420
526
|
|
|
421
527
|
let!(:agent) do
|
|
422
|
-
agency.agents.create(number: '1')
|
|
528
|
+
agency.agents.create!(number: '1')
|
|
423
529
|
end
|
|
424
530
|
|
|
425
531
|
it "updates the parent's updated at" do
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
|
|
4
|
+
module TouchableSpec
|
|
5
|
+
module Embedded
|
|
6
|
+
class Building
|
|
7
|
+
include Mongoid::Document
|
|
8
|
+
include Mongoid::Timestamps
|
|
9
|
+
|
|
10
|
+
embeds_many :entrances
|
|
11
|
+
embeds_many :floors
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class Entrance
|
|
15
|
+
include Mongoid::Document
|
|
16
|
+
include Mongoid::Timestamps
|
|
17
|
+
|
|
18
|
+
embedded_in :building
|
|
19
|
+
|
|
20
|
+
field :last_used_at, type: Time
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class Floor
|
|
24
|
+
include Mongoid::Document
|
|
25
|
+
include Mongoid::Timestamps
|
|
26
|
+
|
|
27
|
+
embedded_in :building, touch: true
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
module Referenced
|
|
32
|
+
class Building
|
|
33
|
+
include Mongoid::Document
|
|
34
|
+
include Mongoid::Timestamps
|
|
35
|
+
|
|
36
|
+
has_many :entrances, inverse_of: :building
|
|
37
|
+
has_many :floors, inverse_of: :building
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class Entrance
|
|
41
|
+
include Mongoid::Document
|
|
42
|
+
include Mongoid::Timestamps
|
|
43
|
+
|
|
44
|
+
belongs_to :building
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class Floor
|
|
48
|
+
include Mongoid::Document
|
|
49
|
+
include Mongoid::Timestamps
|
|
50
|
+
|
|
51
|
+
belongs_to :building, touch: true
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -29,13 +29,17 @@ def database_id_alt
|
|
|
29
29
|
"mongoid_test_alt"
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
require 'mrss/cluster_config'
|
|
33
|
+
require 'support/client_registry'
|
|
34
|
+
require 'mrss/constraints'
|
|
35
|
+
|
|
36
|
+
ClusterConfig = Mrss::ClusterConfig
|
|
37
|
+
|
|
32
38
|
require 'support/authorization'
|
|
33
39
|
require 'support/expectations'
|
|
34
40
|
require 'support/helpers'
|
|
35
41
|
require 'support/macros'
|
|
36
|
-
require 'support/cluster_config'
|
|
37
42
|
require 'support/constraints'
|
|
38
|
-
require 'mrss/constraints'
|
|
39
43
|
|
|
40
44
|
# Give MongoDB servers time to start up in CI environments
|
|
41
45
|
if SpecConfig.instance.ci?
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
|
|
4
|
+
class Hole
|
|
5
|
+
include Mongoid::Document
|
|
6
|
+
|
|
7
|
+
has_one :bolt, dependent: :destroy
|
|
8
|
+
has_one :threadlocker, dependent: :delete_all
|
|
9
|
+
has_one :sealer, dependent: :restrict_with_exception
|
|
10
|
+
has_many :nuts, dependent: :destroy
|
|
11
|
+
has_many :washers, dependent: :delete_all
|
|
12
|
+
has_many :spacers, dependent: :restrict_with_exception
|
|
13
|
+
end
|
data/spec/support/models/mop.rb
CHANGED