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
|
@@ -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
|
|
@@ -130,6 +131,7 @@ describe Mongoid::Clients::Factory do
|
|
|
130
131
|
|
|
131
132
|
before do
|
|
132
133
|
Mongoid::Config.send(:clients=, config)
|
|
134
|
+
# TODO: We should restore overwritten configuration in after block
|
|
133
135
|
end
|
|
134
136
|
|
|
135
137
|
after do
|
|
@@ -174,6 +176,7 @@ describe Mongoid::Clients::Factory do
|
|
|
174
176
|
|
|
175
177
|
before do
|
|
176
178
|
Mongoid::Config.send(:clients=, config)
|
|
179
|
+
# TODO: We should restore overwritten configuration in after block
|
|
177
180
|
end
|
|
178
181
|
|
|
179
182
|
after do
|
|
@@ -212,6 +215,7 @@ describe Mongoid::Clients::Factory do
|
|
|
212
215
|
|
|
213
216
|
before do
|
|
214
217
|
Mongoid::Config.send(:clients=, config)
|
|
218
|
+
# TODO: We should restore overwritten configuration in after block
|
|
215
219
|
end
|
|
216
220
|
|
|
217
221
|
after do
|
|
@@ -259,6 +263,7 @@ describe Mongoid::Clients::Factory do
|
|
|
259
263
|
|
|
260
264
|
before do
|
|
261
265
|
Mongoid::Config.send(:clients=, config)
|
|
266
|
+
# TODO: We should restore overwritten configuration in after block
|
|
262
267
|
end
|
|
263
268
|
|
|
264
269
|
after do
|
|
@@ -290,6 +295,7 @@ describe Mongoid::Clients::Factory do
|
|
|
290
295
|
|
|
291
296
|
before do
|
|
292
297
|
Mongoid.clients[:default] = nil
|
|
298
|
+
# TODO: We should restore overwritten configuration in after block
|
|
293
299
|
end
|
|
294
300
|
|
|
295
301
|
it "raises NoClientsConfig error" do
|
|
@@ -306,6 +312,7 @@ describe Mongoid::Clients::Factory do
|
|
|
306
312
|
|
|
307
313
|
before do
|
|
308
314
|
Mongoid::Config.send(:clients=, config)
|
|
315
|
+
# TODO: We should restore overwritten configuration in after block
|
|
309
316
|
end
|
|
310
317
|
|
|
311
318
|
after do
|
|
@@ -348,6 +355,7 @@ describe Mongoid::Clients::Factory do
|
|
|
348
355
|
|
|
349
356
|
before do
|
|
350
357
|
Mongoid::Config.send(:clients=, config)
|
|
358
|
+
# TODO: We should restore overwritten configuration in after block
|
|
351
359
|
end
|
|
352
360
|
|
|
353
361
|
after do
|
|
@@ -384,4 +392,44 @@ describe Mongoid::Clients::Factory do
|
|
|
384
392
|
expect(client.options[:platform]).to eq(Mongoid::PLATFORM_DETAILS)
|
|
385
393
|
end
|
|
386
394
|
end
|
|
395
|
+
|
|
396
|
+
context "unexpected config options" do
|
|
397
|
+
let(:unknown_opts) do
|
|
398
|
+
{
|
|
399
|
+
bad_one: 1,
|
|
400
|
+
another_one: "here"
|
|
401
|
+
}
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
let(:config) do
|
|
405
|
+
{
|
|
406
|
+
default: { hosts: SpecConfig.instance.addresses, database: database_id },
|
|
407
|
+
good_one: { hosts: [ "127.0.0.1:1234" ], database: database_id},
|
|
408
|
+
bad_one: { hosts: [ "127.0.0.1:1234" ], database: database_id}.merge(unknown_opts),
|
|
409
|
+
good_two: { uri: "mongodb://127.0.0.1:1234,127.0.0.1:5678/#{database_id}" },
|
|
410
|
+
bad_two: { uri: "mongodb://127.0.0.1:1234,127.0.0.1:5678/#{database_id}" }.merge(unknown_opts)
|
|
411
|
+
}
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
around(:each) do |example|
|
|
415
|
+
old_config = Mongoid::Config.clients
|
|
416
|
+
Mongoid::Config.send(:clients=, config)
|
|
417
|
+
example.run
|
|
418
|
+
Mongoid::Config.send(:clients=, old_config)
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
[:bad_one, :bad_two].each do |env|
|
|
422
|
+
it 'does not log a warning if none' do
|
|
423
|
+
expect(described_class.send(:default_logger)).not_to receive(:warn)
|
|
424
|
+
described_class.create(env).close
|
|
425
|
+
end
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
[:bad_one, :bad_two].each do |env|
|
|
429
|
+
it 'logs a warning if some' do
|
|
430
|
+
expect(described_class.send(:default_logger)).not_to receive(:warn)
|
|
431
|
+
described_class.create(env).close
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
end
|
|
387
435
|
end
|
data/spec/mongoid/config_spec.rb
CHANGED
|
@@ -219,7 +219,7 @@ describe Mongoid::Config do
|
|
|
219
219
|
expect(Mongoid::Config.discriminator_key).to be("test")
|
|
220
220
|
end
|
|
221
221
|
|
|
222
|
-
it 'is set globally' do
|
|
222
|
+
it 'is set globally' do
|
|
223
223
|
expect(Mongoid.discriminator_key).to be("test")
|
|
224
224
|
end
|
|
225
225
|
end
|
|
@@ -545,4 +545,109 @@ describe Mongoid::Config do
|
|
|
545
545
|
expect(Mongoid::Config.log_level).to eq(2)
|
|
546
546
|
end
|
|
547
547
|
end
|
|
548
|
+
|
|
549
|
+
describe "#purge!" do
|
|
550
|
+
|
|
551
|
+
it 'deletes models' do
|
|
552
|
+
House.create!(name: '1', model: 'Big')
|
|
553
|
+
expect(House.count).to eq(1)
|
|
554
|
+
Mongoid.purge!
|
|
555
|
+
expect(House.count).to eq(0)
|
|
556
|
+
end
|
|
557
|
+
|
|
558
|
+
it 'drops collections' do
|
|
559
|
+
House.create!(name: '1', model: 'Big')
|
|
560
|
+
Band.create!(name: 'Fleet Foxes')
|
|
561
|
+
|
|
562
|
+
client = Mongoid.default_client
|
|
563
|
+
expect(client.collections.map(&:name).sort).to eq %w[bands houses]
|
|
564
|
+
Mongoid.purge!
|
|
565
|
+
expect(client.collections.map(&:name)).to eq []
|
|
566
|
+
end
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
describe "#truncate!" do
|
|
570
|
+
|
|
571
|
+
it 'deletes models' do
|
|
572
|
+
House.create!(name: '1', model: 'Big')
|
|
573
|
+
expect(House.count).to eq(1)
|
|
574
|
+
Mongoid.truncate!
|
|
575
|
+
expect(House.count).to eq(0)
|
|
576
|
+
end
|
|
577
|
+
|
|
578
|
+
it 'does not drop collections' do
|
|
579
|
+
House.create!(name: '1', model: 'Big')
|
|
580
|
+
Band.create!(name: 'Fleet Foxes')
|
|
581
|
+
|
|
582
|
+
client = Mongoid.default_client
|
|
583
|
+
expect(client.collections.map(&:name).sort).to eq %w[bands houses]
|
|
584
|
+
Mongoid.truncate!
|
|
585
|
+
expect(client.collections.map(&:name).sort).to eq %w[bands houses]
|
|
586
|
+
end
|
|
587
|
+
|
|
588
|
+
it 'does not drop indexes' do
|
|
589
|
+
User.create_indexes
|
|
590
|
+
expect(User.collection.indexes.map {|i| i['name'] }).to eq %w[_id_ name_1]
|
|
591
|
+
Mongoid.truncate!
|
|
592
|
+
expect(User.collection.indexes.map {|i| i['name'] }).to eq %w[_id_ name_1]
|
|
593
|
+
end
|
|
594
|
+
end
|
|
595
|
+
|
|
596
|
+
describe "#override_database" do
|
|
597
|
+
let(:database) do
|
|
598
|
+
"test_override_#{Time.now.to_i}"
|
|
599
|
+
end
|
|
600
|
+
|
|
601
|
+
after do
|
|
602
|
+
# Ensure the database override is cleared.
|
|
603
|
+
Mongoid.override_database(nil)
|
|
604
|
+
end
|
|
605
|
+
|
|
606
|
+
it 'overrides document querying and persistence' do
|
|
607
|
+
House.create!(name: '1', model: 'Big')
|
|
608
|
+
expect(House.count).to eq(1)
|
|
609
|
+
|
|
610
|
+
Mongoid.override_database(database)
|
|
611
|
+
expect(House.count).to eq(0)
|
|
612
|
+
|
|
613
|
+
expect(Band.count).to eq(0)
|
|
614
|
+
Band.create!(name: 'Wolf Alice')
|
|
615
|
+
expect(Band.count).to eq(1)
|
|
616
|
+
|
|
617
|
+
Mongoid.override_database(nil)
|
|
618
|
+
expect(House.count).to eq(1)
|
|
619
|
+
expect(Band.count).to eq(0)
|
|
620
|
+
end
|
|
621
|
+
|
|
622
|
+
context '#truncate and #purge' do
|
|
623
|
+
before do
|
|
624
|
+
House.create!(name: '1', model: 'Big')
|
|
625
|
+
expect(House.count).to eq(1)
|
|
626
|
+
Mongoid.override_database(database)
|
|
627
|
+
end
|
|
628
|
+
|
|
629
|
+
after do
|
|
630
|
+
Mongoid.override_database(nil)
|
|
631
|
+
expect(House.count).to eq(1)
|
|
632
|
+
end
|
|
633
|
+
|
|
634
|
+
context '#purge' do
|
|
635
|
+
it 'respects persistence context overrides' do
|
|
636
|
+
House.create!(name: '2', model: 'Tiny')
|
|
637
|
+
expect(House.count).to eq(1)
|
|
638
|
+
Mongoid.purge!
|
|
639
|
+
expect(House.count).to eq(0)
|
|
640
|
+
end
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
context '#truncate' do
|
|
644
|
+
it '#truncate! respects persistence context overrides' do
|
|
645
|
+
House.create!(name: '2', model: 'Tiny')
|
|
646
|
+
expect(House.count).to eq(1)
|
|
647
|
+
Mongoid.truncate!
|
|
648
|
+
expect(House.count).to eq(0)
|
|
649
|
+
end
|
|
650
|
+
end
|
|
651
|
+
end
|
|
652
|
+
end
|
|
548
653
|
end
|
|
@@ -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
|
|
|
@@ -44,7 +44,7 @@ describe Mongoid::Criteria::Queryable::Mergeable do
|
|
|
44
44
|
|
|
45
45
|
describe '#_mongoid_expand_keys' do
|
|
46
46
|
it 'expands simple keys' do
|
|
47
|
-
query.send(:_mongoid_expand_keys, {a: 1}).should == {a
|
|
47
|
+
query.send(:_mongoid_expand_keys, {a: 1}).should == {'a' => 1}
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
let(:gt) do
|
|
@@ -68,18 +68,116 @@ describe Mongoid::Criteria::Queryable::Mergeable do
|
|
|
68
68
|
'age' => {'$gt' => 42, '$lt' => 50}}
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
context 'given implicit equality and Key instance on the same field' do
|
|
72
|
+
[42, 'infinite', [nil]].each do |value|
|
|
73
|
+
context "for non-regular expression value #{value}" do
|
|
74
|
+
context 'implicit equality then Key instance' do
|
|
75
|
+
it 'expands implicit equality with $eq and combines with Key operator' do
|
|
76
|
+
query.send(:_mongoid_expand_keys, {'age' => value, lt => 50}).should == {
|
|
77
|
+
'age' => {'$eq' => value, '$lt' => 50}}
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context 'symbol operator then implicit equality' do
|
|
82
|
+
it 'expands implicit equality with $eq and combines with Key operator' do
|
|
83
|
+
query.send(:_mongoid_expand_keys, {gt => 42, 'age' => value}).should == {
|
|
84
|
+
'age' => {'$gt' => 42, '$eq' => value}}
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
74
89
|
end
|
|
75
90
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
context 'given implicit equality with Regexp argument and Key instance on the same field' do
|
|
92
|
+
[/42/, BSON::Regexp::Raw.new('42')].each do |value|
|
|
93
|
+
context "for regular expression value #{value}" do
|
|
94
|
+
context 'implicit equality then Key instance' do
|
|
95
|
+
it 'expands implicit equality with $eq and combines with Key operator' do
|
|
96
|
+
query.send(:_mongoid_expand_keys, {'age' => value, lt => 50}).should == {
|
|
97
|
+
'age' => {'$regex' => value, '$lt' => 50}}
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
context 'Key instance then implicit equality' do
|
|
102
|
+
it 'expands implicit equality with $eq and combines with Key operator' do
|
|
103
|
+
query.send(:_mongoid_expand_keys, {gt => 50, 'age' => value}).should == {
|
|
104
|
+
'age' => {'$gt' => 50, '$regex' => value}}
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
79
109
|
end
|
|
80
110
|
|
|
81
111
|
it 'Ruby does not allow same symbol operator with different values' do
|
|
82
112
|
{gt => 42, gtp => 50}.should == {gtp => 50}
|
|
83
113
|
end
|
|
114
|
+
|
|
115
|
+
let(:expanded) do
|
|
116
|
+
query.send(:_mongoid_expand_keys, condition)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
context 'field name => value' do
|
|
120
|
+
shared_examples_for 'expands' do
|
|
121
|
+
|
|
122
|
+
it 'expands' do
|
|
123
|
+
expanded.should == {'foo' => 'bar'}
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
context 'string key' do
|
|
128
|
+
let(:condition) do
|
|
129
|
+
{'foo' => 'bar'}
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it_behaves_like 'expands'
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
context 'symbol key' do
|
|
136
|
+
let(:condition) do
|
|
137
|
+
{foo: 'bar'}
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it_behaves_like 'expands'
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
context 'Key instance => value' do
|
|
145
|
+
let(:key) do
|
|
146
|
+
Mongoid::Criteria::Queryable::Key.new(:foo, :__override__, '$gt')
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
let(:condition) do
|
|
150
|
+
{key => 'bar'}
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
it 'expands' do
|
|
154
|
+
expanded.should == {'foo' => {'$gt' => 'bar'}}
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
context 'operator => operator value expression' do
|
|
159
|
+
shared_examples_for 'expands' do
|
|
160
|
+
|
|
161
|
+
it 'expands' do
|
|
162
|
+
expanded.should == {'foo' => {'$in' => ['bar']}}
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
context 'string key' do
|
|
167
|
+
let(:condition) do
|
|
168
|
+
{foo: {'$in' => %w(bar)}}
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it_behaves_like 'expands'
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
context 'symbol key' do
|
|
175
|
+
let(:condition) do
|
|
176
|
+
{foo: {:$in => %w(bar)}}
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it_behaves_like 'expands'
|
|
180
|
+
end
|
|
181
|
+
end
|
|
84
182
|
end
|
|
85
183
|
end
|