mongoid 6.1.0 → 6.2.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/lib/mongoid/atomic.rb +3 -3
- data/lib/mongoid/attributes/dynamic.rb +3 -2
- data/lib/mongoid/attributes/nested.rb +1 -1
- data/lib/mongoid/attributes/processing.rb +0 -4
- data/lib/mongoid/attributes.rb +1 -2
- data/lib/mongoid/changeable.rb +1 -1
- data/lib/mongoid/clients/options.rb +1 -1
- data/lib/mongoid/composable.rb +3 -1
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/geo_near.rb +3 -2
- data/lib/mongoid/contextual/memory.rb +3 -3
- data/lib/mongoid/contextual/mongo.rb +5 -5
- data/lib/mongoid/contextual/none.rb +14 -2
- data/lib/mongoid/copyable.rb +1 -5
- data/lib/mongoid/criteria/findable.rb +3 -2
- data/lib/mongoid/criteria/includable.rb +2 -2
- data/lib/mongoid/criteria/queryable/aggregable.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/array.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +4 -4
- data/lib/mongoid/criteria/queryable/extensions/object.rb +4 -4
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +34 -0
- data/lib/mongoid/criteria/queryable/options.rb +16 -0
- data/lib/mongoid/criteria/queryable/selector.rb +1 -1
- data/lib/mongoid/criteria.rb +2 -2
- data/lib/mongoid/document.rb +1 -1
- data/lib/mongoid/errors/delete_restriction.rb +2 -2
- data/lib/mongoid/errors/inverse_not_found.rb +1 -1
- data/lib/mongoid/extensions/hash.rb +3 -2
- data/lib/mongoid/extensions/object.rb +2 -2
- data/lib/mongoid/extensions/time.rb +1 -1
- data/lib/mongoid/factory.rb +0 -1
- data/lib/mongoid/fields/foreign_key.rb +2 -2
- data/lib/mongoid/findable.rb +1 -1
- data/lib/mongoid/indexable/specification.rb +1 -1
- data/lib/mongoid/indexable.rb +3 -2
- data/lib/mongoid/interceptable.rb +9 -11
- data/lib/mongoid/loggable.rb +1 -1
- 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 +3 -3
- data/lib/mongoid/matchable/exists.rb +2 -2
- data/lib/mongoid/matchable/gt.rb +2 -2
- data/lib/mongoid/matchable/gte.rb +2 -2
- data/lib/mongoid/matchable/in.rb +2 -2
- data/lib/mongoid/matchable/lt.rb +2 -2
- data/lib/mongoid/matchable/lte.rb +2 -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 +27 -0
- data/lib/mongoid/matchable/size.rb +2 -2
- data/lib/mongoid/matchable.rb +16 -9
- data/lib/mongoid/persistable/creatable.rb +2 -4
- data/lib/mongoid/persistable/deletable.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +1 -1
- data/lib/mongoid/persistable/upsertable.rb +1 -1
- data/lib/mongoid/persistable.rb +0 -3
- data/lib/mongoid/persistence_context.rb +2 -3
- data/lib/mongoid/relations/accessors.rb +1 -2
- data/lib/mongoid/relations/bindings/embedded/in.rb +0 -4
- data/lib/mongoid/relations/bindings/embedded/many.rb +1 -8
- data/lib/mongoid/relations/bindings/embedded/one.rb +0 -10
- data/lib/mongoid/relations/bindings/referenced/many.rb +0 -4
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -4
- data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +1 -1
- data/lib/mongoid/relations/conversions.rb +1 -1
- data/lib/mongoid/relations/counter_cache.rb +10 -10
- data/lib/mongoid/relations/eager/base.rb +4 -4
- data/lib/mongoid/relations/eager.rb +6 -11
- data/lib/mongoid/relations/embedded/batchable.rb +3 -3
- data/lib/mongoid/relations/embedded/in.rb +1 -3
- data/lib/mongoid/relations/embedded/many.rb +12 -9
- data/lib/mongoid/relations/embedded/one.rb +1 -3
- data/lib/mongoid/relations/macros.rb +3 -2
- data/lib/mongoid/relations/metadata.rb +3 -3
- data/lib/mongoid/relations/nested_builder.rb +1 -1
- data/lib/mongoid/relations/proxy.rb +3 -2
- data/lib/mongoid/relations/referenced/in.rb +1 -4
- data/lib/mongoid/relations/referenced/many.rb +5 -7
- data/lib/mongoid/relations/referenced/many_to_many.rb +2 -2
- data/lib/mongoid/relations/referenced/one.rb +0 -2
- data/lib/mongoid/relations/reflections.rb +2 -2
- data/lib/mongoid/relations/synchronization.rb +11 -11
- data/lib/mongoid/scopable.rb +2 -2
- data/lib/mongoid/serializable.rb +4 -3
- data/lib/mongoid/tasks/database.rb +2 -1
- data/lib/mongoid/threaded.rb +4 -4
- data/lib/mongoid/validatable/macros.rb +4 -2
- data/lib/mongoid/validatable.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +12 -2
- data/spec/app/models/book.rb +2 -1
- data/spec/app/models/page.rb +1 -1
- data/spec/mongoid/contextual/none_spec.rb +15 -0
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +89 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +15 -0
- data/spec/mongoid/criteria_spec.rb +6 -2
- data/spec/mongoid/interceptable_spec.rb +35 -8
- 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 +11 -11
- data/spec/mongoid/matchable/exists_spec.rb +5 -5
- data/spec/mongoid/matchable/gt_spec.rb +8 -8
- data/spec/mongoid/matchable/gte_spec.rb +8 -8
- data/spec/mongoid/matchable/in_spec.rb +5 -5
- data/spec/mongoid/matchable/lt_spec.rb +8 -8
- data/spec/mongoid/matchable/lte_spec.rb +8 -8
- 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 +59 -0
- data/spec/mongoid/matchable/size_spec.rb +3 -3
- data/spec/mongoid/matchable_spec.rb +108 -58
- data/spec/mongoid/persistable/deletable_spec.rb +15 -0
- data/spec/mongoid/persistable/settable_spec.rb +16 -0
- data/spec/mongoid/persistence_context_spec.rb +22 -1
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +4 -4
- data/spec/mongoid/relations/embedded/many_spec.rb +24 -6
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +1 -1
- data/spec/mongoid/relations/synchronization_spec.rb +48 -2
- data/spec/mongoid/relations/touchable_spec.rb +40 -0
- data/spec/mongoid/validatable/uniqueness_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -2
- data.tar.gz.sig +0 -0
- metadata +10 -5
- metadata.gz.sig +1 -1
|
@@ -17,7 +17,8 @@ module Mongoid
|
|
|
17
17
|
# validates_associated :name, :addresses
|
|
18
18
|
# end
|
|
19
19
|
#
|
|
20
|
-
# @param [ Array ]
|
|
20
|
+
# @param [ Array ] args The arguments to pass to the validator.
|
|
21
|
+
#
|
|
21
22
|
def validates_associated(*args)
|
|
22
23
|
validates_with(AssociatedValidator, _merge_attributes(args))
|
|
23
24
|
end
|
|
@@ -34,7 +35,8 @@ module Mongoid
|
|
|
34
35
|
# validates_uniqueness_of :title
|
|
35
36
|
# end
|
|
36
37
|
#
|
|
37
|
-
# @param [ Array ]
|
|
38
|
+
# @param [ Array ] args The arguments to pass to the validator.
|
|
39
|
+
#
|
|
38
40
|
def validates_uniqueness_of(*args)
|
|
39
41
|
validates_with(UniquenessValidator, _merge_attributes(args))
|
|
40
42
|
end
|
data/lib/mongoid/validatable.rb
CHANGED
|
@@ -144,7 +144,7 @@ module Mongoid
|
|
|
144
144
|
# @example Validate with a specific validator.
|
|
145
145
|
# validates_with MyValidator, on: :create
|
|
146
146
|
#
|
|
147
|
-
# @param [ Class<Array>, Hash ]
|
|
147
|
+
# @param [ Class<Array>, Hash ] args The validator classes and options.
|
|
148
148
|
#
|
|
149
149
|
# @note See ActiveModel::Validations::With for full options. This is
|
|
150
150
|
# overridden to add autosave functionality when presence validation is
|
data/lib/mongoid/version.rb
CHANGED
|
@@ -34,8 +34,9 @@ development:
|
|
|
34
34
|
# - 'dbOwner'
|
|
35
35
|
|
|
36
36
|
# Change the default authentication mechanism. Valid options are: :scram,
|
|
37
|
-
# :mongodb_cr, :mongodb_x509, and :plain.
|
|
38
|
-
#
|
|
37
|
+
# :mongodb_cr, :mongodb_x509, and :plain. Note that all authentication
|
|
38
|
+
# mechanisms require username and password, with the exception of :mongodb_x509.
|
|
39
|
+
# Default on mongoDB 3.0 is :scram, default on 2.4 and 2.6 is :plain.
|
|
39
40
|
# auth_mech: :scram
|
|
40
41
|
|
|
41
42
|
# The database or source to authenticate the user against.
|
|
@@ -121,6 +122,10 @@ development:
|
|
|
121
122
|
# existing method. (default: false)
|
|
122
123
|
# scope_overwrite_exception: false
|
|
123
124
|
|
|
125
|
+
# Raise an error when defining a field with the same name as an
|
|
126
|
+
# existing method. (default: false)
|
|
127
|
+
# duplicate_fields_exception: false
|
|
128
|
+
|
|
124
129
|
# Use Active Support's time zone in conversions. (default: true)
|
|
125
130
|
# use_activesupport_time_zone: true
|
|
126
131
|
|
|
@@ -132,6 +137,11 @@ development:
|
|
|
132
137
|
# otherwise.(default: :info)
|
|
133
138
|
# log_level: :info
|
|
134
139
|
|
|
140
|
+
# Control whether `belongs_to` association is required. By default
|
|
141
|
+
# `belongs_to` will trigger a validation error if the association
|
|
142
|
+
# is not present. (default: true)
|
|
143
|
+
# belongs_to_required_by_default: true
|
|
144
|
+
|
|
135
145
|
# Application name that is printed to the mongodb logs upon establishing a
|
|
136
146
|
# connection in server versions >= 3.4. Note that the name cannot exceed 128 bytes.
|
|
137
147
|
# app_name: MyApplicationName
|
data/spec/app/models/book.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
class Book
|
|
2
2
|
include Mongoid::Document
|
|
3
3
|
include Mongoid::Attributes::Dynamic
|
|
4
|
+
include Mongoid::Timestamps
|
|
4
5
|
field :title, type: String
|
|
5
6
|
field :chapters, type: Integer
|
|
6
7
|
belongs_to :series
|
|
@@ -11,5 +12,5 @@ class Book
|
|
|
11
12
|
doc.chapters = 5
|
|
12
13
|
end
|
|
13
14
|
|
|
14
|
-
embeds_many :pages
|
|
15
|
+
embeds_many :pages, cascade_callbacks: true
|
|
15
16
|
end
|
data/spec/app/models/page.rb
CHANGED
|
@@ -65,6 +65,21 @@ describe Mongoid::Contextual::None do
|
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
describe "#distinct" do
|
|
69
|
+
|
|
70
|
+
let!(:band) do
|
|
71
|
+
Band.create(name: "Depeche Mode")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
let(:context) do
|
|
75
|
+
described_class.new(Band.where(name: "Depeche Mode"))
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "returns an empty array" do
|
|
79
|
+
expect(context.distinct(:id)).to eq([])
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
68
83
|
describe "#pluck" do
|
|
69
84
|
|
|
70
85
|
let!(:band) do
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Mongoid::Criteria::Queryable::Extensions::Regexp::Raw do
|
|
4
|
+
|
|
5
|
+
describe ".evolve" do
|
|
6
|
+
|
|
7
|
+
context "when provided a bson raw regexp" do
|
|
8
|
+
|
|
9
|
+
let(:regexp) do
|
|
10
|
+
BSON::Regexp::Raw.new("^[123]")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:evolved) do
|
|
14
|
+
BSON::Regexp::Raw.evolve(regexp)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "returns the regexp" do
|
|
18
|
+
expect(evolved).to be(regexp)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "when providing a string" do
|
|
23
|
+
|
|
24
|
+
let(:regexp_string) do
|
|
25
|
+
'^[123]'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
let(:evolved) do
|
|
29
|
+
BSON::Regexp::Raw.evolve(regexp_string)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "returns the converted raw regexp" do
|
|
33
|
+
expect(evolved).to eq(BSON::Regexp::Raw.new(regexp_string))
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "when provided an array" do
|
|
38
|
+
|
|
39
|
+
context "when the elements are bson raw regexps" do
|
|
40
|
+
|
|
41
|
+
let(:regexp) do
|
|
42
|
+
BSON::Regexp::Raw.new("^[123]")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
let(:array) do
|
|
46
|
+
[ regexp ]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
let(:evolved) do
|
|
50
|
+
BSON::Regexp::Raw.evolve(array)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "returns the array containing raw regexps" do
|
|
54
|
+
expect(evolved).to eq([ regexp ])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "does not evolve in place" do
|
|
58
|
+
expect(evolved).to_not equal(array)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context "when the elements are strings" do
|
|
63
|
+
|
|
64
|
+
let(:regexp_string) do
|
|
65
|
+
"^[123]"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
let(:evolved) do
|
|
69
|
+
BSON::Regexp::Raw.evolve([ regexp_string ])
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "returns the regexps" do
|
|
73
|
+
expect(evolved).to eq([ BSON::Regexp::Raw.new(regexp_string) ])
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
describe "#regexp?" do
|
|
80
|
+
|
|
81
|
+
let(:regexp) do
|
|
82
|
+
BSON::Regexp::Raw.new('^[123]')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "returns true" do
|
|
86
|
+
expect(regexp).to be_regexp
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -3469,6 +3469,21 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
3469
3469
|
expect(selection.selector).to eq({ "user_id" => document.id })
|
|
3470
3470
|
end
|
|
3471
3471
|
end
|
|
3472
|
+
|
|
3473
|
+
context 'when the field is a String and the value is a BSON::Regexp::Raw' do
|
|
3474
|
+
|
|
3475
|
+
let(:raw_regexp) do
|
|
3476
|
+
BSON::Regexp::Raw.new('^Em')
|
|
3477
|
+
end
|
|
3478
|
+
|
|
3479
|
+
let(:selection) do
|
|
3480
|
+
Login.where(_id: raw_regexp)
|
|
3481
|
+
end
|
|
3482
|
+
|
|
3483
|
+
it 'does not convert the bson raw regexp object to a String' do
|
|
3484
|
+
expect(selection.selector).to eq({ "_id" => raw_regexp })
|
|
3485
|
+
end
|
|
3486
|
+
end
|
|
3472
3487
|
end
|
|
3473
3488
|
end
|
|
3474
3489
|
|
|
@@ -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
|
|
|
@@ -484,32 +484,40 @@ describe Mongoid::Interceptable do
|
|
|
484
484
|
|
|
485
485
|
context "when the child does not have the same callback defined" do
|
|
486
486
|
|
|
487
|
-
let(:
|
|
488
|
-
|
|
487
|
+
let(:exhibition) do
|
|
488
|
+
Exhibition.new
|
|
489
489
|
end
|
|
490
490
|
|
|
491
|
-
let!(:
|
|
492
|
-
|
|
491
|
+
let!(:exhibitor) do
|
|
492
|
+
exhibition.exhibitors.build
|
|
493
493
|
end
|
|
494
494
|
|
|
495
495
|
context "when running the callbacks directly" do
|
|
496
496
|
|
|
497
497
|
before(:all) do
|
|
498
|
-
|
|
499
|
-
|
|
498
|
+
Exhibition.define_model_callbacks(:rearrange)
|
|
499
|
+
Exhibition.after_rearrange { }
|
|
500
500
|
end
|
|
501
501
|
|
|
502
502
|
after(:all) do
|
|
503
|
-
|
|
503
|
+
Exhibition.reset_callbacks(:rearrange)
|
|
504
504
|
end
|
|
505
505
|
|
|
506
506
|
it "does not cascade to the child" do
|
|
507
|
-
expect(
|
|
507
|
+
expect(exhibition.run_callbacks(:rearrange)).to be true
|
|
508
508
|
end
|
|
509
509
|
end
|
|
510
510
|
|
|
511
511
|
context "when the callbacks get triggered by a destroy" do
|
|
512
512
|
|
|
513
|
+
let(:band) do
|
|
514
|
+
Band.new
|
|
515
|
+
end
|
|
516
|
+
|
|
517
|
+
let!(:record) do
|
|
518
|
+
band.records.build
|
|
519
|
+
end
|
|
520
|
+
|
|
513
521
|
before(:all) do
|
|
514
522
|
Band.define_model_callbacks(:rearrange)
|
|
515
523
|
Band.set_callback(:validation, :before) do
|
|
@@ -1152,6 +1160,25 @@ describe Mongoid::Interceptable do
|
|
|
1152
1160
|
expect(band.reload.records.first.before_validation_called).to be true
|
|
1153
1161
|
end
|
|
1154
1162
|
end
|
|
1163
|
+
|
|
1164
|
+
context 'when the parent is updated' do
|
|
1165
|
+
|
|
1166
|
+
let(:band) do
|
|
1167
|
+
Band.create(name: "Moderat")
|
|
1168
|
+
end
|
|
1169
|
+
|
|
1170
|
+
before do
|
|
1171
|
+
band.update(records: [ { name: 'Black on Both Sides' }])
|
|
1172
|
+
end
|
|
1173
|
+
|
|
1174
|
+
it 'executes the callback' do
|
|
1175
|
+
expect(band.records.first.before_validation_called).to be true
|
|
1176
|
+
end
|
|
1177
|
+
|
|
1178
|
+
it 'persists the change' do
|
|
1179
|
+
expect(band.reload.records.first.before_validation_called).to be true
|
|
1180
|
+
end
|
|
1181
|
+
end
|
|
1155
1182
|
end
|
|
1156
1183
|
|
|
1157
1184
|
context "when the child is persisted" do
|
|
@@ -6,25 +6,25 @@ describe Mongoid::Matchable::All do
|
|
|
6
6
|
described_class.new(["first", "second", "third"])
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
describe "#
|
|
9
|
+
describe "#_matches?" do
|
|
10
10
|
|
|
11
11
|
context "when the attribute includes all of the values" do
|
|
12
12
|
|
|
13
13
|
it "returns true" do
|
|
14
|
-
expect(matcher.
|
|
14
|
+
expect(matcher._matches?("$all" => ["first", /\Asec.*\z/])).to be true
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
context "when the attributes doesn't include all of the values" do
|
|
19
19
|
|
|
20
20
|
it "returns false" do
|
|
21
|
-
expect(matcher.
|
|
21
|
+
expect(matcher._matches?("$all" => ["second", "third", "fourth"])).to be false
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
context "when the value is empty" do
|
|
26
26
|
it "returns false" do
|
|
27
|
-
expect(matcher.
|
|
27
|
+
expect(matcher._matches?("$all" => [])).to be false
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
end
|
|
@@ -10,7 +10,7 @@ describe Mongoid::Matchable::And do
|
|
|
10
10
|
described_class.new("value", person)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
describe "#
|
|
13
|
+
describe "#_matches?" do
|
|
14
14
|
|
|
15
15
|
context "when provided a simple expression" do
|
|
16
16
|
|
|
@@ -19,7 +19,7 @@ describe Mongoid::Matchable::And do
|
|
|
19
19
|
context "when the value matches" do
|
|
20
20
|
|
|
21
21
|
let(:matches) do
|
|
22
|
-
matcher.
|
|
22
|
+
matcher._matches?([ { title: "Sir" } ])
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
before do
|
|
@@ -34,7 +34,7 @@ describe Mongoid::Matchable::And do
|
|
|
34
34
|
context "when the expression is a $not" do
|
|
35
35
|
|
|
36
36
|
let(:matches) do
|
|
37
|
-
matcher.
|
|
37
|
+
matcher._matches?([ { title: {:$not => /Foobar/ } }])
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
context "when the value matches" do
|
|
@@ -59,7 +59,7 @@ describe Mongoid::Matchable::And do
|
|
|
59
59
|
context "when the value does not match" do
|
|
60
60
|
|
|
61
61
|
let(:matches) do
|
|
62
|
-
matcher.
|
|
62
|
+
matcher._matches?([ { title: "Sir" } ])
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it "returns false" do
|
|
@@ -73,7 +73,7 @@ describe Mongoid::Matchable::And do
|
|
|
73
73
|
context "when all of the values are equal" do
|
|
74
74
|
|
|
75
75
|
let(:matches) do
|
|
76
|
-
matcher.
|
|
76
|
+
matcher._matches?(
|
|
77
77
|
[ { title: "Sir" }, { _id: person.id } ]
|
|
78
78
|
)
|
|
79
79
|
end
|
|
@@ -90,7 +90,7 @@ describe Mongoid::Matchable::And do
|
|
|
90
90
|
context "when one of the values does not match" do
|
|
91
91
|
|
|
92
92
|
let(:matches) do
|
|
93
|
-
matcher.
|
|
93
|
+
matcher._matches?(
|
|
94
94
|
[ { title: "Sir" }, { _id: BSON::ObjectId.new } ]
|
|
95
95
|
)
|
|
96
96
|
end
|
|
@@ -107,7 +107,7 @@ describe Mongoid::Matchable::And do
|
|
|
107
107
|
context "when provided no expressions" do
|
|
108
108
|
|
|
109
109
|
let(:matches) do
|
|
110
|
-
matcher.
|
|
110
|
+
matcher._matches?([])
|
|
111
111
|
end
|
|
112
112
|
|
|
113
113
|
it "returns true" do
|
|
@@ -122,7 +122,7 @@ describe Mongoid::Matchable::And do
|
|
|
122
122
|
context "when all of the values are equal" do
|
|
123
123
|
|
|
124
124
|
let(:matches) do
|
|
125
|
-
matcher.
|
|
125
|
+
matcher._matches?(
|
|
126
126
|
[
|
|
127
127
|
{ title: { "$in" => [ "Sir", "Madam" ] } },
|
|
128
128
|
{ _id: person.id }
|
|
@@ -142,7 +142,7 @@ describe Mongoid::Matchable::And do
|
|
|
142
142
|
context "when one of the values does not match" do
|
|
143
143
|
|
|
144
144
|
let(:matches) do
|
|
145
|
-
matcher.
|
|
145
|
+
matcher._matches?(
|
|
146
146
|
[
|
|
147
147
|
{ title: { "$in" => [ "Prince", "Madam" ] } },
|
|
148
148
|
{ _id: BSON::ObjectId.new }
|
|
@@ -164,7 +164,7 @@ describe Mongoid::Matchable::And do
|
|
|
164
164
|
context "when all the expressions match" do
|
|
165
165
|
|
|
166
166
|
let(:matches) do
|
|
167
|
-
matcher.
|
|
167
|
+
matcher._matches?(
|
|
168
168
|
[
|
|
169
169
|
{ title: "Sir", age: 23 },
|
|
170
170
|
{ _id: person.id }
|
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe Mongoid::Matchable::Default do
|
|
4
4
|
|
|
5
|
-
describe "#
|
|
5
|
+
describe "#_matches?" do
|
|
6
6
|
|
|
7
7
|
context "when comparing strings" do
|
|
8
8
|
|
|
@@ -13,14 +13,14 @@ describe Mongoid::Matchable::Default do
|
|
|
13
13
|
context "when the values are equal" do
|
|
14
14
|
|
|
15
15
|
it "returns true" do
|
|
16
|
-
expect(matcher.
|
|
16
|
+
expect(matcher._matches?("Testing")).to be true
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
context "when the values are not equal" do
|
|
21
21
|
|
|
22
22
|
it "returns false" do
|
|
23
|
-
expect(matcher.
|
|
23
|
+
expect(matcher._matches?("Other")).to be false
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -38,14 +38,14 @@ describe Mongoid::Matchable::Default do
|
|
|
38
38
|
context "when the values are equal" do
|
|
39
39
|
|
|
40
40
|
it "returns true" do
|
|
41
|
-
expect(matcher.
|
|
41
|
+
expect(matcher._matches?(object_id)).to be true
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
context "when the values are not equal" do
|
|
46
46
|
|
|
47
47
|
it "returns false" do
|
|
48
|
-
expect(matcher.
|
|
48
|
+
expect(matcher._matches?(BSON::ObjectId.new)).to be false
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
end
|
|
@@ -61,14 +61,14 @@ describe Mongoid::Matchable::Default do
|
|
|
61
61
|
context "when the value is a string" do
|
|
62
62
|
|
|
63
63
|
it "returns true" do
|
|
64
|
-
expect(matcher.
|
|
64
|
+
expect(matcher._matches?("Test1")).to be true
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
context "when the value is a regexp" do
|
|
69
69
|
|
|
70
70
|
it "returns true" do
|
|
71
|
-
expect(matcher.
|
|
71
|
+
expect(matcher._matches?(/^Test[3-5]$/)).to be true
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
74
|
end
|
|
@@ -76,7 +76,7 @@ describe Mongoid::Matchable::Default do
|
|
|
76
76
|
context "when the attribute does not contain the value" do
|
|
77
77
|
|
|
78
78
|
it "returns false" do
|
|
79
|
-
expect(matcher.
|
|
79
|
+
expect(matcher._matches?("Test4")).to be false
|
|
80
80
|
end
|
|
81
81
|
end
|
|
82
82
|
end
|
|
@@ -94,14 +94,14 @@ describe Mongoid::Matchable::Default do
|
|
|
94
94
|
context "when the attribute contains the value" do
|
|
95
95
|
|
|
96
96
|
it "returns true" do
|
|
97
|
-
expect(matcher.
|
|
97
|
+
expect(matcher._matches?(object_id)).to be true
|
|
98
98
|
end
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
context "when the attribute does not contain the value" do
|
|
102
102
|
|
|
103
103
|
it "returns false" do
|
|
104
|
-
expect(matcher.
|
|
104
|
+
expect(matcher._matches?(BSON::ObjectId.new)).to be false
|
|
105
105
|
end
|
|
106
106
|
end
|
|
107
107
|
end
|
|
@@ -115,14 +115,14 @@ describe Mongoid::Matchable::Default do
|
|
|
115
115
|
context "when the attribute contains the value" do
|
|
116
116
|
|
|
117
117
|
it "returns true" do
|
|
118
|
-
expect(matcher.
|
|
118
|
+
expect(matcher._matches?(["Test1", "Test2", "Test3"])).to be true
|
|
119
119
|
end
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
context "when the attribute does not contain the value" do
|
|
123
123
|
|
|
124
124
|
it "returns false" do
|
|
125
|
-
expect(matcher.
|
|
125
|
+
expect(matcher._matches?(["Test1", "Test2"])).to be false
|
|
126
126
|
end
|
|
127
127
|
end
|
|
128
128
|
end
|
|
@@ -7,14 +7,14 @@ describe Mongoid::Matchable::ElemMatch do
|
|
|
7
7
|
described_class.new(attribute)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
describe "#
|
|
10
|
+
describe "#_matches?" do
|
|
11
11
|
|
|
12
12
|
context "when the attribute is not an array" do
|
|
13
13
|
|
|
14
14
|
let(:attribute) {"string"}
|
|
15
15
|
|
|
16
16
|
it "returns false" do
|
|
17
|
-
expect(matcher.
|
|
17
|
+
expect(matcher._matches?("$elemMatch" => {"a" => 1})).to be false
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -23,26 +23,26 @@ describe Mongoid::Matchable::ElemMatch do
|
|
|
23
23
|
let(:attribute) {"string"}
|
|
24
24
|
|
|
25
25
|
it "returns false" do
|
|
26
|
-
expect(matcher.
|
|
26
|
+
expect(matcher._matches?("$elemMatch" => [])).to be false
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
context "when there is a sub document that matches the criteria" do
|
|
31
31
|
|
|
32
32
|
it "returns true" do
|
|
33
|
-
expect(matcher.
|
|
33
|
+
expect(matcher._matches?("$elemMatch" => {"a" => 1})).to be true
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
context "when evaluating multiple fields of the subdocument" do
|
|
37
37
|
|
|
38
38
|
it "returns true" do
|
|
39
|
-
expect(matcher.
|
|
39
|
+
expect(matcher._matches?("$elemMatch" => {"a" => 1, "b" => 2})).to be true
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
context "when the $elemMatch document keys are out of order" do
|
|
43
43
|
|
|
44
44
|
it "returns true" do
|
|
45
|
-
expect(matcher.
|
|
45
|
+
expect(matcher._matches?("$elemMatch" => {"b" => 2, "a" => 1})).to be true
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
end
|
|
@@ -50,7 +50,7 @@ describe Mongoid::Matchable::ElemMatch do
|
|
|
50
50
|
context "when using other operators that match" do
|
|
51
51
|
|
|
52
52
|
it "returns true" do
|
|
53
|
-
expect(matcher.
|
|
53
|
+
expect(matcher._matches?("$elemMatch" => {"a" => {"$in" => [1]}, "b" => {"$gt" => 1}})).to be true
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
end
|
|
@@ -58,20 +58,20 @@ describe Mongoid::Matchable::ElemMatch do
|
|
|
58
58
|
context "when there is not a sub document that matches the criteria" do
|
|
59
59
|
|
|
60
60
|
it "returns false" do
|
|
61
|
-
expect(matcher.
|
|
61
|
+
expect(matcher._matches?("$elemMatch" => {"a" => 10})).to be false
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
context "when evaluating multiple fields of the subdocument" do
|
|
65
65
|
|
|
66
66
|
it "returns false" do
|
|
67
|
-
expect(matcher.
|
|
67
|
+
expect(matcher._matches?("$elemMatch" => {"a" => 1, "b" => 3})).to be false
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
context "when using other operators that do not match" do
|
|
72
72
|
|
|
73
73
|
it "returns true" do
|
|
74
|
-
expect(matcher.
|
|
74
|
+
expect(matcher._matches?("$elemMatch" => {"a" => {"$in" => [1]}, "b" => {"$gt" => 10}})).to be false
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
end
|
|
@@ -79,7 +79,7 @@ describe Mongoid::Matchable::ElemMatch do
|
|
|
79
79
|
context "when using a criteria that matches partially but not a single sub document" do
|
|
80
80
|
|
|
81
81
|
it "returns false" do
|
|
82
|
-
expect(matcher.
|
|
82
|
+
expect(matcher._matches?("$elemMatch" => {"a" => 3, "b" => 2})).to be false
|
|
83
83
|
end
|
|
84
84
|
end
|
|
85
85
|
end
|