mongoid 8.0.13 → 8.1.0
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/CHANGELOG.md +3 -3
- data/README.md +3 -3
- data/Rakefile +17 -66
- data/lib/config/locales/en.yml +46 -40
- data/lib/mongoid/association/accessors.rb +3 -7
- data/lib/mongoid/association/builders.rb +1 -1
- data/lib/mongoid/association/depending.rb +4 -8
- data/lib/mongoid/association/eager_loadable.rb +0 -3
- data/lib/mongoid/association/embedded/batchable.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -1
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +3 -2
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +6 -6
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +2 -2
- data/lib/mongoid/association/macros.rb +0 -6
- data/lib/mongoid/association/nested/many.rb +3 -38
- data/lib/mongoid/association/nested/nested_buildable.rb +0 -14
- data/lib/mongoid/association/nested/one.rb +40 -2
- data/lib/mongoid/association/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +6 -23
- data/lib/mongoid/association/referenced/has_many/proxy.rb +4 -103
- data/lib/mongoid/association/reflections.rb +2 -2
- data/lib/mongoid/atomic.rb +7 -16
- data/lib/mongoid/attributes/dynamic.rb +1 -1
- data/lib/mongoid/attributes/nested.rb +2 -2
- data/lib/mongoid/attributes/processing.rb +5 -29
- data/lib/mongoid/attributes/projector.rb +1 -1
- data/lib/mongoid/attributes/readonly.rb +1 -1
- data/lib/mongoid/attributes.rb +8 -2
- data/lib/mongoid/changeable.rb +107 -5
- data/lib/mongoid/clients/factory.rb +0 -4
- data/lib/mongoid/clients/storage_options.rb +2 -5
- data/lib/mongoid/clients/validators/storage.rb +1 -13
- data/lib/mongoid/collection_configurable.rb +58 -0
- data/lib/mongoid/composable.rb +2 -0
- data/lib/mongoid/config/defaults.rb +60 -0
- data/lib/mongoid/config/options.rb +0 -3
- data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
- data/lib/mongoid/config/validators.rb +1 -0
- data/lib/mongoid/config.rb +88 -89
- data/lib/mongoid/contextual/aggregable/memory.rb +2 -5
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +240 -51
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +370 -133
- data/lib/mongoid/contextual/none.rb +162 -7
- data/lib/mongoid/contextual.rb +12 -0
- data/lib/mongoid/criteria/findable.rb +2 -2
- data/lib/mongoid/criteria/includable.rb +4 -3
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -15
- data/lib/mongoid/criteria/queryable/key.rb +1 -1
- data/lib/mongoid/criteria/queryable/mergeable.rb +1 -13
- data/lib/mongoid/criteria/queryable/optional.rb +8 -8
- data/lib/mongoid/criteria/queryable/selectable.rb +43 -121
- data/lib/mongoid/criteria/queryable/selector.rb +1 -1
- data/lib/mongoid/criteria/queryable/storable.rb +1 -1
- data/lib/mongoid/criteria.rb +6 -5
- data/lib/mongoid/deprecable.rb +1 -2
- data/lib/mongoid/deprecation.rb +3 -3
- data/lib/mongoid/document.rb +1 -8
- data/lib/mongoid/errors/create_collection_failure.rb +33 -0
- data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
- data/lib/mongoid/errors/immutable_attribute.rb +26 -0
- data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
- data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
- data/lib/mongoid/errors.rb +4 -2
- data/lib/mongoid/extensions/hash.rb +3 -51
- data/lib/mongoid/extensions/object.rb +2 -2
- data/lib/mongoid/extensions/time.rb +2 -0
- data/lib/mongoid/fields/localized.rb +10 -0
- data/lib/mongoid/fields/standard.rb +10 -0
- data/lib/mongoid/fields.rb +59 -35
- data/lib/mongoid/findable.rb +27 -3
- data/lib/mongoid/interceptable.rb +6 -116
- data/lib/mongoid/matchable.rb +1 -6
- data/lib/mongoid/matcher/eq_impl.rb +1 -1
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +5 -3
- data/lib/mongoid/matcher/regex.rb +9 -8
- data/lib/mongoid/matcher/type.rb +1 -1
- data/lib/mongoid/matcher.rb +0 -1
- data/lib/mongoid/persistable/creatable.rb +1 -0
- data/lib/mongoid/persistable/deletable.rb +1 -1
- data/lib/mongoid/persistable/savable.rb +13 -1
- data/lib/mongoid/persistable/unsettable.rb +2 -2
- data/lib/mongoid/persistable/updatable.rb +51 -1
- data/lib/mongoid/persistable/upsertable.rb +20 -1
- data/lib/mongoid/persistable.rb +3 -0
- data/lib/mongoid/query_cache.rb +5 -1
- data/lib/mongoid/railties/database.rake +7 -2
- data/lib/mongoid/reloadable.rb +5 -3
- data/lib/mongoid/stateful.rb +22 -1
- data/lib/mongoid/tasks/database.rake +12 -0
- data/lib/mongoid/tasks/database.rb +20 -0
- data/lib/mongoid/threaded.rb +0 -3
- data/lib/mongoid/timestamps/created.rb +1 -8
- data/lib/mongoid/traversable.rb +0 -12
- data/lib/mongoid/utils.rb +22 -0
- data/lib/mongoid/validatable/associated.rb +17 -98
- data/lib/mongoid/validatable/macros.rb +5 -20
- data/lib/mongoid/validatable.rb +4 -10
- data/lib/mongoid/version.rb +1 -5
- data/lib/mongoid/warnings.rb +17 -2
- data/lib/mongoid.rb +16 -3
- data/spec/integration/app_spec.rb +2 -20
- data/spec/integration/associations/embeds_one_spec.rb +5 -25
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +0 -55
- data/spec/integration/callbacks_spec.rb +99 -12
- data/spec/integration/discriminator_key_spec.rb +4 -5
- data/spec/integration/dots_and_dollars_spec.rb +2 -12
- data/spec/integration/i18n_fallbacks_spec.rb +3 -2
- data/spec/integration/matcher_operator_data/regex.yml +0 -21
- data/spec/mongoid/association/eager_spec.rb +2 -24
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +27 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +20 -25
- data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +0 -4
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +15 -2
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -18
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +42 -103
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +9 -195
- data/spec/mongoid/association/syncable_spec.rb +1 -1
- data/spec/mongoid/attributes/nested_spec.rb +10 -204
- data/spec/mongoid/attributes_spec.rb +3 -33
- data/spec/mongoid/changeable_spec.rb +299 -24
- data/spec/mongoid/clients/factory_spec.rb +0 -30
- data/spec/mongoid/clients_spec.rb +122 -13
- data/spec/mongoid/collection_configurable_spec.rb +158 -0
- data/spec/mongoid/config/defaults_spec.rb +160 -0
- data/spec/mongoid/config_spec.rb +154 -27
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +0 -91
- data/spec/mongoid/contextual/memory_spec.rb +332 -253
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
- data/spec/mongoid/contextual/mongo_spec.rb +1009 -125
- data/spec/mongoid/contextual/none_spec.rb +49 -2
- data/spec/mongoid/copyable_spec.rb +2 -10
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -10
- data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +419 -2
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +0 -235
- data/spec/mongoid/criteria/queryable/selector_spec.rb +3 -76
- data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
- data/spec/mongoid/criteria_projection_spec.rb +1 -4
- data/spec/mongoid/criteria_spec.rb +5 -11
- data/spec/mongoid/document_spec.rb +0 -27
- data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
- data/spec/mongoid/extensions/hash_spec.rb +3 -239
- data/spec/mongoid/extensions/time_spec.rb +8 -43
- data/spec/mongoid/extensions/time_with_zone_spec.rb +7 -52
- data/spec/mongoid/fields/localized_spec.rb +46 -28
- data/spec/mongoid/fields_spec.rb +136 -77
- data/spec/mongoid/findable_spec.rb +391 -34
- data/spec/mongoid/indexable_spec.rb +16 -10
- data/spec/mongoid/interceptable_spec.rb +153 -442
- data/spec/mongoid/interceptable_spec_models.rb +111 -51
- data/spec/mongoid/persistable/deletable_spec.rb +26 -6
- data/spec/mongoid/persistable/destroyable_spec.rb +26 -6
- data/spec/mongoid/persistable/incrementable_spec.rb +37 -0
- data/spec/mongoid/persistable/logical_spec.rb +37 -0
- data/spec/mongoid/persistable/poppable_spec.rb +36 -0
- data/spec/mongoid/persistable/pullable_spec.rb +72 -0
- data/spec/mongoid/persistable/pushable_spec.rb +72 -0
- data/spec/mongoid/persistable/renamable_spec.rb +36 -0
- data/spec/mongoid/persistable/savable_spec.rb +96 -0
- data/spec/mongoid/persistable/settable_spec.rb +37 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +36 -0
- data/spec/mongoid/persistable/updatable_spec.rb +20 -28
- data/spec/mongoid/persistable/upsertable_spec.rb +80 -6
- data/spec/mongoid/persistence_context_spec.rb +7 -57
- data/spec/mongoid/query_cache_spec.rb +56 -61
- data/spec/mongoid/reloadable_spec.rb +24 -28
- data/spec/mongoid/scopable_spec.rb +70 -0
- data/spec/mongoid/serializable_spec.rb +23 -44
- data/spec/mongoid/stateful_spec.rb +122 -8
- data/spec/mongoid/tasks/database_rake_spec.rb +74 -0
- data/spec/mongoid/tasks/database_spec.rb +127 -0
- data/spec/mongoid/timestamps/created_spec.rb +0 -23
- data/spec/mongoid/timestamps_spec.rb +9 -11
- data/spec/mongoid/touchable_spec.rb +277 -5
- data/spec/mongoid/touchable_spec_models.rb +3 -1
- data/spec/mongoid/traversable_spec.rb +9 -24
- data/spec/mongoid/validatable/associated_spec.rb +34 -27
- data/spec/mongoid/validatable/numericality_spec.rb +0 -16
- data/spec/mongoid/validatable/uniqueness_spec.rb +2 -3
- data/spec/mongoid_spec.rb +36 -10
- data/spec/shared/lib/mrss/docker_runner.rb +1 -1
- data/spec/shared/lib/mrss/server_version_registry.rb +1 -1
- data/spec/shared/lib/mrss/spec_organizer.rb +3 -32
- data/spec/shared/share/Dockerfile.erb +85 -15
- data/spec/shared/shlib/distro.sh +0 -10
- data/spec/shared/shlib/server.sh +27 -34
- data/spec/shared/shlib/set_env.sh +68 -9
- data/spec/spec_helper.rb +5 -0
- data/spec/support/expectations.rb +17 -20
- data/spec/support/immutable_ids.rb +118 -0
- data/spec/support/macros.rb +47 -15
- data/spec/support/models/artist.rb +0 -1
- data/spec/support/models/band.rb +1 -0
- data/spec/support/models/building.rb +2 -0
- data/spec/support/models/name.rb +0 -10
- data/spec/support/models/person.rb +0 -1
- data/spec/support/models/product.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +715 -671
- metadata.gz.sig +2 -0
- data/lib/mongoid/errors/in_memory_regexp_timeout.rb +0 -26
- data/lib/mongoid/field_readable.rb +0 -70
- data/lib/mongoid/matcher/regexp_budget.rb +0 -389
- data/lib/mongoid/validatable/numericality.rb +0 -19
- data/spec/integration/matcher_regexp_timeout_spec.rb +0 -215
- data/spec/integration/query_operator_guard_spec.rb +0 -89
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -61
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -61
- data/spec/mongoid/matcher/regexp_budget_spec.rb +0 -570
- data/spec/shared/CANDIDATE.md +0 -28
- data/spec/shared/lib/mrss/release/candidate.rb +0 -281
- data/spec/shared/lib/mrss/release/product_data.rb +0 -144
- data/spec/shared/lib/tasks/candidate.rake +0 -64
- data/spec/support/models/purse.rb +0 -9
|
@@ -178,7 +178,7 @@ describe Mongoid::Extensions::Hash do
|
|
|
178
178
|
|
|
179
179
|
it "moves the non hash values under the provided key" do
|
|
180
180
|
expect(consolidated).to eq({
|
|
181
|
-
"$set" => {
|
|
181
|
+
"$set" => { name: "Tool", likes: 10 }, "$inc" => { plays: 1 }
|
|
182
182
|
})
|
|
183
183
|
end
|
|
184
184
|
end
|
|
@@ -195,7 +195,7 @@ describe Mongoid::Extensions::Hash do
|
|
|
195
195
|
|
|
196
196
|
it "moves the non hash values under the provided key" do
|
|
197
197
|
expect(consolidated).to eq({
|
|
198
|
-
"$set" => { likes: 10,
|
|
198
|
+
"$set" => { likes: 10, name: "Tool" }, "$inc" => { plays: 1 }
|
|
199
199
|
})
|
|
200
200
|
end
|
|
201
201
|
end
|
|
@@ -213,7 +213,7 @@ describe Mongoid::Extensions::Hash do
|
|
|
213
213
|
|
|
214
214
|
it "moves the non hash values under the provided key" do
|
|
215
215
|
expect(consolidated).to eq({
|
|
216
|
-
"$set" => { likes: 10, name: "Tool" }, "$inc" => {
|
|
216
|
+
"$set" => { likes: 10, name: "Tool" }, "$inc" => { plays: 1 }
|
|
217
217
|
})
|
|
218
218
|
end
|
|
219
219
|
end
|
|
@@ -497,240 +497,4 @@ describe Mongoid::Extensions::Hash do
|
|
|
497
497
|
|
|
498
498
|
it_behaves_like 'unsatisfiable criteria method'
|
|
499
499
|
end
|
|
500
|
-
|
|
501
|
-
describe '#to_criteria' do
|
|
502
|
-
subject(:criteria) { hash.to_criteria }
|
|
503
|
-
|
|
504
|
-
context 'when klass is specified' do
|
|
505
|
-
let(:hash) do
|
|
506
|
-
{ klass: Band, where: { name: 'Songs Ohia' } }
|
|
507
|
-
end
|
|
508
|
-
|
|
509
|
-
it 'returns a criteria' do
|
|
510
|
-
expect(criteria).to be_a(Mongoid::Criteria)
|
|
511
|
-
end
|
|
512
|
-
|
|
513
|
-
it 'sets the klass' do
|
|
514
|
-
expect(criteria.klass).to eq(Band)
|
|
515
|
-
end
|
|
516
|
-
|
|
517
|
-
it 'sets the selector' do
|
|
518
|
-
expect(criteria.selector).to eq({ 'name' => 'Songs Ohia' })
|
|
519
|
-
end
|
|
520
|
-
end
|
|
521
|
-
|
|
522
|
-
context 'when klass is missing' do
|
|
523
|
-
let(:hash) do
|
|
524
|
-
{ where: { name: 'Songs Ohia' } }
|
|
525
|
-
end
|
|
526
|
-
|
|
527
|
-
it 'returns a criteria' do
|
|
528
|
-
expect(criteria).to be_a(Mongoid::Criteria)
|
|
529
|
-
end
|
|
530
|
-
|
|
531
|
-
it 'has klass nil' do
|
|
532
|
-
expect(criteria.klass).to be_nil
|
|
533
|
-
end
|
|
534
|
-
|
|
535
|
-
it 'sets the selector' do
|
|
536
|
-
expect(criteria.selector).to eq({ 'name' => 'Songs Ohia' })
|
|
537
|
-
end
|
|
538
|
-
end
|
|
539
|
-
|
|
540
|
-
context 'with allowed methods' do
|
|
541
|
-
context 'when using multiple query methods' do
|
|
542
|
-
let(:hash) do
|
|
543
|
-
{
|
|
544
|
-
klass: Band,
|
|
545
|
-
where: { active: true },
|
|
546
|
-
limit: 10,
|
|
547
|
-
skip: 5,
|
|
548
|
-
order_by: { name: 1 }
|
|
549
|
-
}
|
|
550
|
-
end
|
|
551
|
-
|
|
552
|
-
it 'applies all methods successfully' do
|
|
553
|
-
expect(criteria.selector).to eq({ 'active' => true })
|
|
554
|
-
expect(criteria.options[:limit]).to eq(10)
|
|
555
|
-
expect(criteria.options[:skip]).to eq(5)
|
|
556
|
-
expect(criteria.options[:sort]).to eq({ 'name' => 1 })
|
|
557
|
-
end
|
|
558
|
-
end
|
|
559
|
-
|
|
560
|
-
context 'when using query selector methods' do
|
|
561
|
-
let(:hash) do
|
|
562
|
-
{
|
|
563
|
-
klass: Band,
|
|
564
|
-
gt: { members: 2 },
|
|
565
|
-
in: { genre: ['rock', 'metal'] }
|
|
566
|
-
}
|
|
567
|
-
end
|
|
568
|
-
|
|
569
|
-
it 'applies selector methods' do
|
|
570
|
-
expect(criteria.selector['members']).to eq({ '$gt' => 2 })
|
|
571
|
-
expect(criteria.selector['genre']).to eq({ '$in' => ['rock', 'metal'] })
|
|
572
|
-
end
|
|
573
|
-
end
|
|
574
|
-
|
|
575
|
-
context 'when using aggregation methods' do
|
|
576
|
-
let(:hash) do
|
|
577
|
-
{
|
|
578
|
-
klass: Band,
|
|
579
|
-
project: { name: 1, members: 1 }
|
|
580
|
-
}
|
|
581
|
-
end
|
|
582
|
-
|
|
583
|
-
it 'applies aggregation methods' do
|
|
584
|
-
expect { criteria }.not_to raise_error
|
|
585
|
-
end
|
|
586
|
-
end
|
|
587
|
-
end
|
|
588
|
-
|
|
589
|
-
context 'with disallowed methods' do
|
|
590
|
-
context 'when attempting to call create' do
|
|
591
|
-
let(:hash) do
|
|
592
|
-
{ klass: Band, create: { name: 'Malicious' } }
|
|
593
|
-
end
|
|
594
|
-
|
|
595
|
-
it 'raises ArgumentError' do
|
|
596
|
-
expect { criteria }.to raise_error(ArgumentError, "Method 'create' is not allowed in to_criteria")
|
|
597
|
-
end
|
|
598
|
-
end
|
|
599
|
-
|
|
600
|
-
context 'when attempting to call create!' do
|
|
601
|
-
let(:hash) do
|
|
602
|
-
{ klass: Band, 'create!': { name: 'Malicious' } }
|
|
603
|
-
end
|
|
604
|
-
|
|
605
|
-
it 'raises ArgumentError' do
|
|
606
|
-
expect { criteria }.to raise_error(ArgumentError, "Method 'create!' is not allowed in to_criteria")
|
|
607
|
-
end
|
|
608
|
-
end
|
|
609
|
-
|
|
610
|
-
context 'when attempting to call build' do
|
|
611
|
-
let(:hash) do
|
|
612
|
-
{ klass: Band, build: { name: 'Malicious' } }
|
|
613
|
-
end
|
|
614
|
-
|
|
615
|
-
it 'raises ArgumentError' do
|
|
616
|
-
expect { criteria }.to raise_error(ArgumentError, "Method 'build' is not allowed in to_criteria")
|
|
617
|
-
end
|
|
618
|
-
end
|
|
619
|
-
|
|
620
|
-
context 'when attempting to call find' do
|
|
621
|
-
let(:hash) do
|
|
622
|
-
{ klass: Band, find: 'some_id' }
|
|
623
|
-
end
|
|
624
|
-
|
|
625
|
-
it 'raises ArgumentError' do
|
|
626
|
-
expect { criteria }.to raise_error(ArgumentError, "Method 'find' is not allowed in to_criteria")
|
|
627
|
-
end
|
|
628
|
-
end
|
|
629
|
-
|
|
630
|
-
context 'when attempting to call execute_or_raise' do
|
|
631
|
-
let(:hash) do
|
|
632
|
-
{ klass: Band, execute_or_raise: ['id1', 'id2'] }
|
|
633
|
-
end
|
|
634
|
-
|
|
635
|
-
it 'raises ArgumentError' do
|
|
636
|
-
expect { criteria }.to raise_error(ArgumentError, "Method 'execute_or_raise' is not allowed in to_criteria")
|
|
637
|
-
end
|
|
638
|
-
end
|
|
639
|
-
|
|
640
|
-
context 'when attempting to call new' do
|
|
641
|
-
let(:hash) do
|
|
642
|
-
{ klass: Band, new: { name: 'Test' } }
|
|
643
|
-
end
|
|
644
|
-
|
|
645
|
-
it 'raises ArgumentError' do
|
|
646
|
-
expect { criteria }.to raise_error(ArgumentError, "Method 'new' is not allowed in to_criteria")
|
|
647
|
-
end
|
|
648
|
-
end
|
|
649
|
-
|
|
650
|
-
context 'when allowed method is combined with disallowed method' do
|
|
651
|
-
let(:hash) do
|
|
652
|
-
{
|
|
653
|
-
klass: Band,
|
|
654
|
-
where: { active: true },
|
|
655
|
-
create: { name: 'Malicious' }
|
|
656
|
-
}
|
|
657
|
-
end
|
|
658
|
-
|
|
659
|
-
it 'raises ArgumentError before executing any methods' do
|
|
660
|
-
expect { criteria }.to raise_error(ArgumentError, "Method 'create' is not allowed in to_criteria")
|
|
661
|
-
end
|
|
662
|
-
end
|
|
663
|
-
end
|
|
664
|
-
|
|
665
|
-
context 'security validation' do
|
|
666
|
-
# This test ensures that ALL public methods not in the allowlist are blocked
|
|
667
|
-
it 'blocks all dangerous public methods' do
|
|
668
|
-
dangerous_methods = %i[
|
|
669
|
-
build create create! new
|
|
670
|
-
find find_or_create_by find_or_create_by! find_or_initialize_by
|
|
671
|
-
first_or_create first_or_create! first_or_initialize
|
|
672
|
-
execute_or_raise multiple_from_db for_ids
|
|
673
|
-
documents= inclusions= scoping_options=
|
|
674
|
-
initialize freeze as_json
|
|
675
|
-
]
|
|
676
|
-
|
|
677
|
-
dangerous_methods.each do |method|
|
|
678
|
-
hash = { klass: Band, method => 'arg' }
|
|
679
|
-
expect { hash.to_criteria }.to raise_error(
|
|
680
|
-
ArgumentError,
|
|
681
|
-
"Method '#{method}' is not allowed in to_criteria"
|
|
682
|
-
), "Expected method '#{method}' to be blocked but it was allowed"
|
|
683
|
-
end
|
|
684
|
-
end
|
|
685
|
-
|
|
686
|
-
it 'blocks dangerous inherited methods from Object' do
|
|
687
|
-
# Critical security test: block send, instance_eval, etc.
|
|
688
|
-
inherited_dangerous = %i[
|
|
689
|
-
send __send__ instance_eval instance_exec
|
|
690
|
-
instance_variable_set method
|
|
691
|
-
]
|
|
692
|
-
|
|
693
|
-
inherited_dangerous.each do |method|
|
|
694
|
-
hash = { klass: Band, method => 'arg' }
|
|
695
|
-
expect { hash.to_criteria }.to raise_error(
|
|
696
|
-
ArgumentError,
|
|
697
|
-
"Method '#{method}' is not allowed in to_criteria"
|
|
698
|
-
), "Expected inherited method '#{method}' to be blocked"
|
|
699
|
-
end
|
|
700
|
-
end
|
|
701
|
-
|
|
702
|
-
it 'blocks Enumerable execution methods' do
|
|
703
|
-
# to_criteria should build queries, not execute them
|
|
704
|
-
enumerable_methods = %i[each map select count sum]
|
|
705
|
-
|
|
706
|
-
enumerable_methods.each do |method|
|
|
707
|
-
hash = { klass: Band, method => 'arg' }
|
|
708
|
-
expect { hash.to_criteria }.to raise_error(
|
|
709
|
-
ArgumentError,
|
|
710
|
-
"Method '#{method}' is not allowed in to_criteria"
|
|
711
|
-
), "Expected Enumerable method '#{method}' to be blocked"
|
|
712
|
-
end
|
|
713
|
-
end
|
|
714
|
-
|
|
715
|
-
it 'allows all whitelisted methods' do
|
|
716
|
-
# Sample of allowed methods from each category
|
|
717
|
-
allowed_sample = {
|
|
718
|
-
where: { name: 'Test' }, # Query selector
|
|
719
|
-
limit: 10, # Query option
|
|
720
|
-
skip: 5, # Query option
|
|
721
|
-
gt: { age: 18 }, # Query selector
|
|
722
|
-
in: { status: ['active'] }, # Query selector
|
|
723
|
-
ascending: :name, # Sorting
|
|
724
|
-
includes: :notes, # Eager loading
|
|
725
|
-
merge: { klass: Band }, # Merge
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
allowed_sample.each do |method, args|
|
|
729
|
-
hash = { klass: Band, method => args }
|
|
730
|
-
expect { hash.to_criteria }.not_to raise_error,
|
|
731
|
-
"Expected method '#{method}' to be allowed but it was blocked"
|
|
732
|
-
end
|
|
733
|
-
end
|
|
734
|
-
end
|
|
735
|
-
end
|
|
736
500
|
end
|
|
@@ -50,14 +50,7 @@ describe Mongoid::Extensions::Time do
|
|
|
50
50
|
|
|
51
51
|
context "when using the ActiveSupport time zone" do
|
|
52
52
|
config_override :use_activesupport_time_zone, true
|
|
53
|
-
|
|
54
|
-
before do
|
|
55
|
-
Time.zone = "Stockholm"
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
after do
|
|
59
|
-
Time.zone = nil
|
|
60
|
-
end
|
|
53
|
+
time_zone_override "Stockholm"
|
|
61
54
|
|
|
62
55
|
context "when demongoizing a Time" do
|
|
63
56
|
|
|
@@ -123,19 +116,12 @@ describe Mongoid::Extensions::Time do
|
|
|
123
116
|
|
|
124
117
|
context "when using the ActiveSupport time zone" do
|
|
125
118
|
config_override :use_activesupport_time_zone, true
|
|
119
|
+
time_zone_override "Stockholm"
|
|
126
120
|
|
|
127
121
|
let(:time) do
|
|
128
122
|
Time.utc(2010, 11, 19, 0, 30)
|
|
129
123
|
end
|
|
130
124
|
|
|
131
|
-
before do
|
|
132
|
-
Time.zone = "Stockholm"
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
after do
|
|
136
|
-
Time.zone = nil
|
|
137
|
-
end
|
|
138
|
-
|
|
139
125
|
it "returns utc" do
|
|
140
126
|
expect(Time.demongoize(time)).to eq(
|
|
141
127
|
ActiveSupport::TimeZone['UTC'].local(2010, 11, 19, 0, 30)
|
|
@@ -855,20 +841,13 @@ describe Mongoid::Extensions::Time do
|
|
|
855
841
|
|
|
856
842
|
context "when using the ActiveSupport time zone" do
|
|
857
843
|
config_override :use_activesupport_time_zone, true
|
|
844
|
+
# if this is actually your time zone, the following tests are useless
|
|
845
|
+
time_zone_override "Stockholm"
|
|
858
846
|
|
|
859
847
|
let(:datetime) do
|
|
860
848
|
DateTime.new(2010, 11, 19)
|
|
861
849
|
end
|
|
862
850
|
|
|
863
|
-
before do
|
|
864
|
-
# if this is actually your time zone, the following tests are useless
|
|
865
|
-
Time.zone = "Stockholm"
|
|
866
|
-
end
|
|
867
|
-
|
|
868
|
-
after do
|
|
869
|
-
Time.zone = nil
|
|
870
|
-
end
|
|
871
|
-
|
|
872
851
|
it "assumes the given time is local" do
|
|
873
852
|
expect(Time.mongoize(datetime)).to eq(
|
|
874
853
|
Time.utc(2010, 11, 19)
|
|
@@ -945,20 +924,13 @@ describe Mongoid::Extensions::Time do
|
|
|
945
924
|
|
|
946
925
|
context "when using the ActiveSupport time zone" do
|
|
947
926
|
config_override :use_activesupport_time_zone, true
|
|
927
|
+
# if this is actually your time zone, the following tests are useless
|
|
928
|
+
time_zone_override "Stockholm"
|
|
948
929
|
|
|
949
930
|
let(:date) do
|
|
950
931
|
Date.new(2010, 11, 19)
|
|
951
932
|
end
|
|
952
933
|
|
|
953
|
-
before do
|
|
954
|
-
# if this is actually your time zone, the following tests are useless
|
|
955
|
-
Time.zone = "Stockholm"
|
|
956
|
-
end
|
|
957
|
-
|
|
958
|
-
after do
|
|
959
|
-
Time.zone = nil
|
|
960
|
-
end
|
|
961
|
-
|
|
962
934
|
it "assumes the given time is local" do
|
|
963
935
|
expect(Time.mongoize(date)).to eq(Time.utc(2010, 11, 18, 23))
|
|
964
936
|
end
|
|
@@ -977,15 +949,8 @@ describe Mongoid::Extensions::Time do
|
|
|
977
949
|
|
|
978
950
|
context "when using the ActiveSupport time zone" do
|
|
979
951
|
config_override :use_activesupport_time_zone, true
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
# if this is actually your time zone, the following tests are useless
|
|
983
|
-
Time.zone = "Stockholm"
|
|
984
|
-
end
|
|
985
|
-
|
|
986
|
-
after do
|
|
987
|
-
Time.zone = nil
|
|
988
|
-
end
|
|
952
|
+
# if this is actually your time zone, the following tests are useless
|
|
953
|
+
time_zone_override "Stockholm"
|
|
989
954
|
|
|
990
955
|
it "assumes the given time is local" do
|
|
991
956
|
expect(Time.mongoize(array)).to eq(
|
|
@@ -50,14 +50,7 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
|
50
50
|
|
|
51
51
|
context "when using the ActiveSupport time zone" do
|
|
52
52
|
config_override :use_activesupport_time_zone, true
|
|
53
|
-
|
|
54
|
-
before do
|
|
55
|
-
Time.zone = "Stockholm"
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
after do
|
|
59
|
-
Time.zone = nil
|
|
60
|
-
end
|
|
53
|
+
time_zone_override "Stockholm"
|
|
61
54
|
|
|
62
55
|
it "returns an ActiveSupport::TimeWithZone" do
|
|
63
56
|
expect(ActiveSupport::TimeWithZone.demongoize(time).class).to eq(ActiveSupport::TimeWithZone)
|
|
@@ -113,19 +106,12 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
|
113
106
|
|
|
114
107
|
context "when using the ActiveSupport time zone" do
|
|
115
108
|
config_override :use_activesupport_time_zone, true
|
|
109
|
+
time_zone_override "Stockholm"
|
|
116
110
|
|
|
117
111
|
let(:time) do
|
|
118
112
|
Time.utc(2010, 11, 19, 0, 30)
|
|
119
113
|
end
|
|
120
114
|
|
|
121
|
-
before do
|
|
122
|
-
Time.zone = "Stockholm"
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
after do
|
|
126
|
-
Time.zone = nil
|
|
127
|
-
end
|
|
128
|
-
|
|
129
115
|
it "returns utc" do
|
|
130
116
|
expect(ActiveSupport::TimeWithZone.demongoize(time)).to eq(
|
|
131
117
|
ActiveSupport::TimeZone['UTC'].local(2010, 11, 19, 0, 30)
|
|
@@ -203,15 +189,8 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
|
203
189
|
|
|
204
190
|
context "when using the ActiveSupport time zone" do
|
|
205
191
|
config_override :use_activesupport_time_zone, true
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
# if this is actually your time zone, the following tests are useless
|
|
209
|
-
Time.zone = "Stockholm"
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
after do
|
|
213
|
-
Time.zone = nil
|
|
214
|
-
end
|
|
192
|
+
# if this is actually your time zone, the following tests are useless
|
|
193
|
+
time_zone_override "Stockholm"
|
|
215
194
|
|
|
216
195
|
context "when the local time is not observing daylight saving" do
|
|
217
196
|
|
|
@@ -247,20 +226,12 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
|
247
226
|
|
|
248
227
|
context "when using the ActiveSupport time zone" do
|
|
249
228
|
config_override :use_activesupport_time_zone, true
|
|
229
|
+
time_zone_override "Stockholm"
|
|
250
230
|
|
|
251
231
|
let(:datetime) do
|
|
252
232
|
DateTime.new(2010, 11, 19)
|
|
253
233
|
end
|
|
254
234
|
|
|
255
|
-
before do
|
|
256
|
-
# if this is actually your time zone, the following tests are useless
|
|
257
|
-
Time.zone = "Stockholm"
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
after do
|
|
261
|
-
Time.zone = nil
|
|
262
|
-
end
|
|
263
|
-
|
|
264
235
|
it "assumes the given time is local" do
|
|
265
236
|
expect(ActiveSupport::TimeWithZone.mongoize(datetime)).to eq(
|
|
266
237
|
Time.utc(2010, 11, 19)
|
|
@@ -317,20 +288,12 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
|
317
288
|
|
|
318
289
|
context "when using the ActiveSupport time zone" do
|
|
319
290
|
config_override :use_activesupport_time_zone, true
|
|
291
|
+
time_zone_override "Stockholm"
|
|
320
292
|
|
|
321
293
|
let(:date) do
|
|
322
294
|
Date.new(2010, 11, 19)
|
|
323
295
|
end
|
|
324
296
|
|
|
325
|
-
before do
|
|
326
|
-
# if this is actually your time zone, the following tests are useless
|
|
327
|
-
Time.zone = "Stockholm"
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
after do
|
|
331
|
-
Time.zone = nil
|
|
332
|
-
end
|
|
333
|
-
|
|
334
297
|
it "assumes the given time is local" do
|
|
335
298
|
expect(ActiveSupport::TimeWithZone.mongoize(date)).to eq(Time.utc(2010, 11, 18, 23))
|
|
336
299
|
end
|
|
@@ -349,15 +312,7 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
|
349
312
|
|
|
350
313
|
context "when using the ActiveSupport time zone" do
|
|
351
314
|
config_override :use_activesupport_time_zone, true
|
|
352
|
-
|
|
353
|
-
before do
|
|
354
|
-
# if this is actually your time zone, the following tests are useless
|
|
355
|
-
Time.zone = "Stockholm"
|
|
356
|
-
end
|
|
357
|
-
|
|
358
|
-
after do
|
|
359
|
-
Time.zone = nil
|
|
360
|
-
end
|
|
315
|
+
time_zone_override "Stockholm"
|
|
361
316
|
|
|
362
317
|
it "assumes the given time is local" do
|
|
363
318
|
expect(ActiveSupport::TimeWithZone.mongoize(array)).to eq(
|
|
@@ -81,16 +81,12 @@ describe Mongoid::Fields::Localized do
|
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
context "when a locale is provided" do
|
|
84
|
+
with_default_i18n_configs
|
|
84
85
|
|
|
85
86
|
before do
|
|
86
|
-
I18n.enforce_available_locales = false
|
|
87
87
|
::I18n.locale = :de
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
after do
|
|
91
|
-
::I18n.locale = :en
|
|
92
|
-
end
|
|
93
|
-
|
|
94
90
|
context "when the value exists" do
|
|
95
91
|
|
|
96
92
|
let(:value) do
|
|
@@ -128,6 +124,7 @@ describe Mongoid::Fields::Localized do
|
|
|
128
124
|
context "when the value does not exist" do
|
|
129
125
|
|
|
130
126
|
context "when not using fallbacks" do
|
|
127
|
+
require_no_fallbacks
|
|
131
128
|
|
|
132
129
|
let(:value) do
|
|
133
130
|
field.demongoize({ "en" => "testing" })
|
|
@@ -139,8 +136,7 @@ describe Mongoid::Fields::Localized do
|
|
|
139
136
|
end
|
|
140
137
|
|
|
141
138
|
context "when using fallbacks" do
|
|
142
|
-
|
|
143
|
-
with_i18n_fallbacks
|
|
139
|
+
require_fallbacks
|
|
144
140
|
|
|
145
141
|
context "when fallbacks are defined" do
|
|
146
142
|
|
|
@@ -271,15 +267,12 @@ describe Mongoid::Fields::Localized do
|
|
|
271
267
|
end
|
|
272
268
|
|
|
273
269
|
context "when a locale is provided" do
|
|
270
|
+
with_default_i18n_configs
|
|
274
271
|
|
|
275
272
|
before do
|
|
276
273
|
::I18n.locale = :de
|
|
277
274
|
end
|
|
278
275
|
|
|
279
|
-
after do
|
|
280
|
-
::I18n.locale = :en
|
|
281
|
-
end
|
|
282
|
-
|
|
283
276
|
context "when the value exists" do
|
|
284
277
|
|
|
285
278
|
let(:value) do
|
|
@@ -305,10 +298,10 @@ describe Mongoid::Fields::Localized do
|
|
|
305
298
|
end
|
|
306
299
|
|
|
307
300
|
context "when using fallbacks" do
|
|
308
|
-
|
|
309
|
-
with_i18n_fallbacks
|
|
301
|
+
require_fallbacks
|
|
310
302
|
|
|
311
303
|
context "when fallbacks are defined" do
|
|
304
|
+
with_default_i18n_configs
|
|
312
305
|
|
|
313
306
|
before do
|
|
314
307
|
::I18n.fallbacks[:de] = [ :de, :en, :es ]
|
|
@@ -367,6 +360,7 @@ describe Mongoid::Fields::Localized do
|
|
|
367
360
|
end
|
|
368
361
|
|
|
369
362
|
context "when no fallbacks are defined" do
|
|
363
|
+
with_default_i18n_configs
|
|
370
364
|
|
|
371
365
|
before do
|
|
372
366
|
::I18n.fallbacks[:de] = [ :de ]
|
|
@@ -406,15 +400,12 @@ describe Mongoid::Fields::Localized do
|
|
|
406
400
|
end
|
|
407
401
|
|
|
408
402
|
context "when a locale is provided" do
|
|
403
|
+
with_default_i18n_configs
|
|
409
404
|
|
|
410
405
|
before do
|
|
411
406
|
::I18n.locale = :de
|
|
412
407
|
end
|
|
413
408
|
|
|
414
|
-
after do
|
|
415
|
-
::I18n.locale = :en
|
|
416
|
-
end
|
|
417
|
-
|
|
418
409
|
let(:value) do
|
|
419
410
|
field.mongoize("This is a test")
|
|
420
411
|
end
|
|
@@ -443,15 +434,12 @@ describe Mongoid::Fields::Localized do
|
|
|
443
434
|
end
|
|
444
435
|
|
|
445
436
|
context "when a locale is provided" do
|
|
437
|
+
with_default_i18n_configs
|
|
446
438
|
|
|
447
439
|
before do
|
|
448
440
|
::I18n.locale = :de
|
|
449
441
|
end
|
|
450
442
|
|
|
451
|
-
after do
|
|
452
|
-
::I18n.locale = :en
|
|
453
|
-
end
|
|
454
|
-
|
|
455
443
|
let(:value) do
|
|
456
444
|
field.mongoize("100")
|
|
457
445
|
end
|
|
@@ -462,16 +450,12 @@ describe Mongoid::Fields::Localized do
|
|
|
462
450
|
end
|
|
463
451
|
|
|
464
452
|
context 'when the type is Boolean' do
|
|
453
|
+
with_default_i18n_configs
|
|
465
454
|
|
|
466
455
|
before do
|
|
467
|
-
I18n.enforce_available_locales = false
|
|
468
456
|
::I18n.locale = :de
|
|
469
457
|
end
|
|
470
458
|
|
|
471
|
-
after do
|
|
472
|
-
::I18n.locale = :en
|
|
473
|
-
end
|
|
474
|
-
|
|
475
459
|
context "when the value is false" do
|
|
476
460
|
|
|
477
461
|
let(:field) do
|
|
@@ -503,12 +487,12 @@ describe Mongoid::Fields::Localized do
|
|
|
503
487
|
end
|
|
504
488
|
|
|
505
489
|
context "when fallbacks are defined" do
|
|
506
|
-
|
|
507
|
-
with_i18n_fallbacks
|
|
490
|
+
require_fallbacks
|
|
508
491
|
|
|
509
492
|
context "when the lookup does not need to use fallbacks" do
|
|
510
493
|
|
|
511
494
|
context "when the value is false" do
|
|
495
|
+
with_default_i18n_configs
|
|
512
496
|
|
|
513
497
|
before do
|
|
514
498
|
::I18n.fallbacks[:de] = [:en, :es]
|
|
@@ -528,6 +512,7 @@ describe Mongoid::Fields::Localized do
|
|
|
528
512
|
end
|
|
529
513
|
|
|
530
514
|
context "when the value is true" do
|
|
515
|
+
with_default_i18n_configs
|
|
531
516
|
|
|
532
517
|
before do
|
|
533
518
|
::I18n.fallbacks[:de] = [:en, :es]
|
|
@@ -550,4 +535,37 @@ describe Mongoid::Fields::Localized do
|
|
|
550
535
|
end
|
|
551
536
|
end
|
|
552
537
|
end
|
|
538
|
+
|
|
539
|
+
describe "localize: :present" do
|
|
540
|
+
|
|
541
|
+
let(:field) do
|
|
542
|
+
described_class.new(:description, localize: :present, type: String)
|
|
543
|
+
end
|
|
544
|
+
|
|
545
|
+
context "when setting the localize to present" do
|
|
546
|
+
|
|
547
|
+
it "is localized?" do
|
|
548
|
+
expect(field.localized?).to be true
|
|
549
|
+
end
|
|
550
|
+
|
|
551
|
+
it "is localize_present?" do
|
|
552
|
+
expect(field.localize_present?).to be true
|
|
553
|
+
end
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
context "when localize is not localize_present" do
|
|
557
|
+
|
|
558
|
+
let(:field) do
|
|
559
|
+
described_class.new(:description, localize: true, type: String)
|
|
560
|
+
end
|
|
561
|
+
|
|
562
|
+
it "is localized?" do
|
|
563
|
+
expect(field.localized?).to be true
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
it "is not localize_present?" do
|
|
567
|
+
expect(field.localize_present?).to be false
|
|
568
|
+
end
|
|
569
|
+
end
|
|
570
|
+
end
|
|
553
571
|
end
|