mongoid 8.0.1 → 8.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/config/locales/en.yml +1 -0
- data/lib/mongoid/association/accessors.rb +6 -6
- data/lib/mongoid/association/bindable.rb +2 -2
- data/lib/mongoid/association/constrainable.rb +0 -1
- data/lib/mongoid/association/embedded/batchable.rb +5 -5
- data/lib/mongoid/association/embedded/cyclic.rb +1 -1
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +10 -10
- data/lib/mongoid/association/embedded/embeds_many.rb +2 -2
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +2 -2
- data/lib/mongoid/association/embedded/embeds_one.rb +3 -3
- data/lib/mongoid/association/many.rb +6 -7
- data/lib/mongoid/association/nested/many.rb +3 -3
- data/lib/mongoid/association/nested/nested_buildable.rb +4 -4
- data/lib/mongoid/association/nested/one.rb +5 -5
- data/lib/mongoid/association/one.rb +2 -2
- data/lib/mongoid/association/options.rb +9 -9
- data/lib/mongoid/association/proxy.rb +2 -3
- data/lib/mongoid/association/referenced/auto_save.rb +1 -1
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +5 -6
- data/lib/mongoid/association/referenced/belongs_to.rb +1 -1
- data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
- data/lib/mongoid/association/referenced/eager.rb +2 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +2 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +2 -2
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +10 -10
- data/lib/mongoid/association/referenced/has_many/proxy.rb +12 -9
- data/lib/mongoid/association/referenced/has_many.rb +3 -3
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +5 -5
- data/lib/mongoid/association/referenced/has_one/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/has_one.rb +3 -3
- data/lib/mongoid/association/referenced/syncable.rb +2 -2
- data/lib/mongoid/association/reflections.rb +2 -2
- data/lib/mongoid/association/relatable.rb +6 -6
- data/lib/mongoid/association.rb +5 -5
- data/lib/mongoid/atomic/modifiers.rb +2 -2
- data/lib/mongoid/attributes/dynamic.rb +3 -3
- data/lib/mongoid/attributes/nested.rb +5 -5
- data/lib/mongoid/attributes/processing.rb +1 -1
- data/lib/mongoid/attributes/projector.rb +1 -1
- data/lib/mongoid/attributes/readonly.rb +2 -2
- data/lib/mongoid/attributes.rb +13 -13
- data/lib/mongoid/cacheable.rb +2 -2
- data/lib/mongoid/changeable.rb +5 -5
- data/lib/mongoid/clients/options.rb +1 -1
- data/lib/mongoid/clients/validators/storage.rb +3 -3
- data/lib/mongoid/config/validators/client.rb +6 -6
- data/lib/mongoid/config.rb +7 -7
- data/lib/mongoid/contextual/aggregable/memory.rb +1 -1
- data/lib/mongoid/contextual/aggregable/mongo.rb +4 -4
- data/lib/mongoid/contextual/aggregable/none.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/geo_near.rb +7 -7
- data/lib/mongoid/contextual/memory.rb +5 -5
- data/lib/mongoid/contextual/mongo.rb +14 -14
- data/lib/mongoid/contextual/none.rb +2 -2
- data/lib/mongoid/contextual/queryable.rb +1 -1
- data/lib/mongoid/contextual.rb +2 -2
- data/lib/mongoid/criteria/findable.rb +7 -4
- data/lib/mongoid/criteria/includable.rb +1 -1
- data/lib/mongoid/criteria/permission.rb +1 -1
- data/lib/mongoid/criteria/queryable/aggregable.rb +2 -2
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +2 -2
- data/lib/mongoid/criteria/queryable/extensions/set.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/string.rb +3 -3
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +1 -1
- data/lib/mongoid/criteria/queryable/key.rb +3 -3
- data/lib/mongoid/criteria/queryable/optional.rb +2 -2
- data/lib/mongoid/criteria/queryable/options.rb +1 -1
- data/lib/mongoid/criteria/queryable/pipeline.rb +1 -1
- data/lib/mongoid/criteria/queryable/selectable.rb +3 -3
- data/lib/mongoid/criteria/queryable/selector.rb +3 -3
- data/lib/mongoid/criteria/queryable/smash.rb +1 -1
- data/lib/mongoid/criteria/queryable.rb +1 -1
- data/lib/mongoid/criteria/scopable.rb +2 -2
- data/lib/mongoid/criteria.rb +14 -9
- data/lib/mongoid/deprecable.rb +1 -1
- data/lib/mongoid/document.rb +2 -2
- data/lib/mongoid/equality.rb +12 -12
- data/lib/mongoid/errors/document_not_found.rb +5 -5
- data/lib/mongoid/errors/invalid_config_option.rb +1 -1
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +1 -1
- data/lib/mongoid/errors/invalid_field.rb +1 -1
- data/lib/mongoid/errors/invalid_relation.rb +1 -1
- data/lib/mongoid/errors/invalid_relation_option.rb +1 -1
- data/lib/mongoid/errors/invalid_session_use.rb +1 -1
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
- data/lib/mongoid/errors/mongoid_error.rb +3 -3
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -1
- data/lib/mongoid/errors/no_client_database.rb +1 -1
- data/lib/mongoid/errors/no_client_hosts.rb +1 -1
- data/lib/mongoid/errors/readonly_attribute.rb +1 -1
- data/lib/mongoid/errors/unknown_attribute.rb +1 -1
- data/lib/mongoid/extensions/array.rb +1 -1
- data/lib/mongoid/extensions/big_decimal.rb +4 -0
- data/lib/mongoid/extensions/false_class.rb +1 -1
- data/lib/mongoid/extensions/float.rb +6 -2
- data/lib/mongoid/extensions/hash.rb +1 -1
- data/lib/mongoid/extensions/integer.rb +6 -2
- data/lib/mongoid/extensions/module.rb +1 -1
- data/lib/mongoid/extensions/object.rb +6 -6
- data/lib/mongoid/extensions/string.rb +9 -9
- data/lib/mongoid/extensions/symbol.rb +1 -1
- data/lib/mongoid/extensions/true_class.rb +1 -1
- data/lib/mongoid/fields/foreign_key.rb +4 -4
- data/lib/mongoid/fields/localized.rb +9 -4
- data/lib/mongoid/fields/standard.rb +7 -7
- data/lib/mongoid/fields.rb +9 -9
- data/lib/mongoid/findable.rb +7 -6
- data/lib/mongoid/indexable/specification.rb +1 -1
- data/lib/mongoid/indexable/validators/options.rb +2 -1
- data/lib/mongoid/interceptable.rb +4 -4
- data/lib/mongoid/matchable.rb +1 -1
- data/lib/mongoid/matcher.rb +12 -7
- data/lib/mongoid/persistable/creatable.rb +4 -4
- data/lib/mongoid/persistable/deletable.rb +1 -1
- data/lib/mongoid/persistable/destroyable.rb +1 -1
- data/lib/mongoid/persistable/savable.rb +2 -2
- data/lib/mongoid/persistable/unsettable.rb +1 -1
- data/lib/mongoid/persistable/updatable.rb +7 -7
- data/lib/mongoid/persistable/upsertable.rb +1 -1
- data/lib/mongoid/persistable.rb +3 -3
- data/lib/mongoid/persistence_context.rb +44 -8
- data/lib/mongoid/query_cache.rb +2 -2
- data/lib/mongoid/scopable.rb +26 -22
- data/lib/mongoid/serializable.rb +10 -6
- data/lib/mongoid/stateful.rb +10 -10
- data/lib/mongoid/tasks/database.rb +0 -2
- data/lib/mongoid/threaded/lifecycle.rb +5 -5
- data/lib/mongoid/threaded.rb +12 -12
- data/lib/mongoid/timestamps/updated.rb +1 -1
- data/lib/mongoid/traversable.rb +3 -3
- data/lib/mongoid/validatable/localizable.rb +1 -1
- data/lib/mongoid/validatable/macros.rb +0 -2
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +7 -7
- data/lib/mongoid/validatable.rb +6 -6
- data/lib/mongoid/version.rb +1 -1
- data/spec/integration/i18n_fallbacks_spec.rb +1 -17
- data/spec/mongoid/cacheable_spec.rb +3 -3
- data/spec/mongoid/clients_spec.rb +25 -0
- data/spec/mongoid/contextual/memory_spec.rb +4 -5
- data/spec/mongoid/contextual/mongo_spec.rb +2 -4
- data/spec/mongoid/criteria_projection_spec.rb +0 -1
- data/spec/mongoid/criteria_spec.rb +1 -1
- data/spec/mongoid/equality_spec.rb +12 -12
- data/spec/mongoid/extensions/big_decimal_spec.rb +15 -0
- data/spec/mongoid/extensions/float_spec.rb +10 -3
- data/spec/mongoid/extensions/integer_spec.rb +10 -3
- data/spec/mongoid/fields/localized_spec.rb +37 -12
- data/spec/mongoid/indexable_spec.rb +23 -1
- data/spec/mongoid/scopable_spec.rb +34 -16
- data/spec/mongoid/validatable/uniqueness_spec.rb +0 -1
- data/spec/support/macros.rb +16 -0
- data.tar.gz.sig +0 -0
- metadata +643 -643
- metadata.gz.sig +0 -0
@@ -74,7 +74,7 @@ module Mongoid
|
|
74
74
|
# @example Is the validation case sensitive?
|
75
75
|
# validator.case_sensitive?
|
76
76
|
#
|
77
|
-
# @return [ true
|
77
|
+
# @return [ true | false ] If the validation is case sensitive.
|
78
78
|
def case_sensitive?
|
79
79
|
!(options[:case_sensitive] == false)
|
80
80
|
end
|
@@ -86,7 +86,7 @@ module Mongoid
|
|
86
86
|
# @example Create the criteria.
|
87
87
|
# validator.create_criteria(User, user, :name, "syd")
|
88
88
|
#
|
89
|
-
# @param [ Class
|
89
|
+
# @param [ Class | Proxy ] base The base to execute the criteria from.
|
90
90
|
# @param [ Document ] document The document to validate.
|
91
91
|
# @param [ Symbol ] attribute The name of the attribute.
|
92
92
|
# @param [ Object ] value The value of the object.
|
@@ -149,7 +149,7 @@ module Mongoid
|
|
149
149
|
#
|
150
150
|
# @param [ Object ] value The value to filter.
|
151
151
|
#
|
152
|
-
# @return [ Object
|
152
|
+
# @return [ Object | Regexp ] The value, filtered or not.
|
153
153
|
def filter(value)
|
154
154
|
!case_sensitive? && value ? /\A#{Regexp.escape(value.to_s)}\z/i : value
|
155
155
|
end
|
@@ -182,7 +182,7 @@ module Mongoid
|
|
182
182
|
#
|
183
183
|
# @param [ Document ] document The embedded document.
|
184
184
|
#
|
185
|
-
# @return [ true
|
185
|
+
# @return [ true | false ] If the validation should be skipped.
|
186
186
|
def skip_validation?(document)
|
187
187
|
!document._parent || document.embedded_one?
|
188
188
|
end
|
@@ -196,7 +196,7 @@ module Mongoid
|
|
196
196
|
#
|
197
197
|
# @param [ Document ] document The embedded document.
|
198
198
|
#
|
199
|
-
# @return [ true
|
199
|
+
# @return [ true | false ] If the scope reference has changed.
|
200
200
|
def scope_value_changed?(document)
|
201
201
|
Array.wrap(options[:scope]).any? do |item|
|
202
202
|
document.send("attribute_changed?", item.to_s)
|
@@ -278,7 +278,7 @@ module Mongoid
|
|
278
278
|
# @param [ Document ] document The document getting validated.
|
279
279
|
# @param [ Symbol ] attribute The attribute to validate.
|
280
280
|
#
|
281
|
-
# @return [ true
|
281
|
+
# @return [ true | false ] If we need to validate.
|
282
282
|
def validation_required?(document, attribute)
|
283
283
|
document.new_record? ||
|
284
284
|
document.send("attribute_changed?", attribute.to_s) ||
|
@@ -295,7 +295,7 @@ module Mongoid
|
|
295
295
|
# @param [ Document ] document The document getting validated.
|
296
296
|
# @param [ Symbol ] attribute The attribute to validate.
|
297
297
|
#
|
298
|
-
# @return [ true
|
298
|
+
# @return [ true | false ] If the attribute is localized.
|
299
299
|
def localized?(document, attribute)
|
300
300
|
document.fields[document.database_field_name(attribute)].try(:localized?)
|
301
301
|
end
|
data/lib/mongoid/validatable.rb
CHANGED
@@ -44,7 +44,7 @@ module Mongoid
|
|
44
44
|
#
|
45
45
|
# @param [ Hash ] options The options to check.
|
46
46
|
#
|
47
|
-
# @return [ true
|
47
|
+
# @return [ true | false ] If we are validating.
|
48
48
|
def performing_validations?(options = {})
|
49
49
|
options[:validate].nil? ? true : options[:validate]
|
50
50
|
end
|
@@ -83,7 +83,7 @@ module Mongoid
|
|
83
83
|
#
|
84
84
|
# @param [ Symbol ] context The optional validation context.
|
85
85
|
#
|
86
|
-
# @return [ true
|
86
|
+
# @return [ true | false ] True if valid, false if not.
|
87
87
|
def valid?(context = nil)
|
88
88
|
super context ? context : (new_record? ? :create : :update)
|
89
89
|
end
|
@@ -93,7 +93,7 @@ module Mongoid
|
|
93
93
|
# @example Is the document validated?
|
94
94
|
# document.validated?
|
95
95
|
#
|
96
|
-
# @return [ true
|
96
|
+
# @return [ true | false ] Has the document already been validated?
|
97
97
|
def validated?
|
98
98
|
Threaded.validated?(self)
|
99
99
|
end
|
@@ -103,7 +103,7 @@ module Mongoid
|
|
103
103
|
# @example Are we validating with a query?
|
104
104
|
# document.validating_with_query?
|
105
105
|
#
|
106
|
-
# @return [ true
|
106
|
+
# @return [ true | false ] If we are validating with a query.
|
107
107
|
def validating_with_query?
|
108
108
|
self.class.validating_with_query?
|
109
109
|
end
|
@@ -129,7 +129,7 @@ module Mongoid
|
|
129
129
|
# @example Validate with a specific validator.
|
130
130
|
# validates_with MyValidator, on: :create
|
131
131
|
#
|
132
|
-
# @param [ Class<Array
|
132
|
+
# @param [ Class<Array> | Hash ] args The validator classes and options.
|
133
133
|
#
|
134
134
|
# @note See ActiveModel::Validations::With for full options. This is
|
135
135
|
# overridden to add autosave functionality when presence validation is
|
@@ -151,7 +151,7 @@ module Mongoid
|
|
151
151
|
# @example Are we validating with a query?
|
152
152
|
# Model.validating_with_query?
|
153
153
|
#
|
154
|
-
# @return [ true
|
154
|
+
# @return [ true | false ] If we are validating with a query.
|
155
155
|
def validating_with_query?
|
156
156
|
Threaded.executing?("#{name}-validate-with-query")
|
157
157
|
end
|
data/lib/mongoid/version.rb
CHANGED
@@ -3,19 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe 'i18n fallbacks' do
|
6
|
-
|
7
|
-
before(:all) do
|
8
|
-
unless %w(yes true 1).include?((ENV['TEST_I18N_FALLBACKS'] || '').downcase)
|
9
|
-
skip 'Set TEST_I18N_FALLBACKS=1 environment variable to run these tests'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
before(:all) do
|
14
|
-
puts "I18n version: #{I18n::VERSION}"
|
15
|
-
|
16
|
-
require "i18n/backend/fallbacks"
|
17
|
-
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
18
|
-
end
|
6
|
+
with_i18n_fallbacks
|
19
7
|
|
20
8
|
context 'when fallbacks are enabled with a locale list' do
|
21
9
|
before do
|
@@ -36,7 +24,6 @@ describe 'i18n fallbacks' do
|
|
36
24
|
end
|
37
25
|
|
38
26
|
context 'when translation is missing in active locale and present in fallback locale' do
|
39
|
-
|
40
27
|
it 'falls back on default locale' do
|
41
28
|
product = Product.new
|
42
29
|
I18n.locale = :en
|
@@ -44,7 +31,6 @@ describe 'i18n fallbacks' do
|
|
44
31
|
I18n.locale = :de
|
45
32
|
product.description.should == 'Marvelous!'
|
46
33
|
end
|
47
|
-
|
48
34
|
end
|
49
35
|
|
50
36
|
context 'when translation is missing in all locales' do
|
@@ -64,7 +50,6 @@ describe 'i18n fallbacks' do
|
|
64
50
|
I18n.locale = :ru
|
65
51
|
product.description.should be nil
|
66
52
|
end
|
67
|
-
|
68
53
|
end
|
69
54
|
|
70
55
|
context 'i18n 1.0' do
|
@@ -82,7 +67,6 @@ describe 'i18n fallbacks' do
|
|
82
67
|
I18n.locale = :ru
|
83
68
|
product.description.should == 'Marvelous!'
|
84
69
|
end
|
85
|
-
|
86
70
|
end
|
87
71
|
end
|
88
72
|
end
|
@@ -45,7 +45,7 @@ describe Mongoid::Cacheable do
|
|
45
45
|
context "with the default cache_timestamp_format" do
|
46
46
|
|
47
47
|
let!(:updated_at) do
|
48
|
-
document.updated_at.utc.
|
48
|
+
document.updated_at.utc.to_formatted_s(:nsec)
|
49
49
|
end
|
50
50
|
|
51
51
|
it "has the id and updated_at key name" do
|
@@ -64,7 +64,7 @@ describe Mongoid::Cacheable do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
let!(:updated_at) do
|
67
|
-
document.updated_at.utc.
|
67
|
+
document.updated_at.utc.to_formatted_s(:number)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "has the id and updated_at key name" do
|
@@ -103,7 +103,7 @@ describe Mongoid::Cacheable do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
let!(:updated_at) do
|
106
|
-
agent.updated_at.utc.
|
106
|
+
agent.updated_at.utc.to_formatted_s(:nsec)
|
107
107
|
end
|
108
108
|
|
109
109
|
it "has the id and updated_at key name" do
|
@@ -1042,6 +1042,31 @@ describe Mongoid::Clients do
|
|
1042
1042
|
end
|
1043
1043
|
end
|
1044
1044
|
end
|
1045
|
+
|
1046
|
+
context 'when using on different objects' do
|
1047
|
+
require_mri
|
1048
|
+
|
1049
|
+
let(:first_band) do
|
1050
|
+
Band.create!(name: "The Beatles")
|
1051
|
+
end
|
1052
|
+
|
1053
|
+
let(:second_band) do
|
1054
|
+
Band.create!(name: 'Led Zeppelin')
|
1055
|
+
end
|
1056
|
+
|
1057
|
+
it 'does not create extra symbols symbols' do
|
1058
|
+
first_band.with(write: { w: 0, j: false }) do |band|
|
1059
|
+
band.set(active: false)
|
1060
|
+
end
|
1061
|
+
initial_symbols_count = Symbol.all_symbols.size
|
1062
|
+
second_band.with(write: { w: 0, j: false }) do |band|
|
1063
|
+
band.set(active: false)
|
1064
|
+
end
|
1065
|
+
expect(Symbol.all_symbols.size).to eq(initial_symbols_count)
|
1066
|
+
end
|
1067
|
+
|
1068
|
+
end
|
1069
|
+
|
1045
1070
|
end
|
1046
1071
|
|
1047
1072
|
context "when overriding the default database" do
|
@@ -546,7 +546,7 @@ describe Mongoid::Contextual::Memory do
|
|
546
546
|
end
|
547
547
|
|
548
548
|
context 'when fallbacks are enabled with a locale list' do
|
549
|
-
|
549
|
+
with_i18n_fallbacks
|
550
550
|
|
551
551
|
around(:all) do |example|
|
552
552
|
prev_fallbacks = I18n.fallbacks.dup
|
@@ -565,7 +565,7 @@ describe Mongoid::Contextual::Memory do
|
|
565
565
|
|
566
566
|
it "correctly uses the fallback" do
|
567
567
|
I18n.locale = :en
|
568
|
-
|
568
|
+
Dictionary.create!(description: 'english-text')
|
569
569
|
I18n.locale = :he
|
570
570
|
distinct.should == "english-text"
|
571
571
|
end
|
@@ -1598,7 +1598,7 @@ describe Mongoid::Contextual::Memory do
|
|
1598
1598
|
end
|
1599
1599
|
|
1600
1600
|
context 'when fallbacks are enabled with a locale list' do
|
1601
|
-
|
1601
|
+
with_i18n_fallbacks
|
1602
1602
|
|
1603
1603
|
around(:all) do |example|
|
1604
1604
|
prev_fallbacks = I18n.fallbacks.dup
|
@@ -1617,7 +1617,7 @@ describe Mongoid::Contextual::Memory do
|
|
1617
1617
|
|
1618
1618
|
it "correctly uses the fallback" do
|
1619
1619
|
I18n.locale = :en
|
1620
|
-
|
1620
|
+
Dictionary.create!(description: 'english-text')
|
1621
1621
|
I18n.locale = :he
|
1622
1622
|
plucked.should == "english-text"
|
1623
1623
|
end
|
@@ -1960,7 +1960,6 @@ describe Mongoid::Contextual::Memory do
|
|
1960
1960
|
address2b.name = "de3"
|
1961
1961
|
person1
|
1962
1962
|
person2
|
1963
|
-
|
1964
1963
|
I18n.locale = :en
|
1965
1964
|
end
|
1966
1965
|
|
@@ -660,7 +660,7 @@ describe Mongoid::Contextual::Mongo do
|
|
660
660
|
end
|
661
661
|
|
662
662
|
context 'when fallbacks are enabled with a locale list' do
|
663
|
-
|
663
|
+
with_i18n_fallbacks
|
664
664
|
|
665
665
|
around(:all) do |example|
|
666
666
|
prev_fallbacks = I18n.fallbacks.dup
|
@@ -686,7 +686,7 @@ describe Mongoid::Contextual::Mongo do
|
|
686
686
|
|
687
687
|
it "correctly uses the fallback" do
|
688
688
|
I18n.locale = :en
|
689
|
-
|
689
|
+
Dictionary.create!(description: 'english-text')
|
690
690
|
I18n.locale = :he
|
691
691
|
distinct.should == "english-text"
|
692
692
|
end
|
@@ -854,7 +854,6 @@ describe Mongoid::Contextual::Mongo do
|
|
854
854
|
d2.save!
|
855
855
|
d3.save!
|
856
856
|
d4.save!
|
857
|
-
|
858
857
|
I18n.locale = :en
|
859
858
|
end
|
860
859
|
|
@@ -908,7 +907,6 @@ describe Mongoid::Contextual::Mongo do
|
|
908
907
|
address2b.name = "de3"
|
909
908
|
Person.create!(addresses: [ address1a, address1b ])
|
910
909
|
Person.create!(addresses: [ address2a, address2b ])
|
911
|
-
|
912
910
|
I18n.locale = :en
|
913
911
|
end
|
914
912
|
|
@@ -85,8 +85,8 @@ describe Mongoid::Equality do
|
|
85
85
|
|
86
86
|
describe ".===" do
|
87
87
|
|
88
|
-
context "when legacy_triple_equals is set" do
|
89
|
-
config_override :legacy_triple_equals,
|
88
|
+
context "when legacy_triple_equals is not set" do
|
89
|
+
config_override :legacy_triple_equals, false
|
90
90
|
|
91
91
|
context "when comparable is an instance of this document" do
|
92
92
|
|
@@ -128,8 +128,8 @@ describe Mongoid::Equality do
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
context "when legacy_triple_equals is
|
132
|
-
config_override :legacy_triple_equals,
|
131
|
+
context "when legacy_triple_equals is set" do
|
132
|
+
config_override :legacy_triple_equals, true
|
133
133
|
|
134
134
|
context "when comparable is an instance of this document" do
|
135
135
|
|
@@ -205,8 +205,8 @@ describe Mongoid::Equality do
|
|
205
205
|
|
206
206
|
context "when the class is the same" do
|
207
207
|
|
208
|
-
it "returns
|
209
|
-
expect(person === Person).to be
|
208
|
+
it "returns true" do
|
209
|
+
expect(person === Person).to be true
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
@@ -219,8 +219,8 @@ describe Mongoid::Equality do
|
|
219
219
|
|
220
220
|
context "when the class is a superclass" do
|
221
221
|
|
222
|
-
it "returns
|
223
|
-
expect(Doctor.new === Person).to be
|
222
|
+
it "returns true" do
|
223
|
+
expect(Doctor.new === Person).to be true
|
224
224
|
end
|
225
225
|
end
|
226
226
|
end
|
@@ -256,8 +256,8 @@ describe Mongoid::Equality do
|
|
256
256
|
context "when comparing to a class" do
|
257
257
|
context "when the class is the same" do
|
258
258
|
|
259
|
-
it "returns
|
260
|
-
expect(person === Person).to be
|
259
|
+
it "returns false" do
|
260
|
+
expect(person === Person).to be false
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
@@ -270,8 +270,8 @@ describe Mongoid::Equality do
|
|
270
270
|
|
271
271
|
context "when the class is a superclass" do
|
272
272
|
|
273
|
-
it "returns
|
274
|
-
expect(Doctor.new === Person).to be
|
273
|
+
it "returns false" do
|
274
|
+
expect(Doctor.new === Person).to be false
|
275
275
|
end
|
276
276
|
end
|
277
277
|
end
|
@@ -273,6 +273,21 @@ describe Mongoid::Extensions::BigDecimal do
|
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
276
|
+
context "when the value is castable" do
|
277
|
+
|
278
|
+
let(:value) do
|
279
|
+
2.hours
|
280
|
+
end
|
281
|
+
|
282
|
+
before do
|
283
|
+
expect(value).to be_a(ActiveSupport::Duration)
|
284
|
+
end
|
285
|
+
|
286
|
+
it "returns nil" do
|
287
|
+
expect(mongoized).to eq(7200)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
276
291
|
context "when the value is nil" do
|
277
292
|
|
278
293
|
let(:value) do
|
@@ -100,10 +100,10 @@ describe Mongoid::Extensions::Float do
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
context "when the string
|
103
|
+
context "when the string starts with a number" do
|
104
104
|
|
105
|
-
it "returns
|
106
|
-
expect(Float.send(method, "
|
105
|
+
it "returns nil" do
|
106
|
+
expect(Float.send(method, "42bogus")).to be_nil
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
@@ -120,6 +120,13 @@ describe Mongoid::Extensions::Float do
|
|
120
120
|
expect(Float.send(method, nil)).to be_nil
|
121
121
|
end
|
122
122
|
end
|
123
|
+
|
124
|
+
context "when giving an object that is castable to an Float" do
|
125
|
+
|
126
|
+
it "returns the integer value" do
|
127
|
+
expect(Float.send(method, 2.hours)).to eq(7200)
|
128
|
+
end
|
129
|
+
end
|
123
130
|
end
|
124
131
|
end
|
125
132
|
end
|
@@ -94,10 +94,10 @@ describe Mongoid::Extensions::Integer do
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
context "when the string
|
97
|
+
context "when the string starts with a number" do
|
98
98
|
|
99
|
-
it "returns
|
100
|
-
expect(Integer.send(method, "
|
99
|
+
it "returns nil" do
|
100
|
+
expect(Integer.send(method, "42bogus")).to be_nil
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -114,6 +114,13 @@ describe Mongoid::Extensions::Integer do
|
|
114
114
|
expect(Integer.send(method, nil)).to be_nil
|
115
115
|
end
|
116
116
|
end
|
117
|
+
|
118
|
+
context "when giving an object that is castable to an Integer" do
|
119
|
+
|
120
|
+
it "returns the integer value" do
|
121
|
+
expect(Integer.send(method, 2.hours)).to eq(7200)
|
122
|
+
end
|
123
|
+
end
|
117
124
|
end
|
118
125
|
end
|
119
126
|
end
|
@@ -102,6 +102,29 @@ describe Mongoid::Fields::Localized do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
context "when key is a symbol" do
|
106
|
+
|
107
|
+
let(:value) do
|
108
|
+
field.demongoize({ :de => "This is a test" })
|
109
|
+
end
|
110
|
+
|
111
|
+
it "returns the string from the set locale" do
|
112
|
+
expect(value).to eq("This is a test")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
context "passing a bogus value" do
|
118
|
+
|
119
|
+
let(:value) do
|
120
|
+
field.demongoize("bogus")
|
121
|
+
end
|
122
|
+
|
123
|
+
it "returns nil" do
|
124
|
+
expect(value).to be_nil
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
105
128
|
context "when the value does not exist" do
|
106
129
|
|
107
130
|
context "when not using fallbacks" do
|
@@ -117,10 +140,7 @@ describe Mongoid::Fields::Localized do
|
|
117
140
|
|
118
141
|
context "when using fallbacks" do
|
119
142
|
|
120
|
-
|
121
|
-
require "i18n/backend/fallbacks"
|
122
|
-
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
123
|
-
end
|
143
|
+
with_i18n_fallbacks
|
124
144
|
|
125
145
|
context "when fallbacks are defined" do
|
126
146
|
|
@@ -139,6 +159,17 @@ describe Mongoid::Fields::Localized do
|
|
139
159
|
end
|
140
160
|
end
|
141
161
|
|
162
|
+
context "when the fallback translation exists and is a symbol" do
|
163
|
+
|
164
|
+
let(:value) do
|
165
|
+
field.demongoize({ :es => "testing" })
|
166
|
+
end
|
167
|
+
|
168
|
+
it "returns the fallback translation" do
|
169
|
+
expect(value).to eq("testing")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
142
173
|
context "when another fallback translation exists" do
|
143
174
|
|
144
175
|
let(:value) do
|
@@ -275,10 +306,7 @@ describe Mongoid::Fields::Localized do
|
|
275
306
|
|
276
307
|
context "when using fallbacks" do
|
277
308
|
|
278
|
-
|
279
|
-
require "i18n/backend/fallbacks"
|
280
|
-
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
281
|
-
end
|
309
|
+
with_i18n_fallbacks
|
282
310
|
|
283
311
|
context "when fallbacks are defined" do
|
284
312
|
|
@@ -476,10 +504,7 @@ describe Mongoid::Fields::Localized do
|
|
476
504
|
|
477
505
|
context "when fallbacks are defined" do
|
478
506
|
|
479
|
-
|
480
|
-
require "i18n/backend/fallbacks"
|
481
|
-
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
482
|
-
end
|
507
|
+
with_i18n_fallbacks
|
483
508
|
|
484
509
|
context "when the lookup does not need to use fallbacks" do
|
485
510
|
|
@@ -223,8 +223,11 @@ describe Mongoid::Indexable do
|
|
223
223
|
let(:klass) do
|
224
224
|
Class.new do
|
225
225
|
include Mongoid::Document
|
226
|
-
|
226
|
+
|
227
227
|
store_in collection: :specs
|
228
|
+
|
229
|
+
field :a, as: :authentication_token
|
230
|
+
field :username
|
228
231
|
end
|
229
232
|
end
|
230
233
|
|
@@ -588,6 +591,25 @@ describe Mongoid::Indexable do
|
|
588
591
|
end
|
589
592
|
end
|
590
593
|
|
594
|
+
context "when using a wildcard index" do
|
595
|
+
|
596
|
+
before do
|
597
|
+
klass.index({ '$**': 1 }, wildcard_projection: { _id: 1, username: 0 })
|
598
|
+
end
|
599
|
+
|
600
|
+
let(:spec) do
|
601
|
+
klass.index_specification('$**': 1)
|
602
|
+
end
|
603
|
+
|
604
|
+
it "creates the index" do
|
605
|
+
expect(spec).to be_a(Mongoid::Indexable::Specification)
|
606
|
+
end
|
607
|
+
|
608
|
+
it "sets the index with correct options" do
|
609
|
+
expect(spec.options).to eq(wildcard_projection: { _id: 1, username: 0 })
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
591
613
|
context "when providing an invalid option" do
|
592
614
|
|
593
615
|
it "raises an error" do
|
@@ -481,27 +481,45 @@ describe Mongoid::Scopable do
|
|
481
481
|
|
482
482
|
context "when a block is provided" do
|
483
483
|
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
484
|
+
context "when with optional and keyword arguments" do
|
485
|
+
before do
|
486
|
+
Band.scope(:named_by, ->(name, deleted: false) {
|
487
|
+
Band.where(name: name, deleted: deleted)
|
488
|
+
})
|
489
489
|
end
|
490
|
-
end
|
491
490
|
|
492
|
-
|
493
|
-
|
494
|
-
undef_method :active
|
491
|
+
let(:scope) do
|
492
|
+
Band.named_by("Emily", deleted: true)
|
495
493
|
end
|
496
|
-
Band._declared_scopes.clear
|
497
|
-
end
|
498
494
|
|
499
|
-
|
500
|
-
|
495
|
+
it "sets the conditions from keyword arguments" do
|
496
|
+
scope.selector.should == {'name' => 'Emily', 'deleted' => true}
|
497
|
+
end
|
501
498
|
end
|
502
499
|
|
503
|
-
|
504
|
-
|
500
|
+
context "when without arguments" do
|
501
|
+
before do
|
502
|
+
Band.scope(:active, ->{ Band.where(active: true) }) do
|
503
|
+
def add_origin
|
504
|
+
tap { |c| c.selector[:origin] = "Deutschland" }
|
505
|
+
end
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
after do
|
510
|
+
class << Band
|
511
|
+
undef_method :active
|
512
|
+
end
|
513
|
+
Band._declared_scopes.clear
|
514
|
+
end
|
515
|
+
|
516
|
+
let(:scope) do
|
517
|
+
Band.active.add_origin
|
518
|
+
end
|
519
|
+
|
520
|
+
it "adds the extension to the scope" do
|
521
|
+
expect(scope.selector).to eq({ "active" => true, "origin" => "Deutschland" })
|
522
|
+
end
|
505
523
|
end
|
506
524
|
end
|
507
525
|
|
@@ -1173,7 +1191,7 @@ describe Mongoid::Scopable do
|
|
1173
1191
|
end
|
1174
1192
|
end
|
1175
1193
|
|
1176
|
-
context 'when nesting
|
1194
|
+
context 'when nesting unscoped under with_scope' do
|
1177
1195
|
let(:c1) { Band.where(active: true) }
|
1178
1196
|
|
1179
1197
|
it 'restores previous scope' do
|