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
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe Mongoid::Matchable::Exists do
|
|
4
4
|
|
|
5
|
-
describe "#
|
|
5
|
+
describe "#_matches?" do
|
|
6
6
|
|
|
7
7
|
context "when checking for existence" do
|
|
8
8
|
|
|
@@ -13,7 +13,7 @@ describe Mongoid::Matchable::Exists do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "returns true" do
|
|
16
|
-
expect(matcher.
|
|
16
|
+
expect(matcher._matches?("$exists" => true)).to be true
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -24,7 +24,7 @@ describe Mongoid::Matchable::Exists do
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it "returns false" do
|
|
27
|
-
expect(matcher.
|
|
27
|
+
expect(matcher._matches?("$exists" => true)).to be false
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
end
|
|
@@ -38,7 +38,7 @@ describe Mongoid::Matchable::Exists do
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "returns false" do
|
|
41
|
-
expect(matcher.
|
|
41
|
+
expect(matcher._matches?("$exists" => false)).to be false
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
@@ -49,7 +49,7 @@ describe Mongoid::Matchable::Exists do
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
it "returns true" do
|
|
52
|
-
expect(matcher.
|
|
52
|
+
expect(matcher._matches?("$exists" => false)).to be true
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
end
|
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe Mongoid::Matchable::Gt do
|
|
4
4
|
|
|
5
|
-
describe "#
|
|
5
|
+
describe "#_matches?" do
|
|
6
6
|
|
|
7
7
|
context "when the value is larger" do
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ describe Mongoid::Matchable::Gt do
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
it "returns true" do
|
|
14
|
-
expect(matcher.
|
|
14
|
+
expect(matcher._matches?("$gt" => 3)).to be true
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -22,7 +22,7 @@ describe Mongoid::Matchable::Gt do
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it "returns false" do
|
|
25
|
-
expect(matcher.
|
|
25
|
+
expect(matcher._matches?("$gt" => 3)).to be false
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -33,7 +33,7 @@ describe Mongoid::Matchable::Gt do
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "returns false" do
|
|
36
|
-
expect(matcher.
|
|
36
|
+
expect(matcher._matches?("$gt" => 10)).to be false
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -44,7 +44,7 @@ describe Mongoid::Matchable::Gt do
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it "returns false" do
|
|
47
|
-
expect(matcher.
|
|
47
|
+
expect(matcher._matches?("$gt" => 5)).to be false
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
@@ -56,7 +56,7 @@ describe Mongoid::Matchable::Gt do
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
it "returns false" do
|
|
59
|
-
expect(matcher.
|
|
59
|
+
expect(matcher._matches?("$gt" => 5)).to be true
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
@@ -67,7 +67,7 @@ describe Mongoid::Matchable::Gt do
|
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
it "returns false" do
|
|
70
|
-
expect(matcher.
|
|
70
|
+
expect(matcher._matches?("$gt" => 5)).to be false
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
73
|
end
|
|
@@ -79,7 +79,7 @@ describe Mongoid::Matchable::Gt do
|
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it "returns false" do
|
|
82
|
-
expect(matcher.
|
|
82
|
+
expect(matcher._matches?("$gt" => '4.9')).to be false
|
|
83
83
|
end
|
|
84
84
|
end
|
|
85
85
|
end
|
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe Mongoid::Matchable::Gte do
|
|
4
4
|
|
|
5
|
-
describe "#
|
|
5
|
+
describe "#_matches?" do
|
|
6
6
|
|
|
7
7
|
context "when the value is larger" do
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ describe Mongoid::Matchable::Gte do
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
it "returns true" do
|
|
14
|
-
expect(matcher.
|
|
14
|
+
expect(matcher._matches?("$gte" => 3)).to be true
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -22,7 +22,7 @@ describe Mongoid::Matchable::Gte do
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it "returns false" do
|
|
25
|
-
expect(matcher.
|
|
25
|
+
expect(matcher._matches?("$gte" => 10)).to be false
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -33,7 +33,7 @@ describe Mongoid::Matchable::Gte do
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "returns true" do
|
|
36
|
-
expect(matcher.
|
|
36
|
+
expect(matcher._matches?("$gte" => 5)).to be true
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -44,7 +44,7 @@ describe Mongoid::Matchable::Gte do
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it "returns false" do
|
|
47
|
-
expect(matcher.
|
|
47
|
+
expect(matcher._matches?("$gte" => 5)).to be false
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
@@ -55,7 +55,7 @@ describe Mongoid::Matchable::Gte do
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it "returns false" do
|
|
58
|
-
expect(matcher.
|
|
58
|
+
expect(matcher._matches?("$gte" => 5)).to be true
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
|
|
@@ -65,7 +65,7 @@ describe Mongoid::Matchable::Gte do
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "returns false" do
|
|
68
|
-
expect(matcher.
|
|
68
|
+
expect(matcher._matches?("$gte" => 5)).to be false
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
end
|
|
@@ -77,7 +77,7 @@ describe Mongoid::Matchable::Gte do
|
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
it "returns false" do
|
|
80
|
-
expect(matcher.
|
|
80
|
+
expect(matcher._matches?("$gte" => '4.9')).to be false
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
83
|
end
|
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe Mongoid::Matchable::In do
|
|
4
4
|
|
|
5
|
-
describe "#
|
|
5
|
+
describe "#_matches\?" do
|
|
6
6
|
|
|
7
7
|
context 'when the attribute is not nil' do
|
|
8
8
|
|
|
@@ -13,14 +13,14 @@ describe Mongoid::Matchable::In do
|
|
|
13
13
|
context "when the values include the attribute" do
|
|
14
14
|
|
|
15
15
|
it "returns true" do
|
|
16
|
-
expect(matcher.
|
|
16
|
+
expect(matcher._matches?("$in" => [/\Afir.*\z/, "second"])).to be true
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
context "when the values don't include the attribute" do
|
|
21
21
|
|
|
22
22
|
it "returns false" do
|
|
23
|
-
expect(matcher.
|
|
23
|
+
expect(matcher._matches?("$in" => ["third"])).to be false
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -34,14 +34,14 @@ describe Mongoid::Matchable::In do
|
|
|
34
34
|
context "when the values include the attribute" do
|
|
35
35
|
|
|
36
36
|
it "returns true" do
|
|
37
|
-
expect(matcher.
|
|
37
|
+
expect(matcher._matches?("$in" => [/\Afir.*\z/, nil])).to be true
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
context "when the values don't include the attribute" do
|
|
42
42
|
|
|
43
43
|
it "returns false" do
|
|
44
|
-
expect(matcher.
|
|
44
|
+
expect(matcher._matches?("$in" => ["third"])).to be false
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
end
|
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe Mongoid::Matchable::Lt do
|
|
4
4
|
|
|
5
|
-
describe "#
|
|
5
|
+
describe "#_matches\?" do
|
|
6
6
|
|
|
7
7
|
context "when the value is larger" do
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ describe Mongoid::Matchable::Lt do
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
it "returns false" do
|
|
14
|
-
expect(matcher.
|
|
14
|
+
expect(matcher._matches?("$lt" => 3)).to be false
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -22,7 +22,7 @@ describe Mongoid::Matchable::Lt do
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it "returns false" do
|
|
25
|
-
expect(matcher.
|
|
25
|
+
expect(matcher._matches?("$lt" => 3)).to be false
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -33,7 +33,7 @@ describe Mongoid::Matchable::Lt do
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "returns true" do
|
|
36
|
-
expect(matcher.
|
|
36
|
+
expect(matcher._matches?("$lt" => 10)).to be true
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -44,7 +44,7 @@ describe Mongoid::Matchable::Lt do
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it "returns false" do
|
|
47
|
-
expect(matcher.
|
|
47
|
+
expect(matcher._matches?("$lt" => 5)).to be false
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
@@ -55,7 +55,7 @@ describe Mongoid::Matchable::Lt do
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it "returns true" do
|
|
58
|
-
expect(matcher.
|
|
58
|
+
expect(matcher._matches?("$lt" => 5)).to be true
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
|
|
@@ -65,7 +65,7 @@ describe Mongoid::Matchable::Lt do
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "returns false" do
|
|
68
|
-
expect(matcher.
|
|
68
|
+
expect(matcher._matches?("$lt" => 5)).to be false
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
end
|
|
@@ -78,7 +78,7 @@ describe Mongoid::Matchable::Lt do
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
it "returns false" do
|
|
81
|
-
expect(matcher.
|
|
81
|
+
expect(matcher._matches?("$lt" => '5.1')).to be false
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
end
|
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe Mongoid::Matchable::Lte do
|
|
4
4
|
|
|
5
|
-
describe "#
|
|
5
|
+
describe "#_matches\?" do
|
|
6
6
|
|
|
7
7
|
context "when the value is larger" do
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ describe Mongoid::Matchable::Lte do
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
it "returns false" do
|
|
14
|
-
expect(matcher.
|
|
14
|
+
expect(matcher._matches?("$lte" => 3)).to be false
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -22,7 +22,7 @@ describe Mongoid::Matchable::Lte do
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it "returns true" do
|
|
25
|
-
expect(matcher.
|
|
25
|
+
expect(matcher._matches?("$lte" => 10)).to be true
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -33,7 +33,7 @@ describe Mongoid::Matchable::Lte do
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
it "returns true" do
|
|
36
|
-
expect(matcher.
|
|
36
|
+
expect(matcher._matches?("$lte" => 5)).to be true
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -44,7 +44,7 @@ describe Mongoid::Matchable::Lte do
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it "returns false" do
|
|
47
|
-
expect(matcher.
|
|
47
|
+
expect(matcher._matches?("$lte" => 5)).to be false
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
@@ -56,7 +56,7 @@ describe Mongoid::Matchable::Lte do
|
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
it "returns true" do
|
|
59
|
-
expect(matcher.
|
|
59
|
+
expect(matcher._matches?("$lte" => 5)).to be true
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
@@ -66,7 +66,7 @@ describe Mongoid::Matchable::Lte do
|
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
it "returns false" do
|
|
69
|
-
expect(matcher.
|
|
69
|
+
expect(matcher._matches?("$lte" => 5)).to be false
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
end
|
|
@@ -78,7 +78,7 @@ describe Mongoid::Matchable::Lte do
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
it "returns false" do
|
|
81
|
-
expect(matcher.
|
|
81
|
+
expect(matcher._matches?("$lte" => '5.1')).to be false
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
end
|
|
@@ -6,19 +6,19 @@ describe Mongoid::Matchable::Ne do
|
|
|
6
6
|
described_class.new("first")
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
describe "#
|
|
9
|
+
describe "#_matches?" do
|
|
10
10
|
|
|
11
11
|
context "when the values are not equal" do
|
|
12
12
|
|
|
13
13
|
it "returns true" do
|
|
14
|
-
expect(matcher.
|
|
14
|
+
expect(matcher._matches?("$ne" => "second")).to be true
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
context "when the values are equal" do
|
|
19
19
|
|
|
20
20
|
it "returns false" do
|
|
21
|
-
expect(matcher.
|
|
21
|
+
expect(matcher._matches?("$ne" => "first")).to be false
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -31,14 +31,14 @@ describe Mongoid::Matchable::Ne do
|
|
|
31
31
|
context "when the value is in the array" do
|
|
32
32
|
|
|
33
33
|
it "returns false" do
|
|
34
|
-
expect(array_matcher.
|
|
34
|
+
expect(array_matcher._matches?("$ne" => "first")).to be false
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
context "when the value is not in the array" do
|
|
39
39
|
|
|
40
40
|
it "returns true" do
|
|
41
|
-
expect(array_matcher.
|
|
41
|
+
expect(array_matcher._matches?("$ne" => "second")).to be true
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
end
|
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe Mongoid::Matchable::Nin do
|
|
4
4
|
|
|
5
|
-
describe "#
|
|
5
|
+
describe "#_matches?" do
|
|
6
6
|
|
|
7
7
|
context 'when the attribute is not nil' do
|
|
8
8
|
|
|
@@ -13,14 +13,14 @@ describe Mongoid::Matchable::Nin do
|
|
|
13
13
|
context "when the values do not contain the attribute" do
|
|
14
14
|
|
|
15
15
|
it "returns true" do
|
|
16
|
-
expect(matcher.
|
|
16
|
+
expect(matcher._matches?("$nin" => ["second", "third"])).to be true
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
context "when the values contain the attribute" do
|
|
21
21
|
|
|
22
22
|
it "returns false" do
|
|
23
|
-
expect(matcher.
|
|
23
|
+
expect(matcher._matches?("$nin" => ["first"])).to be false
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -33,14 +33,14 @@ describe Mongoid::Matchable::Nin do
|
|
|
33
33
|
context "when the values do not contain the attribute" do
|
|
34
34
|
|
|
35
35
|
it "returns true" do
|
|
36
|
-
expect(matcher.
|
|
36
|
+
expect(matcher._matches?("$nin" => ["third"])).to be true
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
context "when the values contain the attribute" do
|
|
41
41
|
|
|
42
42
|
it "returns false" do
|
|
43
|
-
expect(matcher.
|
|
43
|
+
expect(matcher._matches?("$nin" => [/\Afir.*\z/, nil])).to be false
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
end
|
|
@@ -10,14 +10,14 @@ describe Mongoid::Matchable::Or 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
|
|
|
17
17
|
context "when any of the values are equal" do
|
|
18
18
|
|
|
19
19
|
let(:matches) do
|
|
20
|
-
matcher.
|
|
20
|
+
matcher._matches?(
|
|
21
21
|
[ { title: "Sir" }, { title: "King" } ]
|
|
22
22
|
)
|
|
23
23
|
end
|
|
@@ -34,14 +34,14 @@ describe Mongoid::Matchable::Or do
|
|
|
34
34
|
context "when none of the values are equal" do
|
|
35
35
|
|
|
36
36
|
it "returns false" do
|
|
37
|
-
expect(matcher.
|
|
37
|
+
expect(matcher._matches?([])).to be false
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
context "when the expression is a $not" do
|
|
42
42
|
|
|
43
43
|
let(:matches) do
|
|
44
|
-
matcher.
|
|
44
|
+
matcher._matches?([ { title: {:$not => /Foobar/ } }])
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
context "when the value matches" do
|
|
@@ -69,7 +69,7 @@ describe Mongoid::Matchable::Or do
|
|
|
69
69
|
context "when any of the values are equal" do
|
|
70
70
|
|
|
71
71
|
let(:matches) do
|
|
72
|
-
matcher.
|
|
72
|
+
matcher._matches?(
|
|
73
73
|
[
|
|
74
74
|
{ title: { "$in" => [ "Sir", "Madam" ] } },
|
|
75
75
|
{ title: "King" }
|
|
@@ -89,7 +89,7 @@ describe Mongoid::Matchable::Or do
|
|
|
89
89
|
context "when none of the values are equal" do
|
|
90
90
|
|
|
91
91
|
let(:matches) do
|
|
92
|
-
matcher.
|
|
92
|
+
matcher._matches?(
|
|
93
93
|
[
|
|
94
94
|
{ title: { "$in" => [ "Prince", "Madam" ] } },
|
|
95
95
|
{ title: "King" }
|
|
@@ -109,7 +109,7 @@ describe Mongoid::Matchable::Or do
|
|
|
109
109
|
context "when expression contain multiple fields" do
|
|
110
110
|
|
|
111
111
|
let(:matches) do
|
|
112
|
-
matcher.
|
|
112
|
+
matcher._matches?(
|
|
113
113
|
[
|
|
114
114
|
{ title: "Sir", age: 23 },
|
|
115
115
|
{ title: "King", age: 100 }
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Mongoid::Matchable::Regexp do
|
|
4
|
+
|
|
5
|
+
let(:matcher) do
|
|
6
|
+
described_class.new(attribute)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
let(:attribute) do
|
|
10
|
+
'Emily'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '#_matches?' do
|
|
14
|
+
|
|
15
|
+
context 'when a BSON::Regexp::Raw object is passed' do
|
|
16
|
+
|
|
17
|
+
let(:regexp) do
|
|
18
|
+
BSON::Regexp::Raw.new('^Em')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'compiles the regexp object to a native regexp for the matching' do
|
|
22
|
+
expect(matcher._matches?(regexp)).to be(true)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context 'when the value does not match the attribute' do
|
|
26
|
+
|
|
27
|
+
let(:attribute) do
|
|
28
|
+
'ily'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'compiles the regexp object to a native regexp for the matching' do
|
|
32
|
+
expect(matcher._matches?(regexp)).to be(false)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context 'when a native Regexp object is passed' do
|
|
38
|
+
|
|
39
|
+
let(:regexp) do
|
|
40
|
+
/^Em/
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'calls super with the native regexp' do
|
|
44
|
+
expect(matcher._matches?(regexp)).to be(true)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context 'when the value does not match the attribute' do
|
|
48
|
+
|
|
49
|
+
let(:attribute) do
|
|
50
|
+
'ily'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'compiles the regexp object to a native regexp for the matching' do
|
|
54
|
+
expect(matcher._matches?(regexp)).to be(false)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -6,19 +6,19 @@ describe Mongoid::Matchable::Size do
|
|
|
6
6
|
described_class.new(["first", "second"])
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
describe "#
|
|
9
|
+
describe "#_matches?" do
|
|
10
10
|
|
|
11
11
|
context "when the attribute is the same size" do
|
|
12
12
|
|
|
13
13
|
it "returns true" do
|
|
14
|
-
expect(matcher.
|
|
14
|
+
expect(matcher._matches?("$size" => 2)).to be true
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
context "when the attribute is not the same size" do
|
|
19
19
|
|
|
20
20
|
it "returns false" do
|
|
21
|
-
expect(matcher.
|
|
21
|
+
expect(matcher._matches?("$size" => 5)).to be false
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|