mongoid 7.2.0 → 7.3.0
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/Rakefile +16 -0
- data/lib/config/locales/en.yml +2 -2
- data/lib/mongoid/association/accessors.rb +1 -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 +493 -495
- 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/attributes/projector.rb +120 -0
- data/lib/mongoid/attributes.rb +32 -14
- 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/queryable/selector.rb +0 -4
- data/lib/mongoid/criteria.rb +4 -5
- data/lib/mongoid/document.rb +4 -17
- 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/interceptable.rb +3 -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/elem_match.rb +2 -1
- data/lib/mongoid/matcher/expression.rb +9 -14
- data/lib/mongoid/matcher/field_expression.rb +4 -5
- data/lib/mongoid/matcher/field_operator.rb +13 -11
- data/lib/mongoid/matcher/mod.rb +17 -0
- data/lib/mongoid/matcher/type.rb +99 -0
- data/lib/mongoid/matcher.rb +26 -43
- 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/reloadable.rb +5 -0
- data/lib/mongoid/selectable.rb +5 -7
- data/lib/mongoid/shardable.rb +21 -5
- data/lib/mongoid/touchable.rb +23 -4
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/config_generator.rb +8 -1
- data/spec/integration/app_spec.rb +171 -84
- data/spec/integration/associations/embeds_many_spec.rb +44 -0
- data/spec/integration/associations/has_one_spec.rb +48 -0
- data/spec/integration/callbacks_models.rb +49 -0
- data/spec/integration/callbacks_spec.rb +216 -0
- data/spec/integration/criteria/date_field_spec.rb +1 -1
- data/spec/integration/document_spec.rb +30 -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/elem_match.yml +46 -0
- data/spec/integration/matcher_operator_data/gt_types.yml +63 -0
- data/spec/integration/matcher_operator_data/gte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/implicit_traversal.yml +96 -0
- data/spec/integration/matcher_operator_data/in.yml +16 -0
- data/spec/integration/matcher_operator_data/lt_types.yml +15 -0
- data/spec/integration/matcher_operator_data/lte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/mod.yml +55 -0
- data/spec/integration/matcher_operator_data/ne_types.yml +15 -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 +5 -4
- data/spec/mongoid/association/depending_spec.rb +391 -352
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +50 -0
- 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 +1 -1
- data/spec/mongoid/association/referenced/has_one_models.rb +8 -0
- data/spec/mongoid/atomic/paths_spec.rb +105 -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 +333 -0
- data/spec/mongoid/clients/factory_spec.rb +48 -0
- data/spec/mongoid/config_spec.rb +32 -0
- data/spec/mongoid/contextual/atomic_spec.rb +17 -4
- 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 +265 -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_fields_spec.rb +26 -0
- 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/matcher/extract_attribute_data/numeric_keys.yml +104 -0
- data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +68 -88
- data/spec/mongoid/matcher/extract_attribute_spec.rb +3 -13
- 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/settable_spec.rb +30 -0
- 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 +104 -16
- data/spec/mongoid/touchable_spec_models.rb +52 -0
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/lib/mrss/cluster_config.rb +221 -0
- data/spec/shared/lib/mrss/constraints.rb +51 -0
- data/spec/shared/lib/mrss/docker_runner.rb +265 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +16 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +115 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +14 -1
- data/spec/shared/lib/mrss/utils.rb +15 -0
- data/spec/shared/share/Dockerfile.erb +231 -0
- data/spec/shared/shlib/distro.sh +73 -0
- data/spec/shared/shlib/server.sh +290 -0
- data/spec/shared/shlib/set_env.sh +128 -0
- 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/customer.rb +11 -0
- data/spec/support/models/customer_address.rb +12 -0
- data/spec/support/models/dictionary.rb +6 -0
- data/spec/support/models/hole.rb +13 -0
- data/spec/support/models/mop.rb +9 -0
- 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/spec/support/spec_config.rb +8 -0
- data.tar.gz.sig +0 -0
- metadata +146 -14
- metadata.gz.sig +5 -2
- data/spec/support/cluster_config.rb +0 -158
@@ -96,6 +96,49 @@ describe Mongoid::Attributes do
|
|
96
96
|
it "does not raise an error" do
|
97
97
|
expect(from_db.map).to eq(map)
|
98
98
|
end
|
99
|
+
|
100
|
+
context 'when only one of the hash fields is projected' do
|
101
|
+
|
102
|
+
let(:map) do
|
103
|
+
{ 'dates' => { 'y' => { '2016' => 'Berlin', '2017' => 'Munich' } } }
|
104
|
+
end
|
105
|
+
|
106
|
+
let(:expected) do
|
107
|
+
{ 'dates' => { 'y' => {
|
108
|
+
'2016' => 'Berlin',
|
109
|
+
} } }
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'retrieves only the projected fields' do
|
113
|
+
expect(from_db.map).to eq(expected)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'when several of the hash fields is projected' do
|
118
|
+
|
119
|
+
let(:map) do
|
120
|
+
{ 'dates' => { 'y' => {
|
121
|
+
'2016' => 'Berlin',
|
122
|
+
'2017' => 'Munich',
|
123
|
+
'2018' => 'Krakow',
|
124
|
+
} } }
|
125
|
+
end
|
126
|
+
|
127
|
+
let(:expected) do
|
128
|
+
{ 'dates' => { 'y' => {
|
129
|
+
'2016' => 'Berlin',
|
130
|
+
'2018' => 'Krakow',
|
131
|
+
} } }
|
132
|
+
end
|
133
|
+
|
134
|
+
let(:from_db) do
|
135
|
+
Person.only('map.dates.y.2016', 'map.dates.y.2018').first
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'retrieves only the projected fields' do
|
139
|
+
expect(from_db.map).to eq(expected)
|
140
|
+
end
|
141
|
+
end
|
99
142
|
end
|
100
143
|
end
|
101
144
|
|
@@ -245,6 +288,91 @@ describe Mongoid::Attributes do
|
|
245
288
|
end
|
246
289
|
end
|
247
290
|
|
291
|
+
context "when the field was not explicitly defined" do
|
292
|
+
|
293
|
+
context "when excluding with only and the field was not excluded" do
|
294
|
+
|
295
|
+
let(:from_db) do
|
296
|
+
Person.only(:_id).first
|
297
|
+
end
|
298
|
+
|
299
|
+
it "raises an error" do
|
300
|
+
expect {
|
301
|
+
from_db[:undefined_field]
|
302
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context "when excluding with without and the field was excluded" do
|
307
|
+
|
308
|
+
let(:from_db) do
|
309
|
+
Person.without(:title).first
|
310
|
+
end
|
311
|
+
|
312
|
+
it "raises an error" do
|
313
|
+
expect {
|
314
|
+
from_db[:title]
|
315
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
context "when excluding with without and the field was not excluded" do
|
320
|
+
|
321
|
+
let(:from_db) do
|
322
|
+
Person.without(:title).first
|
323
|
+
end
|
324
|
+
|
325
|
+
it "returns nil" do
|
326
|
+
from_db[:undefined_field].should be nil
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
context 'when projecting with #only' do
|
332
|
+
let!(:person) do
|
333
|
+
Person.create(title: 'sir', name: { first_name: 'Jose', language: { name: 'es' } })
|
334
|
+
end
|
335
|
+
|
336
|
+
context 'when projecting an embedded association' do
|
337
|
+
let(:from_db) do
|
338
|
+
Person.only(:name).first
|
339
|
+
end
|
340
|
+
|
341
|
+
context 'when retrieving a field of the association using the dot notation' do
|
342
|
+
|
343
|
+
it 'retrieves the field' do
|
344
|
+
expect(from_db['name.first_name']).to eq 'Jose'
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
context 'when retrieving a field of a nested association using the dot notation' do
|
349
|
+
it 'retrieves the field' do
|
350
|
+
expect(from_db['name.language.name']).to eq 'es'
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
context 'when projecting a sub-association of an embedded association' do
|
356
|
+
let(:from_db) do
|
357
|
+
Person.only('name.language').first
|
358
|
+
end
|
359
|
+
|
360
|
+
context 'when retrieving a field under the projected sub-association' do
|
361
|
+
it 'retrieves the field' do
|
362
|
+
expect(from_db['name.language.name']).to eq 'es'
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
context 'when retrieving a non-projected field' do
|
367
|
+
it 'raises MissingAttributeError' do
|
368
|
+
expect do
|
369
|
+
from_db['name.first_name']
|
370
|
+
end.to raise_error(ActiveModel::MissingAttributeError)
|
371
|
+
end
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
248
376
|
context "when the attribute does not exist" do
|
249
377
|
|
250
378
|
before do
|
@@ -329,6 +457,67 @@ describe Mongoid::Attributes do
|
|
329
457
|
expect(terms).to eq(true)
|
330
458
|
end
|
331
459
|
end
|
460
|
+
|
461
|
+
context 'when the field is not explicitly defined' do
|
462
|
+
let(:bar) { Bar.new }
|
463
|
+
|
464
|
+
before do
|
465
|
+
bar['missing_field'] = 42
|
466
|
+
end
|
467
|
+
|
468
|
+
it 'writes the value into attributes' do
|
469
|
+
bar.attributes.should == {'_id' => bar.id, 'missing_field' => 42}
|
470
|
+
end
|
471
|
+
|
472
|
+
it 'makes the attribute accessible via []' do
|
473
|
+
bar['missing_field'].should == 42
|
474
|
+
end
|
475
|
+
|
476
|
+
context 'when writing fields on a document with projection' do
|
477
|
+
|
478
|
+
let!(:person) do
|
479
|
+
Person.create(title: "sir")
|
480
|
+
end
|
481
|
+
|
482
|
+
context "when excluding with only and the field was not excluded" do
|
483
|
+
|
484
|
+
let(:from_db) do
|
485
|
+
Person.only(:_id).first
|
486
|
+
end
|
487
|
+
|
488
|
+
it "raises an error" do
|
489
|
+
expect {
|
490
|
+
from_db[:undefined_field] = 'x'
|
491
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
context "when excluding with without and the field was excluded" do
|
496
|
+
|
497
|
+
let(:from_db) do
|
498
|
+
Person.without(:title).first
|
499
|
+
end
|
500
|
+
|
501
|
+
it "raises an error" do
|
502
|
+
expect {
|
503
|
+
from_db[:title] = 'x'
|
504
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
505
|
+
end
|
506
|
+
end
|
507
|
+
|
508
|
+
context "when excluding with without and the field was not excluded" do
|
509
|
+
|
510
|
+
let(:from_db) do
|
511
|
+
Person.without(:title).first
|
512
|
+
end
|
513
|
+
|
514
|
+
it "writes the value" do
|
515
|
+
from_db[:undefined_field] = 'x'
|
516
|
+
from_db[:undefined_field].should == 'x'
|
517
|
+
end
|
518
|
+
end
|
519
|
+
end
|
520
|
+
end
|
332
521
|
end
|
333
522
|
|
334
523
|
describe "#_id" do
|
@@ -893,6 +1082,50 @@ describe Mongoid::Attributes do
|
|
893
1082
|
expect(person.age_before_type_cast).to eq("old")
|
894
1083
|
end
|
895
1084
|
end
|
1085
|
+
|
1086
|
+
context 'when reading fields on a document with projection' do
|
1087
|
+
|
1088
|
+
let!(:person) do
|
1089
|
+
Person.create(title: "sir")
|
1090
|
+
end
|
1091
|
+
|
1092
|
+
context "when excluding with only and the field was not excluded" do
|
1093
|
+
|
1094
|
+
let(:from_db) do
|
1095
|
+
Person.only(:_id).first
|
1096
|
+
end
|
1097
|
+
|
1098
|
+
it "raises an error" do
|
1099
|
+
expect {
|
1100
|
+
from_db.read_attribute(:undefined_field)
|
1101
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
1102
|
+
end
|
1103
|
+
end
|
1104
|
+
|
1105
|
+
context "when excluding with without and the field was excluded" do
|
1106
|
+
|
1107
|
+
let(:from_db) do
|
1108
|
+
Person.without(:title).first
|
1109
|
+
end
|
1110
|
+
|
1111
|
+
it "raises an error" do
|
1112
|
+
expect {
|
1113
|
+
from_db.read_attribute(:title)
|
1114
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
1115
|
+
end
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
context "when excluding with without and the field was not excluded" do
|
1119
|
+
|
1120
|
+
let(:from_db) do
|
1121
|
+
Person.without(:title).first
|
1122
|
+
end
|
1123
|
+
|
1124
|
+
it "returns nil" do
|
1125
|
+
from_db.read_attribute(:undefined_field).should be nil
|
1126
|
+
end
|
1127
|
+
end
|
1128
|
+
end
|
896
1129
|
end
|
897
1130
|
|
898
1131
|
describe "#attribute_present?" do
|
@@ -1398,6 +1631,51 @@ describe Mongoid::Attributes do
|
|
1398
1631
|
expect(dictionary.description).to eq('foo')
|
1399
1632
|
end
|
1400
1633
|
end
|
1634
|
+
|
1635
|
+
context 'when writing fields on a document with projection' do
|
1636
|
+
|
1637
|
+
let!(:person) do
|
1638
|
+
Person.create(title: "sir")
|
1639
|
+
end
|
1640
|
+
|
1641
|
+
context "when excluding with only and the field was not excluded" do
|
1642
|
+
|
1643
|
+
let(:from_db) do
|
1644
|
+
Person.only(:_id).first
|
1645
|
+
end
|
1646
|
+
|
1647
|
+
it "raises an error" do
|
1648
|
+
expect {
|
1649
|
+
from_db.write_attribute(:undefined_field, 'x')
|
1650
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
1651
|
+
end
|
1652
|
+
end
|
1653
|
+
|
1654
|
+
context "when excluding with without and the field was excluded" do
|
1655
|
+
|
1656
|
+
let(:from_db) do
|
1657
|
+
Person.without(:title).first
|
1658
|
+
end
|
1659
|
+
|
1660
|
+
it "raises an error" do
|
1661
|
+
expect {
|
1662
|
+
from_db.write_attribute(:title, 'x')
|
1663
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
1664
|
+
end
|
1665
|
+
end
|
1666
|
+
|
1667
|
+
context "when excluding with without and the field was not excluded" do
|
1668
|
+
|
1669
|
+
let(:from_db) do
|
1670
|
+
Person.without(:title).first
|
1671
|
+
end
|
1672
|
+
|
1673
|
+
it "writes the value" do
|
1674
|
+
from_db.write_attribute(:undefined_field, 'x')
|
1675
|
+
from_db.read_attribute(:undefined_field).should == 'x'
|
1676
|
+
end
|
1677
|
+
end
|
1678
|
+
end
|
1401
1679
|
end
|
1402
1680
|
|
1403
1681
|
describe "#typed_value_for" do
|
@@ -1651,6 +1929,61 @@ describe Mongoid::Attributes do
|
|
1651
1929
|
end
|
1652
1930
|
end
|
1653
1931
|
|
1932
|
+
describe '#unalias_attribute' do
|
1933
|
+
let(:shirt) { Shirt.new }
|
1934
|
+
let(:id) { '1234' }
|
1935
|
+
|
1936
|
+
context 'when creating object' do
|
1937
|
+
let(:shirt) { Shirt.new(id: id) }
|
1938
|
+
|
1939
|
+
it 'id and _id are not the same' do
|
1940
|
+
expect(shirt.id).to eq(id)
|
1941
|
+
expect(shirt._id).not_to eq(id)
|
1942
|
+
end
|
1943
|
+
end
|
1944
|
+
|
1945
|
+
context 'update' do
|
1946
|
+
before do
|
1947
|
+
shirt.update(id: id)
|
1948
|
+
end
|
1949
|
+
|
1950
|
+
it 'updates id but not_id' do
|
1951
|
+
expect(shirt.id).to eq(id)
|
1952
|
+
expect(shirt._id).not_to eq(id)
|
1953
|
+
end
|
1954
|
+
end
|
1955
|
+
|
1956
|
+
context 'id=' do
|
1957
|
+
before do
|
1958
|
+
shirt.id = id
|
1959
|
+
end
|
1960
|
+
|
1961
|
+
it 'sets id and not _id' do
|
1962
|
+
expect(shirt.id).to eq(id)
|
1963
|
+
expect(shirt._id).not_to eq(id)
|
1964
|
+
end
|
1965
|
+
end
|
1966
|
+
|
1967
|
+
context 'id?' do
|
1968
|
+
context 'with null id' do
|
1969
|
+
it 'returns false' do
|
1970
|
+
expect(shirt.id?).to be false
|
1971
|
+
expect(shirt._id?).to be true
|
1972
|
+
end
|
1973
|
+
end
|
1974
|
+
|
1975
|
+
context 'with id' do
|
1976
|
+
before do
|
1977
|
+
shirt.id = id
|
1978
|
+
end
|
1979
|
+
|
1980
|
+
it 'returns true' do
|
1981
|
+
expect(shirt.id?).to be true
|
1982
|
+
end
|
1983
|
+
end
|
1984
|
+
end
|
1985
|
+
end
|
1986
|
+
|
1654
1987
|
describe "#alias_attribute" do
|
1655
1988
|
|
1656
1989
|
let(:product) do
|
@@ -47,6 +47,7 @@ describe Mongoid::Clients::Factory do
|
|
47
47
|
|
48
48
|
before do
|
49
49
|
Mongoid::Config.send(:clients=, config)
|
50
|
+
# TODO: We should restore overwritten configuration in after block
|
50
51
|
end
|
51
52
|
|
52
53
|
after do
|
@@ -124,6 +125,7 @@ describe Mongoid::Clients::Factory do
|
|
124
125
|
|
125
126
|
before do
|
126
127
|
Mongoid::Config.send(:clients=, config)
|
128
|
+
# TODO: We should restore overwritten configuration in after block
|
127
129
|
end
|
128
130
|
|
129
131
|
after do
|
@@ -168,6 +170,7 @@ describe Mongoid::Clients::Factory do
|
|
168
170
|
|
169
171
|
before do
|
170
172
|
Mongoid::Config.send(:clients=, config)
|
173
|
+
# TODO: We should restore overwritten configuration in after block
|
171
174
|
end
|
172
175
|
|
173
176
|
after do
|
@@ -206,6 +209,7 @@ describe Mongoid::Clients::Factory do
|
|
206
209
|
|
207
210
|
before do
|
208
211
|
Mongoid::Config.send(:clients=, config)
|
212
|
+
# TODO: We should restore overwritten configuration in after block
|
209
213
|
end
|
210
214
|
|
211
215
|
after do
|
@@ -253,6 +257,7 @@ describe Mongoid::Clients::Factory do
|
|
253
257
|
|
254
258
|
before do
|
255
259
|
Mongoid::Config.send(:clients=, config)
|
260
|
+
# TODO: We should restore overwritten configuration in after block
|
256
261
|
end
|
257
262
|
|
258
263
|
after do
|
@@ -284,6 +289,7 @@ describe Mongoid::Clients::Factory do
|
|
284
289
|
|
285
290
|
before do
|
286
291
|
Mongoid.clients[:default] = nil
|
292
|
+
# TODO: We should restore overwritten configuration in after block
|
287
293
|
end
|
288
294
|
|
289
295
|
it "raises NoClientsConfig error" do
|
@@ -300,6 +306,7 @@ describe Mongoid::Clients::Factory do
|
|
300
306
|
|
301
307
|
before do
|
302
308
|
Mongoid::Config.send(:clients=, config)
|
309
|
+
# TODO: We should restore overwritten configuration in after block
|
303
310
|
end
|
304
311
|
|
305
312
|
after do
|
@@ -342,6 +349,7 @@ describe Mongoid::Clients::Factory do
|
|
342
349
|
|
343
350
|
before do
|
344
351
|
Mongoid::Config.send(:clients=, config)
|
352
|
+
# TODO: We should restore overwritten configuration in after block
|
345
353
|
end
|
346
354
|
|
347
355
|
after do
|
@@ -378,4 +386,44 @@ describe Mongoid::Clients::Factory do
|
|
378
386
|
expect(client.options[:platform]).to eq(Mongoid::PLATFORM_DETAILS)
|
379
387
|
end
|
380
388
|
end
|
389
|
+
|
390
|
+
context "unexpected config options" do
|
391
|
+
let(:unknown_opts) do
|
392
|
+
{
|
393
|
+
bad_one: 1,
|
394
|
+
another_one: "here"
|
395
|
+
}
|
396
|
+
end
|
397
|
+
|
398
|
+
let(:config) do
|
399
|
+
{
|
400
|
+
default: { hosts: SpecConfig.instance.addresses, database: database_id },
|
401
|
+
good_one: { hosts: [ "127.0.0.1:1234" ], database: database_id},
|
402
|
+
bad_one: { hosts: [ "127.0.0.1:1234" ], database: database_id}.merge(unknown_opts),
|
403
|
+
good_two: { uri: "mongodb://127.0.0.1:1234,127.0.0.1:5678/#{database_id}" },
|
404
|
+
bad_two: { uri: "mongodb://127.0.0.1:1234,127.0.0.1:5678/#{database_id}" }.merge(unknown_opts)
|
405
|
+
}
|
406
|
+
end
|
407
|
+
|
408
|
+
around(:each) do |example|
|
409
|
+
old_config = Mongoid::Config.clients
|
410
|
+
Mongoid::Config.send(:clients=, config)
|
411
|
+
example.run
|
412
|
+
Mongoid::Config.send(:clients=, old_config)
|
413
|
+
end
|
414
|
+
|
415
|
+
[:bad_one, :bad_two].each do |env|
|
416
|
+
it 'does not log a warning if none' do
|
417
|
+
expect(described_class.send(:default_logger)).not_to receive(:warn)
|
418
|
+
described_class.create(env).close
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
[:bad_one, :bad_two].each do |env|
|
423
|
+
it 'logs a warning if some' do
|
424
|
+
expect(described_class.send(:default_logger)).not_to receive(:warn)
|
425
|
+
described_class.create(env).close
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|
381
429
|
end
|
data/spec/mongoid/config_spec.rb
CHANGED
@@ -545,4 +545,36 @@ describe Mongoid::Config do
|
|
545
545
|
expect(Mongoid::Config.log_level).to eq(2)
|
546
546
|
end
|
547
547
|
end
|
548
|
+
|
549
|
+
context "with an overridden database" do
|
550
|
+
let(:database) do
|
551
|
+
"test_purge_#{Time.now.to_i}"
|
552
|
+
end
|
553
|
+
|
554
|
+
before do
|
555
|
+
Mongoid.override_database(database)
|
556
|
+
end
|
557
|
+
|
558
|
+
after do
|
559
|
+
Mongoid.override_database(nil)
|
560
|
+
end
|
561
|
+
|
562
|
+
describe "#purge!" do
|
563
|
+
it 'respects persistence context overrides' do
|
564
|
+
House.create!(name: '1', model: 'Big')
|
565
|
+
expect(House.count).to eq(1)
|
566
|
+
Mongoid.purge!
|
567
|
+
expect(House.count).to eq(0)
|
568
|
+
end
|
569
|
+
end
|
570
|
+
|
571
|
+
describe "#truncate!" do
|
572
|
+
it 'respects persistence context overrides' do
|
573
|
+
House.create!(name: '1', model: 'Big')
|
574
|
+
expect(House.count).to eq(1)
|
575
|
+
Mongoid.truncate!
|
576
|
+
expect(House.count).to eq(0)
|
577
|
+
end
|
578
|
+
end
|
579
|
+
end
|
548
580
|
end
|
@@ -753,12 +753,25 @@ describe Mongoid::Contextual::Atomic do
|
|
753
753
|
context.set(name: "Recoil")
|
754
754
|
end
|
755
755
|
|
756
|
-
|
757
|
-
|
756
|
+
shared_examples 'writes as expected' do
|
757
|
+
it "sets existing fields" do
|
758
|
+
expect(depeche_mode.reload.name).to eq("Recoil")
|
759
|
+
end
|
760
|
+
|
761
|
+
it "sets non existent fields" do
|
762
|
+
expect(smiths.reload.name).to eq("Recoil")
|
763
|
+
end
|
758
764
|
end
|
759
765
|
|
760
|
-
|
761
|
-
|
766
|
+
include_examples 'writes as expected'
|
767
|
+
|
768
|
+
context 'when fields being set have been projected out' do
|
769
|
+
|
770
|
+
let(:criteria) do
|
771
|
+
Band.only(:genres)
|
772
|
+
end
|
773
|
+
|
774
|
+
include_examples 'writes as expected'
|
762
775
|
end
|
763
776
|
end
|
764
777
|
|
@@ -1442,8 +1442,8 @@ describe Mongoid::Contextual::Mongo do
|
|
1442
1442
|
describe "##{method}" do
|
1443
1443
|
|
1444
1444
|
before do
|
1445
|
-
Band.create(name: "Depeche Mode")
|
1446
|
-
Band.create(name: "New Order")
|
1445
|
+
Band.create!(name: "Depeche Mode")
|
1446
|
+
Band.create!(name: "New Order")
|
1447
1447
|
end
|
1448
1448
|
|
1449
1449
|
context "when the criteria has a limit" do
|
@@ -9,79 +9,6 @@ describe Mongoid::Criteria::Queryable::Expandable do
|
|
9
9
|
Mongoid::Query.new
|
10
10
|
end
|
11
11
|
|
12
|
-
describe '#expand_condition' do
|
13
|
-
|
14
|
-
let(:expanded) do
|
15
|
-
query.send(:expand_condition, condition)
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'field name => value' do
|
19
|
-
shared_examples_for 'expands' do
|
20
|
-
|
21
|
-
it 'expands' do
|
22
|
-
expanded.should == {'foo' => 'bar'}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'string key' do
|
27
|
-
let(:condition) do
|
28
|
-
{'foo' => 'bar'}
|
29
|
-
end
|
30
|
-
|
31
|
-
it_behaves_like 'expands'
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'symbol key' do
|
35
|
-
let(:condition) do
|
36
|
-
{foo: 'bar'}
|
37
|
-
end
|
38
|
-
|
39
|
-
it_behaves_like 'expands'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'Key instance => value' do
|
44
|
-
let(:key) do
|
45
|
-
Mongoid::Criteria::Queryable::Key.new(:foo, :__override__, '$gt')
|
46
|
-
end
|
47
|
-
|
48
|
-
let(:condition) do
|
49
|
-
{key => 'bar'}
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'expands' do
|
53
|
-
expanded.should == {'foo' => {'$gt' => 'bar'}}
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
=begin
|
58
|
-
context 'operator => operator value expression' do
|
59
|
-
shared_examples_for 'expands' do
|
60
|
-
|
61
|
-
it 'expands' do
|
62
|
-
expanded.should == {'foo' => 'bar'}
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'string key' do
|
67
|
-
let(:condition) do
|
68
|
-
{'$in' => %w(bar)}
|
69
|
-
end
|
70
|
-
|
71
|
-
it_behaves_like 'expands'
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'symbol key' do
|
75
|
-
let(:condition) do
|
76
|
-
{:$in => %w(bar)}
|
77
|
-
end
|
78
|
-
|
79
|
-
it_behaves_like 'expands'
|
80
|
-
end
|
81
|
-
end
|
82
|
-
=end
|
83
|
-
end
|
84
|
-
|
85
12
|
describe '#expand_condition_to_array_values' do
|
86
13
|
shared_examples_for 'expands' do
|
87
14
|
|