mongoid 5.4.1 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,59 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe BigDecimal do
|
4
|
+
|
5
|
+
describe ".evolve" do
|
6
|
+
|
7
|
+
context "when provided a big decimal" do
|
8
|
+
|
9
|
+
let(:big_decimal) do
|
10
|
+
BigDecimal.new("123456.789")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns the decimal as a string" do
|
14
|
+
expect(described_class.evolve(big_decimal)).to eq(big_decimal.to_s)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when provided a non big decimal" do
|
19
|
+
|
20
|
+
it "returns the object as a string" do
|
21
|
+
expect(described_class.evolve("testing")).to eq("testing")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when provided an array of big decimals" do
|
26
|
+
|
27
|
+
let(:bd_one) do
|
28
|
+
BigDecimal.new("123456.789")
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:bd_two) do
|
32
|
+
BigDecimal.new("123333.789")
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:array) do
|
36
|
+
[ bd_one, bd_two ]
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:evolved) do
|
40
|
+
described_class.evolve(array)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns the array as strings" do
|
44
|
+
expect(evolved).to eq([ bd_one.to_s, bd_two.to_s ])
|
45
|
+
end
|
46
|
+
|
47
|
+
it "does not evolve in place" do
|
48
|
+
expect(evolved).to_not equal(array)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when provided nil" do
|
53
|
+
|
54
|
+
it "returns nil" do
|
55
|
+
expect(described_class.evolve(nil)).to be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Bignum do
|
4
|
+
|
5
|
+
describe ".evolve" do
|
6
|
+
|
7
|
+
context "when provided a string" do
|
8
|
+
|
9
|
+
context "when the string is a number" do
|
10
|
+
|
11
|
+
context "when the string is an bignum" do
|
12
|
+
|
13
|
+
it "returns an bignum" do
|
14
|
+
expect(described_class.evolve("1")).to eq(1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when the string is a float" do
|
19
|
+
|
20
|
+
it "converts it to a float" do
|
21
|
+
expect(described_class.evolve("2.23")).to eq(2.23)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when the string is not a number" do
|
27
|
+
|
28
|
+
it "returns the string" do
|
29
|
+
expect(described_class.evolve("testing")).to eq("testing")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when provided a number" do
|
36
|
+
|
37
|
+
context "when the number is an bignum" do
|
38
|
+
|
39
|
+
it "returns an bignum" do
|
40
|
+
expect(described_class.evolve(1)).to eq(1)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when the number is a float" do
|
45
|
+
|
46
|
+
it "returns the float" do
|
47
|
+
expect(described_class.evolve(2.23)).to eq(2.23)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when provided nil" do
|
53
|
+
|
54
|
+
it "returns nil" do
|
55
|
+
expect(described_class.evolve(nil)).to be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,213 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Boolean do
|
4
|
+
|
5
|
+
describe ".evolve" do
|
6
|
+
|
7
|
+
context "when provided a boolean" do
|
8
|
+
|
9
|
+
context "when provided true" do
|
10
|
+
|
11
|
+
it "returns true" do
|
12
|
+
expect(described_class.evolve(true)).to eq(true)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when provided false" do
|
17
|
+
|
18
|
+
it "returns false" do
|
19
|
+
expect(described_class.evolve(false)).to eq(false)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when provided a string" do
|
25
|
+
|
26
|
+
context "when provided true" do
|
27
|
+
|
28
|
+
it "returns true" do
|
29
|
+
expect(described_class.evolve("true")).to eq(true)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when provided t" do
|
34
|
+
|
35
|
+
it "returns true" do
|
36
|
+
expect(described_class.evolve("t")).to eq(true)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when provided 1" do
|
41
|
+
|
42
|
+
it "returns true" do
|
43
|
+
expect(described_class.evolve("1")).to eq(true)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when provided 1.0" do
|
48
|
+
|
49
|
+
it "returns true" do
|
50
|
+
expect(described_class.evolve("1.0")).to eq(true)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when provided yes" do
|
55
|
+
|
56
|
+
it "returns true" do
|
57
|
+
expect(described_class.evolve("yes")).to eq(true)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when provided y" do
|
62
|
+
|
63
|
+
it "returns true" do
|
64
|
+
expect(described_class.evolve("y")).to eq(true)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when provided false" do
|
69
|
+
|
70
|
+
it "returns false" do
|
71
|
+
expect(described_class.evolve("false")).to eq(false)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when provided f" do
|
76
|
+
|
77
|
+
it "returns false" do
|
78
|
+
expect(described_class.evolve("f")).to eq(false)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when provided 0" do
|
83
|
+
|
84
|
+
it "returns false" do
|
85
|
+
expect(described_class.evolve("0")).to eq(false)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "when provided 0.0" do
|
90
|
+
|
91
|
+
it "returns false" do
|
92
|
+
expect(described_class.evolve("0.0")).to eq(false)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when provided no" do
|
97
|
+
|
98
|
+
it "returns false" do
|
99
|
+
expect(described_class.evolve("no")).to eq(false)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "when provided n" do
|
104
|
+
|
105
|
+
it "returns false" do
|
106
|
+
expect(described_class.evolve("n")).to eq(false)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "when provided an array" do
|
113
|
+
|
114
|
+
context "when provided a string" do
|
115
|
+
|
116
|
+
context "when provided true" do
|
117
|
+
|
118
|
+
let(:array) do
|
119
|
+
[ "true" ]
|
120
|
+
end
|
121
|
+
|
122
|
+
let(:evolved) do
|
123
|
+
described_class.evolve(array)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "returns true" do
|
127
|
+
expect(evolved).to eq([ true ])
|
128
|
+
end
|
129
|
+
|
130
|
+
it "does not evolve in place" do
|
131
|
+
expect(evolved).to_not equal(array)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "when provided t" do
|
136
|
+
|
137
|
+
it "returns true" do
|
138
|
+
expect(described_class.evolve([ "t" ])).to eq([ true ])
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context "when provided 1" do
|
143
|
+
|
144
|
+
it "returns true" do
|
145
|
+
expect(described_class.evolve([ "1" ])).to eq([ true ])
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "when provided 1.0" do
|
150
|
+
|
151
|
+
it "returns true" do
|
152
|
+
expect(described_class.evolve([ "1.0" ])).to eq([ true ])
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when provided yes" do
|
157
|
+
|
158
|
+
it "returns true" do
|
159
|
+
expect(described_class.evolve([ "yes" ])).to eq([ true ])
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context "when provided y" do
|
164
|
+
|
165
|
+
it "returns true" do
|
166
|
+
expect(described_class.evolve([ "y" ])).to eq([ true ])
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context "when provided false" do
|
171
|
+
|
172
|
+
it "returns false" do
|
173
|
+
expect(described_class.evolve([ "false" ])).to eq([ false ])
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context "when provided f" do
|
178
|
+
|
179
|
+
it "returns false" do
|
180
|
+
expect(described_class.evolve([ "f" ])).to eq([ false ])
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "when provided 0" do
|
185
|
+
|
186
|
+
it "returns false" do
|
187
|
+
expect(described_class.evolve([ "0" ])).to eq([ false ])
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context "when provided 0.0" do
|
192
|
+
|
193
|
+
it "returns false" do
|
194
|
+
expect(described_class.evolve([ "0.0" ])).to eq([ false ])
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "when provided no" do
|
199
|
+
|
200
|
+
it "returns false" do
|
201
|
+
expect(described_class.evolve([ "no" ])).to eq([ false ])
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context "when provided n" do
|
206
|
+
|
207
|
+
it "returns false" do
|
208
|
+
expect(described_class.evolve([ "n" ])).to eq([ false ])
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
@@ -0,0 +1,330 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Date do
|
4
|
+
|
5
|
+
describe "#__evolve_date__" do
|
6
|
+
|
7
|
+
let(:date) do
|
8
|
+
Date.new(2010, 1, 1)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:evolved) do
|
12
|
+
date.__evolve_date__
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:expected) do
|
16
|
+
Time.utc(2010, 1, 1, 0, 0, 0)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the time" do
|
20
|
+
expect(evolved).to eq(expected)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#__evolve_time__" do
|
25
|
+
|
26
|
+
let(:date) do
|
27
|
+
Date.new(2010, 1, 1)
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:evolved) do
|
31
|
+
date.__evolve_time__
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:expected) do
|
35
|
+
Time.local(2010, 1, 1, 0, 0, 0)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns the time" do
|
39
|
+
expect(evolved).to eq(expected)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".evolve" do
|
44
|
+
|
45
|
+
context "when provided a date" do
|
46
|
+
|
47
|
+
let(:date) do
|
48
|
+
Date.new(2010, 1, 1)
|
49
|
+
end
|
50
|
+
|
51
|
+
let(:evolved) do
|
52
|
+
described_class.evolve(date)
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:expected) do
|
56
|
+
Time.utc(2010, 1, 1, 0, 0, 0)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns the time" do
|
60
|
+
expect(evolved).to eq(expected)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when provided an array" do
|
65
|
+
|
66
|
+
context "when the array is composed of dates" do
|
67
|
+
|
68
|
+
let(:date) do
|
69
|
+
Date.new(2010, 1, 1)
|
70
|
+
end
|
71
|
+
|
72
|
+
let(:evolved) do
|
73
|
+
described_class.evolve([ date ])
|
74
|
+
end
|
75
|
+
|
76
|
+
let(:expected) do
|
77
|
+
Time.utc(2010, 1, 1, 0, 0, 0, 0)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns the array with evolved times" do
|
81
|
+
expect(evolved).to eq([ expected ])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when the array is composed of strings" do
|
86
|
+
|
87
|
+
let(:date) do
|
88
|
+
Date.parse("1st Jan 2010")
|
89
|
+
end
|
90
|
+
|
91
|
+
let(:evolved) do
|
92
|
+
described_class.evolve([ date.to_s ])
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns the strings as a times" do
|
96
|
+
expect(evolved).to eq([ Time.new(2010, 1, 1, 0, 0, 0, 0).utc ])
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "when the array is composed of integers" do
|
101
|
+
|
102
|
+
let(:time) do
|
103
|
+
Time.utc(2010, 1, 1, 0, 0, 0, 0)
|
104
|
+
end
|
105
|
+
|
106
|
+
let(:integer) do
|
107
|
+
time.to_i
|
108
|
+
end
|
109
|
+
|
110
|
+
let(:evolved) do
|
111
|
+
described_class.evolve([ integer ])
|
112
|
+
end
|
113
|
+
|
114
|
+
let(:expected) do
|
115
|
+
Time.at(integer)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "returns the integers as times" do
|
119
|
+
expect(evolved).to eq([ time ])
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when the array is composed of floats" do
|
124
|
+
|
125
|
+
let(:time) do
|
126
|
+
Time.utc(2010, 1, 1, 0, 0, 0, 0)
|
127
|
+
end
|
128
|
+
|
129
|
+
let(:float) do
|
130
|
+
time.to_f
|
131
|
+
end
|
132
|
+
|
133
|
+
let(:evolved) do
|
134
|
+
described_class.evolve([ float ])
|
135
|
+
end
|
136
|
+
|
137
|
+
let(:expected) do
|
138
|
+
Time.at(float)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "returns the floats as times" do
|
142
|
+
expect(evolved).to eq([ time ])
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "when provided a range" do
|
148
|
+
|
149
|
+
context "when the range are dates" do
|
150
|
+
|
151
|
+
let(:min) do
|
152
|
+
Date.new(2010, 1, 1)
|
153
|
+
end
|
154
|
+
|
155
|
+
let(:max) do
|
156
|
+
Date.new(2010, 1, 3)
|
157
|
+
end
|
158
|
+
|
159
|
+
let(:evolved) do
|
160
|
+
described_class.evolve(min..max)
|
161
|
+
end
|
162
|
+
|
163
|
+
let(:expected_min) do
|
164
|
+
Time.utc(2010, 1, 1, 0, 0, 0, 0)
|
165
|
+
end
|
166
|
+
|
167
|
+
let(:expected_max) do
|
168
|
+
Time.utc(2010, 1, 3, 0, 0, 0, 0)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "returns a selection of times" do
|
172
|
+
expect(evolved).to eq(
|
173
|
+
{ "$gte" => expected_min, "$lte" => expected_max }
|
174
|
+
)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "when the range are strings" do
|
179
|
+
|
180
|
+
let(:min) do
|
181
|
+
Date.new(2010, 1, 1)
|
182
|
+
end
|
183
|
+
|
184
|
+
let(:max) do
|
185
|
+
Date.new(2010, 1, 3)
|
186
|
+
end
|
187
|
+
|
188
|
+
let(:evolved) do
|
189
|
+
described_class.evolve(min.to_s..max.to_s)
|
190
|
+
end
|
191
|
+
|
192
|
+
let(:expected_min) do
|
193
|
+
Time.utc(2010, 1, 1, 0, 0, 0, 0)
|
194
|
+
end
|
195
|
+
|
196
|
+
let(:expected_max) do
|
197
|
+
Time.utc(2010, 1, 3, 0, 0, 0, 0)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "returns a selection of times" do
|
201
|
+
expect(evolved).to eq(
|
202
|
+
{ "$gte" => expected_min, "$lte" => expected_max }
|
203
|
+
)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context "when the range is floats" do
|
208
|
+
|
209
|
+
let(:min_time) do
|
210
|
+
Time.utc(2010, 1, 1, 0, 0, 0, 0)
|
211
|
+
end
|
212
|
+
|
213
|
+
let(:max_time) do
|
214
|
+
Time.utc(2010, 1, 3, 0, 0, 0, 0)
|
215
|
+
end
|
216
|
+
|
217
|
+
let(:min) do
|
218
|
+
min_time.to_f
|
219
|
+
end
|
220
|
+
|
221
|
+
let(:max) do
|
222
|
+
max_time.to_f
|
223
|
+
end
|
224
|
+
|
225
|
+
let(:evolved) do
|
226
|
+
described_class.evolve(min..max)
|
227
|
+
end
|
228
|
+
|
229
|
+
it "returns a selection of times" do
|
230
|
+
expect(evolved).to eq(
|
231
|
+
{ "$gte" => min_time, "$lte" => max_time }
|
232
|
+
)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context "when the range is integers" do
|
237
|
+
|
238
|
+
let(:min_time) do
|
239
|
+
Time.utc(2010, 1, 1, 0, 0, 0, 0)
|
240
|
+
end
|
241
|
+
|
242
|
+
let(:max_time) do
|
243
|
+
Time.utc(2010, 1, 3, 0, 0, 0, 0)
|
244
|
+
end
|
245
|
+
|
246
|
+
let(:min) do
|
247
|
+
min_time.to_i
|
248
|
+
end
|
249
|
+
|
250
|
+
let(:max) do
|
251
|
+
max_time.to_i
|
252
|
+
end
|
253
|
+
|
254
|
+
let(:evolved) do
|
255
|
+
described_class.evolve(min..max)
|
256
|
+
end
|
257
|
+
|
258
|
+
it "returns a selection of times" do
|
259
|
+
expect(evolved).to eq(
|
260
|
+
{ "$gte" => min_time, "$lte" => max_time }
|
261
|
+
)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
context "when provided a string" do
|
267
|
+
|
268
|
+
let(:date) do
|
269
|
+
Date.parse("1st Jan 2010")
|
270
|
+
end
|
271
|
+
|
272
|
+
let(:evolved) do
|
273
|
+
described_class.evolve(date.to_s)
|
274
|
+
end
|
275
|
+
|
276
|
+
let(:expected) do
|
277
|
+
Time.utc(2010, 1, 1, 0, 0, 0, 0)
|
278
|
+
end
|
279
|
+
|
280
|
+
it "returns the string as a time" do
|
281
|
+
expect(evolved).to eq(expected)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
context "when provided a float" do
|
286
|
+
|
287
|
+
let(:time) do
|
288
|
+
Time.utc(2010, 1, 1, 0, 0, 0, 0)
|
289
|
+
end
|
290
|
+
|
291
|
+
let(:float) do
|
292
|
+
time.to_f
|
293
|
+
end
|
294
|
+
|
295
|
+
let(:evolved) do
|
296
|
+
described_class.evolve(float)
|
297
|
+
end
|
298
|
+
|
299
|
+
it "returns the float as a time" do
|
300
|
+
expect(evolved).to eq(time)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context "when provided an integer" do
|
305
|
+
|
306
|
+
let(:time) do
|
307
|
+
Time.utc(2010, 1, 1, 0, 0, 0, 0)
|
308
|
+
end
|
309
|
+
|
310
|
+
let(:integer) do
|
311
|
+
time.to_i
|
312
|
+
end
|
313
|
+
|
314
|
+
let(:evolved) do
|
315
|
+
described_class.evolve(integer)
|
316
|
+
end
|
317
|
+
|
318
|
+
it "returns the integer as a time" do
|
319
|
+
expect(evolved).to eq(time)
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
context "when provided nil" do
|
324
|
+
|
325
|
+
it "returns nil" do
|
326
|
+
expect(described_class.evolve(nil)).to be_nil
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|