mongoid 7.2.0.rc1 → 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.tar.gz.sig +0 -0
- data/Rakefile +45 -10
- 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/buildable.rb +8 -0
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +2 -2
- data/lib/mongoid/association/referenced/has_one/proxy.rb +6 -1
- data/lib/mongoid/attributes.rb +32 -14
- data/lib/mongoid/attributes/projector.rb +120 -0
- data/lib/mongoid/cacheable.rb +2 -2
- data/lib/mongoid/clients.rb +1 -1
- data/lib/mongoid/clients/factory.rb +22 -8
- data/lib/mongoid/config.rb +19 -2
- data/lib/mongoid/contextual/aggregable/mongo.rb +10 -8
- data/lib/mongoid/copyable.rb +6 -2
- data/lib/mongoid/criteria.rb +4 -5
- data/lib/mongoid/criteria/findable.rb +1 -1
- data/lib/mongoid/criteria/queryable/expandable.rb +0 -24
- data/lib/mongoid/criteria/queryable/extensions.rb +0 -4
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
- 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/document.rb +4 -17
- data/lib/mongoid/errors/delete_restriction.rb +8 -9
- data/lib/mongoid/evolvable.rb +1 -1
- data/lib/mongoid/extensions.rb +1 -0
- 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 +46 -5
- data/lib/mongoid/inspectable.rb +1 -1
- data/lib/mongoid/interceptable.rb +3 -1
- data/lib/mongoid/matcher.rb +26 -43
- 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/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/stringified_symbol.rb +53 -0
- 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/README.md +19 -4
- data/spec/integration/app_spec.rb +175 -88
- data/spec/integration/associations/embeds_many_spec.rb +68 -0
- data/spec/integration/associations/embeds_one_spec.rb +24 -0
- data/spec/integration/associations/has_many_spec.rb +60 -0
- data/spec/integration/associations/has_one_spec.rb +108 -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/integration/stringified_symbol_field_spec.rb +190 -0
- data/spec/lite_spec_helper.rb +9 -7
- 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_many_models.rb +12 -0
- data/spec/mongoid/association/referenced/has_one_models.rb +20 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +1 -1
- 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/copyable_spec.rb +44 -17
- data/spec/mongoid/copyable_spec_models.rb +14 -0
- 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/equality_spec.rb +0 -1
- 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/stringified_symbol_spec.rb +85 -0
- 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/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +221 -0
- data/spec/shared/lib/mrss/constraints.rb +354 -0
- data/spec/shared/lib/mrss/docker_runner.rb +265 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +115 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +162 -0
- 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 +7 -1
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/constraints.rb +0 -226
- 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/order.rb +11 -0
- data/spec/support/models/person.rb +8 -0
- data/spec/support/models/sealer.rb +8 -0
- data/spec/support/models/series.rb +1 -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/models/wiki_page.rb +1 -0
- data/spec/support/spec_config.rb +8 -0
- metadata +655 -507
- metadata.gz.sig +0 -0
- data/spec/support/child_process_helper.rb +0 -79
- data/spec/support/cluster_config.rb +0 -158
- data/spec/support/lite_constraints.rb +0 -22
- data/spec/support/spec_organizer.rb +0 -130
@@ -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
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
# -*- coding: utf-8 -*-
|
5
4
|
require "spec_helper"
|
6
5
|
|
7
6
|
require_relative './copyable_spec_models'
|
@@ -65,30 +64,58 @@ describe Mongoid::Copyable do
|
|
65
64
|
|
66
65
|
context "when a document has fields from a legacy schema" do
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
shared_examples 'behaves as expected' do
|
68
|
+
let!(:instance) do
|
69
|
+
cls.create(name: "test")
|
70
|
+
end
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
before do
|
73
|
+
legacy_fields = { "this_is_not_a_field" => 1, "this_legacy_field_is_nil" => nil }
|
74
|
+
cls.collection.find(_id: instance.id).update_one("$set" => legacy_fields)
|
75
|
+
end
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
let(:cloned) do
|
78
|
+
instance.reload.send(method)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "sets the legacy attribute" do
|
82
|
+
expect(cloned.attributes['this_is_not_a_field']).to eq(1)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "contains legacy attributes that are nil" do
|
86
|
+
expect(cloned.attributes.key?('this_legacy_field_is_nil')).to eq(true)
|
87
|
+
end
|
80
88
|
|
81
|
-
|
82
|
-
|
89
|
+
it "copies the known attributes" do
|
90
|
+
expect(cloned.name).to eq('test')
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'calls constructor with explicitly declared attributes only' do
|
94
|
+
expect(cls).to receive(:new).with('name' => 'test').and_call_original
|
95
|
+
cloned
|
96
|
+
end
|
83
97
|
end
|
84
98
|
|
85
|
-
|
86
|
-
|
99
|
+
context 'without Attributes::Dynamic' do
|
100
|
+
let(:cls) { CopyableSpec::Reg }
|
101
|
+
|
102
|
+
before do
|
103
|
+
cls.should_not include(Mongoid::Attributes::Dynamic)
|
104
|
+
end
|
105
|
+
|
106
|
+
include_examples 'behaves as expected'
|
87
107
|
end
|
88
108
|
|
89
|
-
|
90
|
-
|
109
|
+
context 'with Attributes::Dynamic' do
|
110
|
+
let(:cls) { CopyableSpec::Dyn }
|
111
|
+
|
112
|
+
before do
|
113
|
+
cls.should include(Mongoid::Attributes::Dynamic)
|
114
|
+
end
|
115
|
+
|
116
|
+
include_examples 'behaves as expected'
|
91
117
|
end
|
118
|
+
|
92
119
|
end
|
93
120
|
|
94
121
|
context "when using store_as" do
|
@@ -31,4 +31,18 @@ module CopyableSpec
|
|
31
31
|
class Blurb
|
32
32
|
include Mongoid::Document
|
33
33
|
end
|
34
|
+
|
35
|
+
# Do not include Attributes::Dynamic
|
36
|
+
class Reg
|
37
|
+
include Mongoid::Document
|
38
|
+
|
39
|
+
field :name, type: String
|
40
|
+
end
|
41
|
+
|
42
|
+
class Dyn
|
43
|
+
include Mongoid::Document
|
44
|
+
include Mongoid::Attributes::Dynamic
|
45
|
+
|
46
|
+
field :name, type: String
|
47
|
+
end
|
34
48
|
end
|
@@ -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
|