mongoid 5.4.1 → 6.1.1
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 +5 -5
- data/README.md +3 -3
- data/lib/config/locales/en.yml +19 -0
- data/lib/mongoid.rb +4 -4
- data/lib/mongoid/atomic.rb +2 -2
- data/lib/mongoid/atomic/modifiers.rb +8 -12
- data/lib/mongoid/attributes.rb +22 -21
- data/lib/mongoid/attributes/readonly.rb +22 -0
- data/lib/mongoid/cacheable.rb +36 -0
- data/lib/mongoid/changeable.rb +36 -0
- data/lib/mongoid/clients.rb +8 -63
- data/lib/mongoid/clients/options.rb +55 -250
- data/lib/mongoid/clients/storage_options.rb +1 -69
- data/lib/mongoid/composable.rb +29 -3
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/atomic.rb +5 -8
- data/lib/mongoid/contextual/map_reduce.rb +0 -4
- data/lib/mongoid/contextual/memory.rb +2 -2
- data/lib/mongoid/contextual/mongo.rb +40 -22
- data/lib/mongoid/contextual/none.rb +12 -0
- data/lib/mongoid/copyable.rb +13 -6
- data/lib/mongoid/criteria.rb +5 -2
- data/lib/mongoid/criteria/marshalable.rb +2 -2
- data/lib/mongoid/criteria/modifiable.rb +17 -1
- data/lib/mongoid/criteria/options.rb +25 -0
- data/lib/mongoid/criteria/queryable.rb +87 -0
- data/lib/mongoid/criteria/queryable/aggregable.rb +120 -0
- data/lib/mongoid/criteria/queryable/extensions.rb +28 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +185 -0
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +37 -0
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/date.rb +63 -0
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +53 -0
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +200 -0
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +86 -0
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +90 -0
- data/lib/mongoid/criteria/queryable/extensions/object.rb +206 -0
- data/lib/mongoid/criteria/queryable/extensions/range.rb +70 -0
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +79 -0
- data/lib/mongoid/criteria/queryable/extensions/set.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/string.rb +137 -0
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +79 -0
- data/lib/mongoid/criteria/queryable/extensions/time.rb +60 -0
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +54 -0
- data/lib/mongoid/criteria/queryable/forwardable.rb +65 -0
- data/lib/mongoid/criteria/queryable/key.rb +103 -0
- data/lib/mongoid/criteria/queryable/macroable.rb +27 -0
- data/lib/mongoid/criteria/queryable/mergeable.rb +271 -0
- data/lib/mongoid/criteria/queryable/optional.rb +429 -0
- data/lib/mongoid/criteria/queryable/options.rb +153 -0
- data/lib/mongoid/criteria/queryable/pipeline.rb +111 -0
- data/lib/mongoid/criteria/queryable/selectable.rb +662 -0
- data/lib/mongoid/criteria/queryable/selector.rb +212 -0
- data/lib/mongoid/criteria/queryable/smash.rb +104 -0
- data/lib/mongoid/document.rb +30 -37
- data/lib/mongoid/errors.rb +2 -0
- data/lib/mongoid/errors/ambiguous_relationship.rb +1 -1
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -1
- data/lib/mongoid/errors/invalid_field.rb +2 -2
- data/lib/mongoid/errors/invalid_persistence_option.rb +29 -0
- data/lib/mongoid/errors/invalid_relation.rb +66 -0
- data/lib/mongoid/evolvable.rb +1 -1
- data/lib/mongoid/extensions.rb +0 -4
- data/lib/mongoid/extensions/big_decimal.rb +17 -8
- data/lib/mongoid/extensions/date.rb +4 -1
- data/lib/mongoid/extensions/decimal128.rb +3 -3
- data/lib/mongoid/extensions/hash.rb +1 -0
- data/lib/mongoid/extensions/string.rb +4 -3
- data/lib/mongoid/extensions/time.rb +4 -1
- data/lib/mongoid/fields/validators/macro.rb +18 -0
- data/lib/mongoid/findable.rb +2 -2
- data/lib/mongoid/indexable.rb +15 -13
- data/lib/mongoid/interceptable.rb +5 -22
- data/lib/mongoid/matchable.rb +13 -7
- data/lib/mongoid/matchable/all.rb +2 -2
- data/lib/mongoid/matchable/and.rb +3 -3
- data/lib/mongoid/matchable/default.rb +2 -2
- data/lib/mongoid/matchable/elem_match.rb +28 -0
- data/lib/mongoid/matchable/exists.rb +2 -2
- data/lib/mongoid/matchable/gt.rb +4 -2
- data/lib/mongoid/matchable/gte.rb +4 -2
- data/lib/mongoid/matchable/in.rb +2 -2
- data/lib/mongoid/matchable/lt.rb +4 -2
- data/lib/mongoid/matchable/lte.rb +4 -2
- data/lib/mongoid/matchable/ne.rb +2 -2
- data/lib/mongoid/matchable/nin.rb +2 -2
- data/lib/mongoid/matchable/or.rb +3 -3
- data/lib/mongoid/matchable/regexp.rb +3 -3
- data/lib/mongoid/matchable/size.rb +2 -2
- data/lib/mongoid/persistable.rb +3 -5
- data/lib/mongoid/persistable/creatable.rb +2 -2
- data/lib/mongoid/persistable/deletable.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +1 -1
- data/lib/mongoid/persistable/updatable.rb +5 -12
- data/lib/mongoid/persistable/upsertable.rb +1 -1
- data/lib/mongoid/persistence_context.rb +215 -0
- data/lib/mongoid/query_cache.rb +3 -6
- data/lib/mongoid/relations/accessors.rb +3 -0
- data/lib/mongoid/relations/auto_save.rb +12 -4
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -4
- data/lib/mongoid/relations/counter_cache.rb +15 -5
- data/lib/mongoid/relations/eager.rb +6 -11
- data/lib/mongoid/relations/eager/base.rb +3 -3
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +2 -2
- data/lib/mongoid/relations/eager/has_many.rb +1 -1
- data/lib/mongoid/relations/embedded/batchable.rb +12 -36
- data/lib/mongoid/relations/embedded/in.rb +13 -1
- data/lib/mongoid/relations/embedded/many.rb +28 -10
- data/lib/mongoid/relations/embedded/one.rb +14 -1
- data/lib/mongoid/relations/macros.rb +9 -1
- data/lib/mongoid/relations/metadata.rb +3 -3
- data/lib/mongoid/relations/options.rb +2 -2
- data/lib/mongoid/relations/proxy.rb +1 -31
- data/lib/mongoid/relations/referenced/in.rb +19 -10
- data/lib/mongoid/relations/referenced/many.rb +23 -17
- data/lib/mongoid/relations/referenced/many_to_many.rb +20 -13
- data/lib/mongoid/relations/referenced/one.rb +15 -1
- data/lib/mongoid/relations/synchronization.rb +11 -11
- data/lib/mongoid/relations/touchable.rb +6 -3
- data/lib/mongoid/reloadable.rb +1 -1
- data/lib/mongoid/serializable.rb +1 -1
- data/lib/mongoid/traversable.rb +1 -1
- data/lib/mongoid/validatable/uniqueness.rb +1 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +14 -3
- data/spec/app/models/album.rb +5 -1
- data/spec/app/models/artist.rb +21 -0
- data/spec/app/models/book.rb +2 -1
- data/spec/app/models/dokument.rb +1 -0
- data/spec/app/models/ordered_post.rb +5 -0
- data/spec/app/models/oscar.rb +1 -2
- data/spec/app/models/page.rb +1 -1
- data/spec/app/models/person.rb +3 -3
- data/spec/app/models/princess.rb +2 -0
- data/spec/app/models/record.rb +1 -0
- data/spec/app/models/subscription.rb +1 -0
- data/spec/app/models/thing.rb +1 -1
- data/spec/config/mongoid.yml +15 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +17 -17
- data/spec/mongoid/atomic_spec.rb +17 -17
- data/spec/mongoid/attributes/nested_spec.rb +14 -14
- data/spec/mongoid/attributes/readonly_spec.rb +87 -44
- data/spec/mongoid/attributes_spec.rb +90 -5
- data/spec/mongoid/cacheable_spec.rb +112 -0
- data/spec/mongoid/changeable_spec.rb +58 -0
- data/spec/mongoid/clients/factory_spec.rb +31 -3
- data/spec/mongoid/clients/options_spec.rb +382 -96
- data/spec/mongoid/clients_spec.rb +243 -101
- data/spec/mongoid/composable_spec.rb +7 -0
- data/spec/mongoid/config_spec.rb +67 -11
- data/spec/mongoid/contextual/atomic_spec.rb +3 -3
- data/spec/mongoid/contextual/mongo_spec.rb +165 -20
- data/spec/mongoid/contextual/none_spec.rb +15 -0
- data/spec/mongoid/copyable_spec.rb +13 -4
- data/spec/mongoid/criteria/modifiable_spec.rb +239 -7
- data/spec/mongoid/criteria/options_spec.rb +29 -0
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +370 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +523 -0
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +59 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +213 -0
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +330 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +405 -0
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +327 -0
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +77 -0
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +108 -0
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +309 -0
- data/spec/mongoid/{extensions/origin → criteria/queryable/extensions}/regexp_raw_spec.rb +2 -2
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +90 -0
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +39 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +302 -0
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +167 -0
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +376 -0
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +347 -0
- data/spec/mongoid/criteria/queryable/forwardable_spec.rb +87 -0
- data/spec/mongoid/criteria/queryable/key_spec.rb +52 -0
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +49 -0
- data/spec/mongoid/criteria/queryable/optional_spec.rb +1799 -0
- data/spec/mongoid/criteria/queryable/options_spec.rb +360 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +200 -0
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +137 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +4174 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +844 -0
- data/spec/mongoid/criteria/queryable/smash_spec.rb +30 -0
- data/spec/mongoid/criteria_spec.rb +152 -21
- data/spec/mongoid/document_spec.rb +37 -88
- data/spec/mongoid/errors/invalid_relation_spec.rb +37 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +6 -3
- data/spec/mongoid/extensions/big_decimal_spec.rb +320 -18
- data/spec/mongoid/extensions/boolean_spec.rb +14 -0
- data/spec/mongoid/extensions/date_spec.rb +2 -6
- data/spec/mongoid/extensions/date_time_spec.rb +2 -6
- data/spec/mongoid/extensions/decimal128_spec.rb +1 -1
- data/spec/mongoid/extensions/float_spec.rb +8 -1
- data/spec/mongoid/extensions/hash_spec.rb +15 -0
- data/spec/mongoid/extensions/integer_spec.rb +8 -1
- data/spec/mongoid/extensions/object_spec.rb +11 -0
- data/spec/mongoid/extensions/string_spec.rb +21 -0
- data/spec/mongoid/extensions/time_spec.rb +2 -6
- data/spec/mongoid/extensions/time_with_zone_spec.rb +2 -6
- data/spec/mongoid/findable_spec.rb +46 -1
- data/spec/mongoid/indexable_spec.rb +15 -3
- data/spec/mongoid/interceptable_spec.rb +68 -10
- data/spec/mongoid/matchable/all_spec.rb +4 -4
- data/spec/mongoid/matchable/and_spec.rb +10 -10
- data/spec/mongoid/matchable/default_spec.rb +12 -12
- data/spec/mongoid/matchable/elem_match_spec.rb +86 -0
- data/spec/mongoid/matchable/exists_spec.rb +5 -5
- data/spec/mongoid/matchable/gt_spec.rb +18 -7
- data/spec/mongoid/matchable/gte_spec.rb +17 -7
- data/spec/mongoid/matchable/in_spec.rb +5 -5
- data/spec/mongoid/matchable/lt_spec.rb +18 -7
- data/spec/mongoid/matchable/lte_spec.rb +18 -7
- data/spec/mongoid/matchable/ne_spec.rb +5 -5
- data/spec/mongoid/matchable/nin_spec.rb +5 -5
- data/spec/mongoid/matchable/or_spec.rb +7 -7
- data/spec/mongoid/matchable/regexp_spec.rb +5 -5
- data/spec/mongoid/matchable/size_spec.rb +3 -3
- data/spec/mongoid/matchable_spec.rb +173 -53
- data/spec/mongoid/persistable/creatable_spec.rb +7 -2
- data/spec/mongoid/persistable/deletable_spec.rb +16 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +6 -2
- data/spec/mongoid/persistable/savable_spec.rb +35 -30
- data/spec/mongoid/persistable/settable_spec.rb +45 -29
- data/spec/mongoid/persistable/updatable_spec.rb +184 -5
- data/spec/mongoid/persistence_context_spec.rb +680 -0
- data/spec/mongoid/positional_spec.rb +10 -10
- data/spec/mongoid/query_cache_spec.rb +89 -0
- data/spec/mongoid/relations/accessors_spec.rb +1 -1
- data/spec/mongoid/relations/auto_save_spec.rb +39 -6
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +4 -4
- data/spec/mongoid/relations/builders_spec.rb +37 -10
- data/spec/mongoid/relations/counter_cache_spec.rb +64 -3
- data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +16 -0
- data/spec/mongoid/relations/eager_spec.rb +40 -0
- data/spec/mongoid/relations/embedded/many_spec.rb +63 -47
- data/spec/mongoid/relations/embedded/one_spec.rb +2 -1
- data/spec/mongoid/relations/macros_spec.rb +395 -7
- data/spec/mongoid/relations/metadata_spec.rb +15 -1
- data/spec/mongoid/relations/proxy_spec.rb +27 -1
- data/spec/mongoid/relations/referenced/in_spec.rb +41 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +13 -25
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +14 -26
- data/spec/mongoid/relations/synchronization_spec.rb +48 -2
- data/spec/mongoid/relations/touchable_spec.rb +40 -0
- data/spec/mongoid/reloadable_spec.rb +51 -0
- data/spec/mongoid/serializable_spec.rb +0 -50
- data/spec/mongoid/validatable/presence_spec.rb +1 -1
- data/spec/mongoid/validatable/uniqueness_spec.rb +18 -9
- data/spec/mongoid/validatable_spec.rb +16 -0
- data/spec/spec_helper.rb +20 -11
- metadata +524 -469
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongoid/clients/thread_options.rb +0 -19
- data/lib/mongoid/extensions/origin/regexp_raw.rb +0 -43
- metadata.gz.sig +0 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Criteria::Queryable::Smash do
|
4
|
+
|
5
|
+
let(:smash) do
|
6
|
+
described_class.new(ns: :namespace)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#[]" do
|
10
|
+
|
11
|
+
before do
|
12
|
+
smash.store(:namespace, :default)
|
13
|
+
smash.store(:some_field, 42)
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when accessing aliased field" do
|
17
|
+
|
18
|
+
it "returns value for original field" do
|
19
|
+
expect(smash[:ns]).to eq(:default)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when accessing non-aliased field" do
|
24
|
+
|
25
|
+
it "returns value for the field" do
|
26
|
+
expect(smash[:some_field]).to eq(42)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -412,7 +412,7 @@ describe Mongoid::Criteria do
|
|
412
412
|
end
|
413
413
|
|
414
414
|
let(:criteria) do
|
415
|
-
Band.where(name: "Depeche Mode").asc(:name).includes(:records)
|
415
|
+
Band.where(name: "Depeche Mode").asc(:name).includes(:records).read(mode: :secondary)
|
416
416
|
end
|
417
417
|
|
418
418
|
before do
|
@@ -433,7 +433,7 @@ describe Mongoid::Criteria do
|
|
433
433
|
end
|
434
434
|
|
435
435
|
it "contains equal options" do
|
436
|
-
expect(clone.options).to eq({ sort: { "name" => 1 }})
|
436
|
+
expect(clone.options).to eq({ sort: { "name" => 1 }, read: { mode: :secondary } })
|
437
437
|
end
|
438
438
|
|
439
439
|
it "clones the options" do
|
@@ -467,6 +467,10 @@ describe Mongoid::Criteria do
|
|
467
467
|
it "sets the context to nil" do
|
468
468
|
expect(clone.instance_variable_get(:@context)).to be_nil
|
469
469
|
end
|
470
|
+
|
471
|
+
it 'does not convert the option keys to string from symbols' do
|
472
|
+
expect(clone.options[:read][:mode]).to eq(:secondary)
|
473
|
+
end
|
470
474
|
end
|
471
475
|
end
|
472
476
|
|
@@ -590,7 +594,8 @@ describe Mongoid::Criteria do
|
|
590
594
|
|
591
595
|
let!(:match) do
|
592
596
|
Band.create(name: "Depeche Mode").tap do |band|
|
593
|
-
band.records
|
597
|
+
r = band.records
|
598
|
+
r.create(name: "101")
|
594
599
|
end
|
595
600
|
end
|
596
601
|
|
@@ -2803,6 +2808,93 @@ describe Mongoid::Criteria do
|
|
2803
2808
|
end
|
2804
2809
|
end
|
2805
2810
|
end
|
2811
|
+
|
2812
|
+
context 'when the field is localized' do
|
2813
|
+
|
2814
|
+
before do
|
2815
|
+
I18n.locale = :en
|
2816
|
+
d = Dictionary.create(description: 'english-text')
|
2817
|
+
I18n.locale = :de
|
2818
|
+
d.description = 'deutsch-text'
|
2819
|
+
d.save
|
2820
|
+
end
|
2821
|
+
|
2822
|
+
after do
|
2823
|
+
I18n.locale = :en
|
2824
|
+
end
|
2825
|
+
|
2826
|
+
context 'when entire field is included' do
|
2827
|
+
|
2828
|
+
let(:dictionary) do
|
2829
|
+
Dictionary.only(:description).first
|
2830
|
+
|
2831
|
+
end
|
2832
|
+
|
2833
|
+
it 'loads all translations' do
|
2834
|
+
expect(dictionary.description_translations.keys).to include('de', 'en')
|
2835
|
+
end
|
2836
|
+
|
2837
|
+
it 'returns the field value for the current locale' do
|
2838
|
+
I18n.locale = :en
|
2839
|
+
expect(dictionary.description).to eq('english-text')
|
2840
|
+
I18n.locale = :de
|
2841
|
+
expect(dictionary.description).to eq('deutsch-text')
|
2842
|
+
end
|
2843
|
+
end
|
2844
|
+
|
2845
|
+
context 'when a specific locale is included' do
|
2846
|
+
|
2847
|
+
let(:dictionary) do
|
2848
|
+
Dictionary.only(:'description.de').first
|
2849
|
+
end
|
2850
|
+
|
2851
|
+
it 'loads translations only for the included locale' do
|
2852
|
+
expect(dictionary.description_translations.keys).to include('de')
|
2853
|
+
expect(dictionary.description_translations.keys).to_not include('en')
|
2854
|
+
end
|
2855
|
+
|
2856
|
+
it 'returns the field value for the included locale' do
|
2857
|
+
I18n.locale = :en
|
2858
|
+
expect(dictionary.description).to be_nil
|
2859
|
+
I18n.locale = :de
|
2860
|
+
expect(dictionary.description).to eq('deutsch-text')
|
2861
|
+
end
|
2862
|
+
end
|
2863
|
+
|
2864
|
+
context 'when entire field is excluded' do
|
2865
|
+
|
2866
|
+
let(:dictionary) do
|
2867
|
+
Dictionary.without(:description).first
|
2868
|
+
end
|
2869
|
+
|
2870
|
+
it 'does not load all translations' do
|
2871
|
+
expect(dictionary.description_translations.keys).to_not include('de', 'en')
|
2872
|
+
end
|
2873
|
+
|
2874
|
+
it 'raises an ActiveModel::MissingAttributeError when attempting to access the field' do
|
2875
|
+
expect{dictionary.description}.to raise_error ActiveModel::MissingAttributeError
|
2876
|
+
end
|
2877
|
+
end
|
2878
|
+
|
2879
|
+
context 'when a specific locale is excluded' do
|
2880
|
+
|
2881
|
+
let(:dictionary) do
|
2882
|
+
Dictionary.without(:'description.de').first
|
2883
|
+
end
|
2884
|
+
|
2885
|
+
it 'does not load excluded translations' do
|
2886
|
+
expect(dictionary.description_translations.keys).to_not include('de')
|
2887
|
+
expect(dictionary.description_translations.keys).to include('en')
|
2888
|
+
end
|
2889
|
+
|
2890
|
+
it 'returns nil for excluded translations' do
|
2891
|
+
I18n.locale = :en
|
2892
|
+
expect(dictionary.description).to eq('english-text')
|
2893
|
+
I18n.locale = :de
|
2894
|
+
expect(dictionary.description).to be_nil
|
2895
|
+
end
|
2896
|
+
end
|
2897
|
+
end
|
2806
2898
|
end
|
2807
2899
|
|
2808
2900
|
[ :or, :any_of ].each do |method|
|
@@ -2890,7 +2982,7 @@ describe Mongoid::Criteria do
|
|
2890
2982
|
end
|
2891
2983
|
|
2892
2984
|
it "returns the values" do
|
2893
|
-
expect(plucked).to
|
2985
|
+
expect(plucked).to contain_exactly("Depeche Mode", "Tool", "Photek")
|
2894
2986
|
end
|
2895
2987
|
|
2896
2988
|
context "when subsequently executing the criteria without a pluck" do
|
@@ -2955,14 +3047,14 @@ describe Mongoid::Criteria do
|
|
2955
3047
|
end
|
2956
3048
|
end
|
2957
3049
|
|
2958
|
-
context "when plucking
|
3050
|
+
context "when plucking multi-fields" do
|
2959
3051
|
|
2960
3052
|
let(:plucked) do
|
2961
3053
|
Band.where(:name.exists => true).pluck(:name, :likes)
|
2962
3054
|
end
|
2963
3055
|
|
2964
3056
|
it "returns the values" do
|
2965
|
-
expect(plucked).to
|
3057
|
+
expect(plucked).to contain_exactly(["Depeche Mode", 3], ["Tool", 3], ["Photek", 1])
|
2966
3058
|
end
|
2967
3059
|
end
|
2968
3060
|
|
@@ -2973,7 +3065,7 @@ describe Mongoid::Criteria do
|
|
2973
3065
|
end
|
2974
3066
|
|
2975
3067
|
it "returns the duplicates" do
|
2976
|
-
expect(plucked).to
|
3068
|
+
expect(plucked).to contain_exactly(3, 3, 1)
|
2977
3069
|
end
|
2978
3070
|
end
|
2979
3071
|
end
|
@@ -3035,6 +3127,43 @@ describe Mongoid::Criteria do
|
|
3035
3127
|
end
|
3036
3128
|
end
|
3037
3129
|
end
|
3130
|
+
|
3131
|
+
context 'when plucking a localized field' do
|
3132
|
+
|
3133
|
+
before do
|
3134
|
+
I18n.locale = :en
|
3135
|
+
d = Dictionary.create(description: 'english-text')
|
3136
|
+
I18n.locale = :de
|
3137
|
+
d.description = 'deutsch-text'
|
3138
|
+
d.save
|
3139
|
+
end
|
3140
|
+
|
3141
|
+
after do
|
3142
|
+
I18n.locale = :en
|
3143
|
+
end
|
3144
|
+
|
3145
|
+
context 'when plucking the entire field' do
|
3146
|
+
|
3147
|
+
let(:plucked) do
|
3148
|
+
Dictionary.all.pluck(:description)
|
3149
|
+
end
|
3150
|
+
|
3151
|
+
it 'returns all translations' do
|
3152
|
+
expect(plucked.first).to eq({'en' => 'english-text', 'de' => 'deutsch-text'})
|
3153
|
+
end
|
3154
|
+
end
|
3155
|
+
|
3156
|
+
context 'when plucking a specific locale' do
|
3157
|
+
|
3158
|
+
let(:plucked) do
|
3159
|
+
Dictionary.all.pluck(:'description.de')
|
3160
|
+
end
|
3161
|
+
|
3162
|
+
it 'returns the specific translations' do
|
3163
|
+
expect(plucked.first).to eq({'de' => 'deutsch-text'})
|
3164
|
+
end
|
3165
|
+
end
|
3166
|
+
end
|
3038
3167
|
end
|
3039
3168
|
|
3040
3169
|
describe "#respond_to?" do
|
@@ -3314,17 +3443,6 @@ describe Mongoid::Criteria do
|
|
3314
3443
|
end
|
3315
3444
|
end
|
3316
3445
|
|
3317
|
-
context 'when the criteria contains a BSON::Regexp::Raw' do
|
3318
|
-
|
3319
|
-
let(:criteria) do
|
3320
|
-
Band.where(name: BSON::Regexp::Raw.new("^Depeche"))
|
3321
|
-
end
|
3322
|
-
|
3323
|
-
it "returns the matching documents" do
|
3324
|
-
expect(criteria).to eq([ match ])
|
3325
|
-
end
|
3326
|
-
end
|
3327
|
-
|
3328
3446
|
context "when the criteria is an exact fk array match" do
|
3329
3447
|
|
3330
3448
|
let(:id_one) do
|
@@ -3502,8 +3620,21 @@ describe Mongoid::Criteria do
|
|
3502
3620
|
|
3503
3621
|
describe "#with" do
|
3504
3622
|
|
3505
|
-
let!(:
|
3506
|
-
|
3623
|
+
let!(:criteria_and_collection) do
|
3624
|
+
collection = nil
|
3625
|
+
criteria = Band.where(name: "Depeche Mode").with(collection: "artists") do |crit|
|
3626
|
+
collection = crit.collection
|
3627
|
+
crit
|
3628
|
+
end
|
3629
|
+
[ criteria, collection ]
|
3630
|
+
end
|
3631
|
+
|
3632
|
+
let(:criteria) do
|
3633
|
+
criteria_and_collection[0]
|
3634
|
+
end
|
3635
|
+
|
3636
|
+
let(:collection) do
|
3637
|
+
criteria_and_collection[1]
|
3507
3638
|
end
|
3508
3639
|
|
3509
3640
|
it "retains the criteria selection" do
|
@@ -3511,7 +3642,7 @@ describe Mongoid::Criteria do
|
|
3511
3642
|
end
|
3512
3643
|
|
3513
3644
|
it "sets the persistence options" do
|
3514
|
-
expect(
|
3645
|
+
expect(collection.name).to eq("artists")
|
3515
3646
|
end
|
3516
3647
|
end
|
3517
3648
|
|
@@ -122,75 +122,6 @@ describe Mongoid::Document do
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
describe "#cache_key" do
|
126
|
-
|
127
|
-
let(:document) do
|
128
|
-
Dokument.new
|
129
|
-
end
|
130
|
-
|
131
|
-
context "when the document is new" do
|
132
|
-
|
133
|
-
it "has a new key name" do
|
134
|
-
expect(document.cache_key).to eq("dokuments/new")
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context "when persisted" do
|
139
|
-
|
140
|
-
before do
|
141
|
-
document.save
|
142
|
-
end
|
143
|
-
|
144
|
-
context "with updated_at" do
|
145
|
-
|
146
|
-
let!(:updated_at) do
|
147
|
-
document.updated_at.utc.to_s(:nsec)
|
148
|
-
end
|
149
|
-
|
150
|
-
it "has the id and updated_at key name" do
|
151
|
-
expect(document.cache_key).to eq("dokuments/#{document.id}-#{updated_at}")
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context "without updated_at, with Timestamps" do
|
156
|
-
|
157
|
-
before do
|
158
|
-
document.updated_at = nil
|
159
|
-
end
|
160
|
-
|
161
|
-
it "has the id key name" do
|
162
|
-
expect(document.cache_key).to eq("dokuments/#{document.id}")
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
context "when model dont have Timestamps" do
|
168
|
-
|
169
|
-
let(:artist) do
|
170
|
-
Artist.create!
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should have the id key name" do
|
174
|
-
expect(artist.cache_key).to eq("artists/#{artist.id}")
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
context "when model has Short Timestamps" do
|
179
|
-
|
180
|
-
let(:agent) do
|
181
|
-
ShortAgent.create!
|
182
|
-
end
|
183
|
-
|
184
|
-
let!(:updated_at) do
|
185
|
-
agent.updated_at.utc.to_s(:nsec)
|
186
|
-
end
|
187
|
-
|
188
|
-
it "has the id and updated_at key name" do
|
189
|
-
expect(agent.cache_key).to eq("short_agents/#{agent.id}-#{updated_at}")
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
125
|
describe "#identity" do
|
195
126
|
|
196
127
|
let(:person) do
|
@@ -519,14 +450,26 @@ describe Mongoid::Document do
|
|
519
450
|
expect(person.as_document).to have_key("name")
|
520
451
|
end
|
521
452
|
|
453
|
+
it "includes embeds one attributes as a symbol" do
|
454
|
+
expect(person.as_document).to have_key(:name)
|
455
|
+
end
|
456
|
+
|
522
457
|
it "includes embeds many attributes" do
|
523
458
|
expect(person.as_document).to have_key("addresses")
|
524
459
|
end
|
525
460
|
|
461
|
+
it "includes embeds many attributes as a symbol" do
|
462
|
+
expect(person.as_document).to have_key(:addresses)
|
463
|
+
end
|
464
|
+
|
526
465
|
it "includes second level embeds many attributes" do
|
527
466
|
expect(person.as_document["addresses"].first).to have_key("locations")
|
528
467
|
end
|
529
468
|
|
469
|
+
it "includes second level embeds many attributes as a symbol" do
|
470
|
+
expect(person.as_document["addresses"].first).to have_key(:locations)
|
471
|
+
end
|
472
|
+
|
530
473
|
context "with relation define store_as option in embeded_many" do
|
531
474
|
|
532
475
|
let!(:phone) do
|
@@ -537,6 +480,10 @@ describe Mongoid::Document do
|
|
537
480
|
expect(person.as_document).to have_key("mobile_phones")
|
538
481
|
end
|
539
482
|
|
483
|
+
it 'includes the store_as key association as a symbol' do
|
484
|
+
expect(person.as_document).to have_key(:mobile_phones)
|
485
|
+
end
|
486
|
+
|
540
487
|
it 'should not include the key of association' do
|
541
488
|
expect(person.as_document).to_not have_key("phones")
|
542
489
|
end
|
@@ -675,7 +622,7 @@ describe Mongoid::Document do
|
|
675
622
|
|
676
623
|
it "freezes attributes" do
|
677
624
|
expect(person.freeze).to eq(person)
|
678
|
-
expect { person.title = "something" }.to raise_error
|
625
|
+
expect { person.title = "something" }.to raise_error(RuntimeError)
|
679
626
|
end
|
680
627
|
end
|
681
628
|
|
@@ -689,7 +636,7 @@ describe Mongoid::Document do
|
|
689
636
|
person.freeze
|
690
637
|
expect {
|
691
638
|
person.title = "something"
|
692
|
-
}.to raise_error
|
639
|
+
}.to raise_error(RuntimeError)
|
693
640
|
end
|
694
641
|
end
|
695
642
|
end
|
@@ -1215,22 +1162,20 @@ describe Mongoid::Document do
|
|
1215
1162
|
|
1216
1163
|
context "when marshalling the document" do
|
1217
1164
|
|
1218
|
-
let(:
|
1219
|
-
|
1220
|
-
person.addresses.extension
|
1221
|
-
end
|
1165
|
+
let(:agency) do
|
1166
|
+
Agency.new
|
1222
1167
|
end
|
1223
1168
|
|
1224
|
-
let!(:
|
1225
|
-
|
1169
|
+
let!(:agent) do
|
1170
|
+
agency.agents.build(title: "VIP")
|
1226
1171
|
end
|
1227
1172
|
|
1228
1173
|
describe Marshal, ".dump" do
|
1229
1174
|
|
1230
1175
|
it "successfully dumps the document" do
|
1231
1176
|
expect {
|
1232
|
-
Marshal.dump(
|
1233
|
-
Marshal.dump(
|
1177
|
+
Marshal.dump(agency)
|
1178
|
+
Marshal.dump(agent)
|
1234
1179
|
}.not_to raise_error
|
1235
1180
|
end
|
1236
1181
|
end
|
@@ -1238,7 +1183,7 @@ describe Mongoid::Document do
|
|
1238
1183
|
describe Marshal, ".load" do
|
1239
1184
|
|
1240
1185
|
it "successfully loads the document" do
|
1241
|
-
expect
|
1186
|
+
expect(Marshal.load(Marshal.dump(agency))).to eq(agency)
|
1242
1187
|
end
|
1243
1188
|
end
|
1244
1189
|
end
|
@@ -1253,22 +1198,26 @@ describe Mongoid::Document do
|
|
1253
1198
|
|
1254
1199
|
describe "#fetch" do
|
1255
1200
|
|
1256
|
-
let
|
1257
|
-
|
1201
|
+
let(:agency) do
|
1202
|
+
Agency.new
|
1203
|
+
end
|
1204
|
+
|
1205
|
+
let(:agent) do
|
1206
|
+
agency.agents.build(title: "VIP", address: address)
|
1258
1207
|
end
|
1259
1208
|
|
1260
|
-
let
|
1261
|
-
|
1209
|
+
let(:address) do
|
1210
|
+
Address.new(city: 'Berlin')
|
1262
1211
|
end
|
1263
1212
|
|
1264
1213
|
it "stores the parent object" do
|
1265
|
-
expect(cache.fetch("key") {
|
1266
|
-
expect(cache.fetch("key")).to eq(
|
1214
|
+
expect(cache.fetch("key") { agency }).to eq(agency)
|
1215
|
+
expect(cache.fetch("key")).to eq(agency)
|
1267
1216
|
end
|
1268
1217
|
|
1269
1218
|
it "stores the embedded object" do
|
1270
|
-
expect(cache.fetch("key") {
|
1271
|
-
expect(cache.fetch("key")).to eq(
|
1219
|
+
expect(cache.fetch("key") { agent }).to eq(agent)
|
1220
|
+
expect(cache.fetch("key").address).to eq(agent.address)
|
1272
1221
|
end
|
1273
1222
|
end
|
1274
1223
|
end
|