mongoid 8.0.5 → 8.1.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/CHANGELOG.md +3 -3
- data/README.md +3 -3
- data/Rakefile +0 -25
- data/lib/config/locales/en.yml +46 -14
- data/lib/mongoid/association/accessors.rb +2 -2
- data/lib/mongoid/association/builders.rb +1 -1
- 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 +1 -1
- 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 +2 -2
- data/lib/mongoid/association/referenced/has_many/proxy.rb +3 -3
- data/lib/mongoid/association/reflections.rb +2 -2
- data/lib/mongoid/atomic.rb +0 -7
- data/lib/mongoid/attributes/dynamic.rb +1 -1
- data/lib/mongoid/attributes/nested.rb +2 -2
- 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/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/validators/async_query_executor.rb +24 -0
- data/lib/mongoid/config/validators.rb +1 -0
- data/lib/mongoid/config.rb +101 -0
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +233 -33
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +373 -113
- 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/key.rb +1 -1
- data/lib/mongoid/criteria/queryable/mergeable.rb +1 -1
- data/lib/mongoid/criteria/queryable/optional.rb +8 -8
- data/lib/mongoid/criteria/queryable/selectable.rb +43 -12
- data/lib/mongoid/criteria.rb +6 -5
- data/lib/mongoid/deprecable.rb +1 -1
- 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 -1
- 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 +69 -13
- data/lib/mongoid/findable.rb +27 -3
- data/lib/mongoid/interceptable.rb +7 -6
- data/lib/mongoid/matcher/eq_impl.rb +1 -1
- data/lib/mongoid/matcher/type.rb +1 -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/utils.rb +22 -0
- data/lib/mongoid/validatable/macros.rb +5 -5
- data/lib/mongoid/validatable.rb +4 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +17 -1
- data/lib/mongoid.rb +16 -3
- data/spec/integration/app_spec.rb +2 -2
- data/spec/integration/callbacks_models.rb +37 -0
- data/spec/integration/callbacks_spec.rb +134 -0
- data/spec/integration/discriminator_key_spec.rb +4 -5
- data/spec/integration/i18n_fallbacks_spec.rb +3 -2
- 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_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 +5 -27
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +9 -50
- data/spec/mongoid/association/syncable_spec.rb +1 -1
- data/spec/mongoid/attributes_spec.rb +3 -6
- data/spec/mongoid/changeable_spec.rb +299 -24
- 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 -18
- data/spec/mongoid/contextual/memory_spec.rb +332 -76
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
- data/spec/mongoid/contextual/mongo_spec.rb +995 -36
- data/spec/mongoid/contextual/none_spec.rb +49 -2
- data/spec/mongoid/copyable_spec.rb +3 -11
- 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 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selector_spec.rb +1 -1
- data/spec/mongoid/criteria_projection_spec.rb +1 -4
- data/spec/mongoid/criteria_spec.rb +5 -9
- data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
- 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 -34
- data/spec/mongoid/findable_spec.rb +391 -34
- data/spec/mongoid/indexable_spec.rb +16 -10
- data/spec/mongoid/interceptable_spec.rb +15 -3
- 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 +9 -30
- 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_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/uniqueness_spec.rb +2 -3
- data/spec/mongoid_spec.rb +36 -10
- data/spec/shared/lib/mrss/docker_runner.rb +7 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +15 -5
- data/spec/shared/lib/mrss/lite_constraints.rb +10 -2
- data/spec/shared/lib/mrss/server_version_registry.rb +16 -23
- data/spec/shared/lib/mrss/utils.rb +28 -6
- data/spec/shared/share/Dockerfile.erb +36 -40
- data/spec/shared/shlib/server.sh +32 -8
- data/spec/shared/shlib/set_env.sh +4 -4
- data/spec/spec_helper.rb +5 -0
- 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/book.rb +1 -0
- data/spec/support/models/building.rb +2 -0
- data/spec/support/models/cover.rb +10 -0
- data/spec/support/models/product.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +686 -650
- metadata.gz.sig +0 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -60
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -60
@@ -89,7 +89,7 @@ describe Mongoid::Touchable do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
shared_examples 'updates the parent when :touch is
|
92
|
+
shared_examples 'updates the parent when :touch is false' do
|
93
93
|
it 'does not update updated_at on parent' do
|
94
94
|
entrance
|
95
95
|
update_time
|
@@ -130,7 +130,7 @@ describe Mongoid::Touchable do
|
|
130
130
|
|
131
131
|
include_examples 'updates the child'
|
132
132
|
include_examples 'updates the parent when :touch is true'
|
133
|
-
include_examples 'updates the parent when :touch is
|
133
|
+
include_examples 'updates the parent when :touch is false'
|
134
134
|
|
135
135
|
context 'when also updating an additional field' do
|
136
136
|
it 'persists the update to the additional field' do
|
@@ -587,7 +587,7 @@ describe Mongoid::Touchable do
|
|
587
587
|
|
588
588
|
context "when the touch option is true" do
|
589
589
|
|
590
|
-
shared_examples "updates the updated_at" do
|
590
|
+
shared_examples "updates the parent's updated_at" do
|
591
591
|
|
592
592
|
let!(:start_time) { Timecop.freeze(Time.at(Time.now.to_i)) }
|
593
593
|
|
@@ -624,19 +624,58 @@ describe Mongoid::Touchable do
|
|
624
624
|
end
|
625
625
|
end
|
626
626
|
|
627
|
+
shared_examples "updates the child's updated_at" do
|
628
|
+
|
629
|
+
let!(:start_time) { Timecop.freeze(Time.at(Time.now.to_i)) }
|
630
|
+
|
631
|
+
let(:update_time) do
|
632
|
+
Timecop.freeze(Time.at(Time.now.to_i) + 2)
|
633
|
+
end
|
634
|
+
|
635
|
+
after do
|
636
|
+
Timecop.return
|
637
|
+
end
|
638
|
+
|
639
|
+
let(:building) do
|
640
|
+
parent_cls.create!
|
641
|
+
end
|
642
|
+
|
643
|
+
let(:floor) do
|
644
|
+
building.floors.create!
|
645
|
+
end
|
646
|
+
|
647
|
+
before do
|
648
|
+
floor
|
649
|
+
update_time
|
650
|
+
floor.level = 9
|
651
|
+
floor.send(meth)
|
652
|
+
end
|
653
|
+
|
654
|
+
it "the parent is not nil" do
|
655
|
+
expect(floor.building).to_not be nil
|
656
|
+
end
|
657
|
+
|
658
|
+
it "updates the child's timestamp" do
|
659
|
+
floor.updated_at.should == update_time
|
660
|
+
floor.reload.updated_at.should == update_time
|
661
|
+
end
|
662
|
+
end
|
663
|
+
|
627
664
|
[ :save!, :destroy, :touch].each do |meth|
|
628
665
|
context "with #{meth} on referenced associations" do
|
629
666
|
let(:parent_cls) { TouchableSpec::Referenced::Building }
|
630
667
|
let(:meth) { meth }
|
631
668
|
|
632
|
-
include_examples "updates the updated_at"
|
669
|
+
include_examples "updates the child's updated_at" unless meth == :destroy
|
670
|
+
include_examples "updates the parent's updated_at"
|
633
671
|
end
|
634
672
|
|
635
673
|
context "with #{meth} on embedded associations" do
|
636
674
|
let(:parent_cls) { TouchableSpec::Embedded::Building }
|
637
675
|
let(:meth) { meth }
|
638
676
|
|
639
|
-
include_examples "updates the updated_at"
|
677
|
+
include_examples "updates the child's updated_at" unless meth == :destroy
|
678
|
+
include_examples "updates the parent's updated_at"
|
640
679
|
end
|
641
680
|
end
|
642
681
|
end
|
@@ -701,4 +740,237 @@ describe Mongoid::Touchable do
|
|
701
740
|
end
|
702
741
|
end
|
703
742
|
end
|
743
|
+
|
744
|
+
describe "when saving a document" do
|
745
|
+
|
746
|
+
let!(:start_time) { Timecop.freeze(Time.at(Time.now.to_i)) }
|
747
|
+
|
748
|
+
let(:update_time) do
|
749
|
+
Timecop.freeze(Time.at(Time.now.to_i) + 2)
|
750
|
+
end
|
751
|
+
|
752
|
+
after do
|
753
|
+
Timecop.return
|
754
|
+
end
|
755
|
+
|
756
|
+
context "when only using the root document" do
|
757
|
+
|
758
|
+
shared_examples "timeless is cleared" do
|
759
|
+
it "clears the timeless option" do
|
760
|
+
expect(doc.timeless?).to be false
|
761
|
+
end
|
762
|
+
end
|
763
|
+
|
764
|
+
shared_examples "touches the document" do
|
765
|
+
it "touches the document" do
|
766
|
+
expect(doc.created_at).to eq(start_time)
|
767
|
+
expect(doc.updated_at).to eq(start_time)
|
768
|
+
end
|
769
|
+
end
|
770
|
+
|
771
|
+
shared_examples "updates the document" do
|
772
|
+
it "updates the document" do
|
773
|
+
expect(doc.created_at).to eq(start_time)
|
774
|
+
expect(doc.updated_at).to eq(update_time)
|
775
|
+
end
|
776
|
+
end
|
777
|
+
|
778
|
+
let(:doc) { Dokument.new }
|
779
|
+
|
780
|
+
context "when saving a new document" do
|
781
|
+
|
782
|
+
context "when not passing a touch option" do
|
783
|
+
|
784
|
+
before do
|
785
|
+
doc.save!
|
786
|
+
end
|
787
|
+
|
788
|
+
include_examples "touches the document"
|
789
|
+
include_examples "timeless is cleared"
|
790
|
+
end
|
791
|
+
|
792
|
+
context "when passing touch: true" do
|
793
|
+
|
794
|
+
before do
|
795
|
+
doc.save!(touch: true)
|
796
|
+
end
|
797
|
+
|
798
|
+
include_examples "touches the document"
|
799
|
+
include_examples "timeless is cleared"
|
800
|
+
end
|
801
|
+
|
802
|
+
context "when passing touch: false" do
|
803
|
+
|
804
|
+
before do
|
805
|
+
doc.save!(touch: false)
|
806
|
+
end
|
807
|
+
|
808
|
+
include_examples "touches the document"
|
809
|
+
include_examples "timeless is cleared"
|
810
|
+
end
|
811
|
+
end
|
812
|
+
|
813
|
+
context "when updating a document" do
|
814
|
+
before do
|
815
|
+
doc.save!
|
816
|
+
doc.title = "title"
|
817
|
+
update_time
|
818
|
+
end
|
819
|
+
|
820
|
+
context "when not passing a touch option" do
|
821
|
+
|
822
|
+
before do
|
823
|
+
doc.save!
|
824
|
+
end
|
825
|
+
|
826
|
+
include_examples "updates the document"
|
827
|
+
include_examples "timeless is cleared"
|
828
|
+
end
|
829
|
+
|
830
|
+
context "when passing touch: true" do
|
831
|
+
|
832
|
+
before do
|
833
|
+
doc.save!(touch: true)
|
834
|
+
end
|
835
|
+
|
836
|
+
include_examples "updates the document"
|
837
|
+
include_examples "timeless is cleared"
|
838
|
+
end
|
839
|
+
|
840
|
+
context "when passing touch: false" do
|
841
|
+
|
842
|
+
before do
|
843
|
+
doc.save!(touch: false)
|
844
|
+
end
|
845
|
+
|
846
|
+
include_examples "touches the document"
|
847
|
+
include_examples "timeless is cleared"
|
848
|
+
end
|
849
|
+
end
|
850
|
+
end
|
851
|
+
|
852
|
+
context "when saving embedded associations with cascadable callbacks" do
|
853
|
+
|
854
|
+
shared_examples "timeless is cleared" do
|
855
|
+
it "clears the timeless option" do
|
856
|
+
expect(book.timeless?).to be false
|
857
|
+
expect(book.covers.first.timeless?).to be false
|
858
|
+
end
|
859
|
+
end
|
860
|
+
|
861
|
+
shared_examples "touches the document" do
|
862
|
+
it "touches the document" do
|
863
|
+
expect(book.created_at).to eq(start_time)
|
864
|
+
expect(book.updated_at).to eq(start_time)
|
865
|
+
end
|
866
|
+
end
|
867
|
+
|
868
|
+
shared_examples "updates the document" do
|
869
|
+
it "updates the document" do
|
870
|
+
expect(book.created_at).to eq(start_time)
|
871
|
+
expect(book.updated_at).to eq(update_time)
|
872
|
+
end
|
873
|
+
end
|
874
|
+
|
875
|
+
shared_examples "touches the children" do
|
876
|
+
it "touches the children" do
|
877
|
+
expect(book.covers.first.created_at).to eq(start_time)
|
878
|
+
expect(book.covers.first.updated_at).to eq(start_time)
|
879
|
+
end
|
880
|
+
end
|
881
|
+
|
882
|
+
shared_examples "updates the children" do
|
883
|
+
it "updates the children" do
|
884
|
+
expect(book.covers.first.created_at).to eq(start_time)
|
885
|
+
expect(book.covers.first.updated_at).to eq(update_time)
|
886
|
+
end
|
887
|
+
end
|
888
|
+
|
889
|
+
let(:book) do
|
890
|
+
Book.new(covers: [ cover ])
|
891
|
+
end
|
892
|
+
|
893
|
+
let(:cover) do
|
894
|
+
Cover.new
|
895
|
+
end
|
896
|
+
|
897
|
+
context "when saving a new document" do
|
898
|
+
|
899
|
+
context "when not passing a touch option" do
|
900
|
+
|
901
|
+
before do
|
902
|
+
book.save!
|
903
|
+
end
|
904
|
+
|
905
|
+
include_examples "touches the document"
|
906
|
+
include_examples "touches the children"
|
907
|
+
include_examples "timeless is cleared"
|
908
|
+
end
|
909
|
+
|
910
|
+
context "when passing touch: true" do
|
911
|
+
|
912
|
+
before do
|
913
|
+
book.save!(touch: true)
|
914
|
+
end
|
915
|
+
|
916
|
+
include_examples "touches the document"
|
917
|
+
include_examples "touches the children"
|
918
|
+
include_examples "timeless is cleared"
|
919
|
+
end
|
920
|
+
|
921
|
+
context "when passing touch: false" do
|
922
|
+
|
923
|
+
before do
|
924
|
+
book.save!(touch: false)
|
925
|
+
end
|
926
|
+
|
927
|
+
include_examples "touches the document"
|
928
|
+
include_examples "touches the children"
|
929
|
+
include_examples "timeless is cleared"
|
930
|
+
end
|
931
|
+
end
|
932
|
+
|
933
|
+
context "when updating a document" do
|
934
|
+
before do
|
935
|
+
book.save!
|
936
|
+
book.title = "title"
|
937
|
+
book.covers.first.title = "title"
|
938
|
+
update_time
|
939
|
+
end
|
940
|
+
|
941
|
+
context "when not passing a touch option" do
|
942
|
+
|
943
|
+
before do
|
944
|
+
book.save!
|
945
|
+
end
|
946
|
+
|
947
|
+
include_examples "updates the document"
|
948
|
+
include_examples "updates the children"
|
949
|
+
include_examples "timeless is cleared"
|
950
|
+
end
|
951
|
+
|
952
|
+
context "when passing touch: true" do
|
953
|
+
|
954
|
+
before do
|
955
|
+
book.save!(touch: true)
|
956
|
+
end
|
957
|
+
|
958
|
+
include_examples "updates the document"
|
959
|
+
include_examples "updates the children"
|
960
|
+
include_examples "timeless is cleared"
|
961
|
+
end
|
962
|
+
|
963
|
+
context "when passing touch: false" do
|
964
|
+
|
965
|
+
before do
|
966
|
+
book.save!(touch: false)
|
967
|
+
end
|
968
|
+
|
969
|
+
include_examples "touches the document"
|
970
|
+
include_examples "touches the children"
|
971
|
+
include_examples "timeless is cleared"
|
972
|
+
end
|
973
|
+
end
|
974
|
+
end
|
975
|
+
end
|
704
976
|
end
|
@@ -6,6 +6,8 @@ module TouchableSpec
|
|
6
6
|
include Mongoid::Document
|
7
7
|
include Mongoid::Timestamps
|
8
8
|
|
9
|
+
field :title, type: String
|
10
|
+
|
9
11
|
embeds_many :entrances, class_name: "TouchableSpec::Embedded::Entrance"
|
10
12
|
embeds_many :floors, class_name: "TouchableSpec::Embedded::Floor"
|
11
13
|
end
|
@@ -14,7 +16,7 @@ module TouchableSpec
|
|
14
16
|
include Mongoid::Document
|
15
17
|
include Mongoid::Timestamps
|
16
18
|
|
17
|
-
embedded_in :building, class_name: "TouchableSpec::Embedded::Building"
|
19
|
+
embedded_in :building, touch: false, class_name: "TouchableSpec::Embedded::Building"
|
18
20
|
|
19
21
|
field :last_used_at, type: Time
|
20
22
|
end
|
@@ -531,9 +531,9 @@ describe Mongoid::Traversable do
|
|
531
531
|
end
|
532
532
|
|
533
533
|
context "before class creation" do
|
534
|
-
|
535
|
-
Mongoid.discriminator_key = "test"
|
534
|
+
config_override :discriminator_key, "test"
|
536
535
|
|
536
|
+
before do
|
537
537
|
class PreGlobalDiscriminatorParent
|
538
538
|
include Mongoid::Document
|
539
539
|
end
|
@@ -542,10 +542,6 @@ describe Mongoid::Traversable do
|
|
542
542
|
end
|
543
543
|
end
|
544
544
|
|
545
|
-
after do
|
546
|
-
Mongoid.discriminator_key = "_type"
|
547
|
-
end
|
548
|
-
|
549
545
|
it "creates a field with new discriminator key in the parent" do
|
550
546
|
expect(PreGlobalDiscriminatorParent.fields.keys).to include("test")
|
551
547
|
end
|
@@ -677,9 +673,9 @@ describe Mongoid::Traversable do
|
|
677
673
|
end
|
678
674
|
|
679
675
|
context "before class creation" do
|
680
|
-
|
681
|
-
Mongoid.discriminator_key = :test
|
676
|
+
config_override :discriminator_key, :test
|
682
677
|
|
678
|
+
before do
|
683
679
|
class PreGlobalSymDiscriminatorParent
|
684
680
|
include Mongoid::Document
|
685
681
|
end
|
@@ -688,10 +684,6 @@ describe Mongoid::Traversable do
|
|
688
684
|
end
|
689
685
|
end
|
690
686
|
|
691
|
-
after do
|
692
|
-
Mongoid.discriminator_key = "_type"
|
693
|
-
end
|
694
|
-
|
695
687
|
it "creates a field with new discriminator key as a string in the parent" do
|
696
688
|
expect(PreGlobalSymDiscriminatorParent.fields.keys).to include("test")
|
697
689
|
end
|
@@ -829,8 +821,9 @@ describe Mongoid::Traversable do
|
|
829
821
|
end
|
830
822
|
|
831
823
|
context "when setting a field equal to discriminator key and duplicate_fields_exception is true" do
|
824
|
+
config_override :duplicate_fields_exception, true
|
825
|
+
|
832
826
|
before do
|
833
|
-
Mongoid.duplicate_fields_exception = true
|
834
827
|
|
835
828
|
class DuplicateDiscriminatorKeyParent
|
836
829
|
include Mongoid::Document
|
@@ -841,10 +834,6 @@ describe Mongoid::Traversable do
|
|
841
834
|
end
|
842
835
|
end
|
843
836
|
|
844
|
-
after do
|
845
|
-
Mongoid.duplicate_fields_exception = false
|
846
|
-
end
|
847
|
-
|
848
837
|
it "does not raise an error" do
|
849
838
|
expect do
|
850
839
|
DuplicateDiscriminatorKeyParent.discriminator_key = "dkey"
|
@@ -871,9 +860,10 @@ describe Mongoid::Traversable do
|
|
871
860
|
end
|
872
861
|
|
873
862
|
context "when setting a field equal to global discriminator key and duplicate_fields_exception is true" do
|
863
|
+
config_override :duplicate_fields_exception, true
|
864
|
+
config_override :discriminator_key, "dkey"
|
865
|
+
|
874
866
|
before do
|
875
|
-
Mongoid.duplicate_fields_exception = true
|
876
|
-
Mongoid.discriminator_key = "dkey"
|
877
867
|
|
878
868
|
class GlobalDuplicateDiscriminatorKeyParent
|
879
869
|
include Mongoid::Document
|
@@ -883,11 +873,6 @@ describe Mongoid::Traversable do
|
|
883
873
|
end
|
884
874
|
end
|
885
875
|
|
886
|
-
after do
|
887
|
-
Mongoid.duplicate_fields_exception = false
|
888
|
-
Mongoid.discriminator_key = "_type"
|
889
|
-
end
|
890
|
-
|
891
876
|
it "raises an error" do
|
892
877
|
expect do
|
893
878
|
GlobalDuplicateDiscriminatorKeyParent.class_eval do
|
@@ -2476,11 +2476,10 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
2476
2476
|
describe "i18n" do
|
2477
2477
|
|
2478
2478
|
context 'when using a different locale' do
|
2479
|
-
|
2480
|
-
I18n.with_locale(:fr) { example.run }
|
2481
|
-
end
|
2479
|
+
with_default_i18n_configs
|
2482
2480
|
|
2483
2481
|
before do
|
2482
|
+
I18n.locale = :fr
|
2484
2483
|
# Translation key location is as per rails-i18n gem.
|
2485
2484
|
# See: https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en.yml
|
2486
2485
|
I18n.backend.store_translations(:fr, { errors: { messages: { taken: 'est déjà utilisé(e)' } } })
|
data/spec/mongoid_spec.rb
CHANGED
@@ -13,22 +13,46 @@ describe Mongoid do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
context "when a block is
|
16
|
+
context "when a block is given" do
|
17
|
+
config_override :preload_models, false
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
context "with arity 0" do
|
20
|
+
|
21
|
+
before do
|
22
|
+
Mongoid.configure do
|
23
|
+
config.preload_models = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "sets the values on the config instance" do
|
28
|
+
expect(Mongoid.preload_models).to be true
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
24
|
-
|
25
|
-
|
26
|
-
|
32
|
+
context "with arity 1" do
|
33
|
+
|
34
|
+
before do
|
35
|
+
Mongoid.configure do |config|
|
36
|
+
config.preload_models = true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "sets the values on the config instance" do
|
41
|
+
expect(Mongoid.preload_models).to be true
|
27
42
|
end
|
28
43
|
end
|
29
44
|
|
30
|
-
|
31
|
-
|
45
|
+
context "with arity 2" do
|
46
|
+
|
47
|
+
before do
|
48
|
+
Mongoid.configure do |config, _other|
|
49
|
+
config.preload_models = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "sets the values on the config instance" do
|
54
|
+
expect(Mongoid.preload_models).to be true
|
55
|
+
end
|
32
56
|
end
|
33
57
|
end
|
34
58
|
end
|
@@ -51,8 +75,10 @@ describe Mongoid do
|
|
51
75
|
end
|
52
76
|
|
53
77
|
it "disconnects from all active clients" do
|
78
|
+
pending 'https://jira.mongodb.org/browse/MONGOID-5621'
|
79
|
+
|
54
80
|
clients.each do |client|
|
55
|
-
expect(client).to receive(:
|
81
|
+
expect(client.cluster).to receive(:disconnect!).and_call_original
|
56
82
|
end
|
57
83
|
Mongoid.disconnect_clients
|
58
84
|
end
|
@@ -195,12 +195,15 @@ module Mrss
|
|
195
195
|
'debian81' => 'debian:jessie',
|
196
196
|
'debian92' => 'debian:stretch',
|
197
197
|
'debian10' => 'debian:buster',
|
198
|
+
'debian11' => 'debian:bullseye',
|
198
199
|
'ubuntu1404' => 'ubuntu:trusty',
|
199
200
|
'ubuntu1604' => 'ubuntu:xenial',
|
200
201
|
'ubuntu1804' => 'ubuntu:bionic',
|
201
202
|
'ubuntu2004' => 'ubuntu:focal',
|
203
|
+
'ubuntu2204' => 'ubuntu:jammy',
|
202
204
|
'rhel62' => 'centos:6',
|
203
205
|
'rhel70' => 'centos:7',
|
206
|
+
'rhel80' => 'rockylinux:8',
|
204
207
|
}.freeze
|
205
208
|
|
206
209
|
def base_image
|
@@ -231,6 +234,10 @@ module Mrss
|
|
231
234
|
distro =~ /debian|ubuntu/
|
232
235
|
end
|
233
236
|
|
237
|
+
def ubuntu?
|
238
|
+
distro=~ /ubuntu/
|
239
|
+
end
|
240
|
+
|
234
241
|
def preload?
|
235
242
|
!!@options[:preload]
|
236
243
|
end
|
@@ -84,22 +84,32 @@ module Mrss
|
|
84
84
|
|
85
85
|
# Locates command stated events for the specified command name,
|
86
86
|
# asserts that there is exactly one such event, and returns it.
|
87
|
-
def single_command_started_event(command_name, include_auth: false)
|
87
|
+
def single_command_started_event(command_name, include_auth: false, database_name: nil)
|
88
88
|
events = if include_auth
|
89
89
|
started_events
|
90
90
|
else
|
91
91
|
non_auth_command_started_events
|
92
92
|
end
|
93
|
-
events
|
94
|
-
|
93
|
+
get_one_event(events, command_name, 'started', database_name: database_name)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Locates command succeeded events for the specified command name,
|
97
|
+
# asserts that there is exactly one such event, and returns it.
|
98
|
+
def single_command_succeeded_event(command_name, database_name: nil)
|
99
|
+
get_one_event(succeeded_events, command_name, 'succeeded', database_name: database_name)
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_one_event(events, command_name, kind, database_name: nil)
|
103
|
+
events = events.select do |event|
|
104
|
+
event.command_name == command_name and
|
105
|
+
database_name.nil? || database_name == event.database_name
|
95
106
|
end
|
96
107
|
if events.length != 1
|
97
|
-
raise "Expected a single #{command_name} event but we have #{events.length}"
|
108
|
+
raise "Expected a single '#{command_name}' #{kind} event#{database_name ? " for '#{database_name}'" : ''} but we have #{events.length}"
|
98
109
|
end
|
99
110
|
events.first
|
100
111
|
end
|
101
112
|
|
102
|
-
|
103
113
|
# Get the first succeeded event published for the name, and then delete it.
|
104
114
|
#
|
105
115
|
# @param [ String ] name The event name.
|
@@ -98,8 +98,8 @@ module Mrss
|
|
98
98
|
def min_libmongocrypt_version(version)
|
99
99
|
require_libmongocrypt
|
100
100
|
before(:all) do
|
101
|
-
actual_version =
|
102
|
-
min_version =
|
101
|
+
actual_version = Utils.parse_version(Mongo::Crypt::Binding.mongocrypt_version(nil))
|
102
|
+
min_version = Utils.parse_version(version)
|
103
103
|
unless actual_version >= min_version
|
104
104
|
skip "libmongocrypt version #{min_version} required, but version #{actual_version} is available"
|
105
105
|
end
|
@@ -209,6 +209,14 @@ module Mrss
|
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
212
|
+
def require_no_fallbacks
|
213
|
+
before(:all) do
|
214
|
+
if %w(yes true 1).include?((ENV['TEST_I18N_FALLBACKS'] || '').downcase)
|
215
|
+
skip 'Set TEST_I18N_FALLBACKS=0 environment variable to run these tests'
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
212
220
|
# This is a macro for retrying flaky tests on CI that occasionally fail.
|
213
221
|
# Note that the tests will only be retried on CI.
|
214
222
|
#
|
@@ -24,6 +24,21 @@ module Mrss
|
|
24
24
|
|
25
25
|
attr_reader :desired_version, :arch
|
26
26
|
|
27
|
+
def target_arch
|
28
|
+
# can't use RbConfig::CONFIG["arch"] because JRuby doesn't
|
29
|
+
# return anything meaningful there.
|
30
|
+
#
|
31
|
+
# also, need to use `uname -a` instead of (e.g.) `uname -p`
|
32
|
+
# because debian (at least) does not return anything meaningful
|
33
|
+
# for `uname -p`.
|
34
|
+
uname = `uname -a`.strip
|
35
|
+
@target_arch ||= case uname
|
36
|
+
when /aarch/ then "aarch64"
|
37
|
+
when /x86/ then "x86_64"
|
38
|
+
else raise "unsupported architecture #{uname.inspect}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
27
42
|
def download_url
|
28
43
|
@download_url ||= begin
|
29
44
|
version, version_ok = detect_version(current_catalog)
|
@@ -40,35 +55,13 @@ module Mrss
|
|
40
55
|
end
|
41
56
|
dl = version['downloads'].detect do |dl|
|
42
57
|
dl['archive']['url'].index("enterprise-#{arch}") &&
|
43
|
-
dl['arch'] ==
|
58
|
+
dl['arch'] == target_arch
|
44
59
|
end
|
45
60
|
unless dl
|
46
61
|
raise MissingDownloadUrl, "No download for #{arch} for #{version['version']}"
|
47
62
|
end
|
48
63
|
url = dl['archive']['url']
|
49
64
|
end
|
50
|
-
rescue MissingDownloadUrl
|
51
|
-
if %w(2.6 3.0).include?(desired_version) && arch == 'ubuntu1604'
|
52
|
-
# 2.6 and 3.0 are only available for ubuntu1204 and ubuntu1404.
|
53
|
-
# Those ubuntus have ancient Pythons that don't work due to not
|
54
|
-
# implementing recent TLS protocols.
|
55
|
-
# Because of this we test on ubuntu1604 which has a newer Python.
|
56
|
-
# But we still need to retrieve ubuntu1404-targeting builds.
|
57
|
-
url = self.class.new('3.2', arch).download_url
|
58
|
-
unless url.include?('3.2.')
|
59
|
-
raise 'URL not in expected format'
|
60
|
-
end
|
61
|
-
url = case desired_version
|
62
|
-
when '2.6'
|
63
|
-
url.sub(/\b3\.2\.\d+/, '2.6.12')
|
64
|
-
when '3.0'
|
65
|
-
url.sub(/\b3\.2\.\d+/, '3.0.15')
|
66
|
-
else
|
67
|
-
raise NotImplementedError
|
68
|
-
end.sub('ubuntu1604', 'ubuntu1404')
|
69
|
-
else
|
70
|
-
raise
|
71
|
-
end
|
72
65
|
end
|
73
66
|
|
74
67
|
private
|