mongoid 8.0.3 → 8.1.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/CHANGELOG.md +3 -3
- data/README.md +3 -3
- data/lib/config/locales/en.yml +46 -14
- data/lib/mongoid/association/accessors.rb +2 -2
- data/lib/mongoid/association/builders.rb +1 -1
- data/lib/mongoid/association/embedded/batchable.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -1
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +3 -2
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +23 -21
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +1 -1
- data/lib/mongoid/association/nested/one.rb +40 -2
- data/lib/mongoid/association/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +5 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +2 -2
- data/lib/mongoid/association/referenced/has_many/proxy.rb +7 -3
- data/lib/mongoid/association/reflections.rb +2 -2
- data/lib/mongoid/attributes/dynamic.rb +1 -1
- data/lib/mongoid/attributes/nested.rb +2 -2
- data/lib/mongoid/attributes/projector.rb +1 -1
- data/lib/mongoid/attributes/readonly.rb +1 -1
- data/lib/mongoid/attributes.rb +8 -2
- data/lib/mongoid/changeable.rb +104 -4
- data/lib/mongoid/clients/storage_options.rb +2 -5
- data/lib/mongoid/clients/validators/storage.rb +1 -13
- data/lib/mongoid/collection_configurable.rb +58 -0
- data/lib/mongoid/composable.rb +2 -0
- data/lib/mongoid/config/defaults.rb +60 -0
- data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
- data/lib/mongoid/config/validators.rb +1 -0
- data/lib/mongoid/config.rb +101 -0
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +233 -33
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +373 -113
- data/lib/mongoid/contextual/none.rb +162 -7
- data/lib/mongoid/contextual.rb +12 -0
- data/lib/mongoid/criteria/findable.rb +2 -2
- data/lib/mongoid/criteria/includable.rb +4 -3
- data/lib/mongoid/criteria/queryable/extensions/array.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +0 -8
- data/lib/mongoid/criteria/queryable/extensions/string.rb +1 -11
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +0 -10
- data/lib/mongoid/criteria/queryable/key.rb +1 -1
- data/lib/mongoid/criteria/queryable/mergeable.rb +1 -1
- data/lib/mongoid/criteria/queryable/optional.rb +8 -8
- data/lib/mongoid/criteria/queryable/selectable.rb +43 -12
- data/lib/mongoid/criteria/translator.rb +45 -0
- data/lib/mongoid/criteria.rb +7 -5
- data/lib/mongoid/deprecable.rb +1 -1
- data/lib/mongoid/document.rb +50 -13
- data/lib/mongoid/errors/create_collection_failure.rb +33 -0
- data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
- data/lib/mongoid/errors/immutable_attribute.rb +26 -0
- data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
- data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
- data/lib/mongoid/errors.rb +4 -1
- data/lib/mongoid/extensions/object.rb +2 -2
- data/lib/mongoid/extensions/time.rb +2 -0
- data/lib/mongoid/factory.rb +21 -8
- data/lib/mongoid/fields/localized.rb +10 -0
- data/lib/mongoid/fields/standard.rb +10 -0
- data/lib/mongoid/fields.rb +69 -13
- data/lib/mongoid/findable.rb +27 -3
- data/lib/mongoid/interceptable.rb +7 -6
- data/lib/mongoid/matcher/eq_impl.rb +1 -1
- data/lib/mongoid/matcher/type.rb +1 -1
- data/lib/mongoid/matcher.rb +21 -6
- data/lib/mongoid/persistable/creatable.rb +1 -0
- data/lib/mongoid/persistable/deletable.rb +1 -1
- data/lib/mongoid/persistable/savable.rb +13 -1
- data/lib/mongoid/persistable/unsettable.rb +2 -2
- data/lib/mongoid/persistable/updatable.rb +51 -1
- data/lib/mongoid/persistable/upsertable.rb +20 -1
- data/lib/mongoid/persistable.rb +3 -0
- data/lib/mongoid/query_cache.rb +5 -1
- data/lib/mongoid/railties/database.rake +7 -2
- data/lib/mongoid/shardable.rb +35 -11
- data/lib/mongoid/stateful.rb +22 -1
- data/lib/mongoid/tasks/database.rake +12 -0
- data/lib/mongoid/tasks/database.rb +20 -0
- data/lib/mongoid/threaded.rb +30 -0
- data/lib/mongoid/traversable.rb +1 -1
- data/lib/mongoid/utils.rb +22 -0
- data/lib/mongoid/validatable/macros.rb +5 -5
- data/lib/mongoid/validatable.rb +4 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +17 -1
- data/lib/mongoid.rb +16 -3
- data/spec/integration/app_spec.rb +2 -2
- data/spec/integration/callbacks_models.rb +37 -0
- data/spec/integration/callbacks_spec.rb +134 -0
- data/spec/integration/discriminator_key_spec.rb +4 -5
- data/spec/integration/i18n_fallbacks_spec.rb +3 -2
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +27 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +57 -57
- data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +15 -2
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -18
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +148 -224
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +111 -164
- data/spec/mongoid/association/syncable_spec.rb +1 -1
- data/spec/mongoid/attributes_spec.rb +5 -8
- data/spec/mongoid/changeable_spec.rb +299 -24
- data/spec/mongoid/clients_spec.rb +122 -13
- data/spec/mongoid/collection_configurable_spec.rb +158 -0
- data/spec/mongoid/config/defaults_spec.rb +160 -0
- data/spec/mongoid/config_spec.rb +154 -18
- data/spec/mongoid/contextual/memory_spec.rb +332 -76
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
- data/spec/mongoid/contextual/mongo_spec.rb +995 -36
- data/spec/mongoid/contextual/none_spec.rb +49 -2
- data/spec/mongoid/copyable_spec.rb +3 -11
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -69
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +0 -59
- data/spec/mongoid/criteria/queryable/optional_spec.rb +15 -0
- data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +419 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selector_spec.rb +1 -1
- data/spec/mongoid/criteria/translator_spec.rb +132 -0
- data/spec/mongoid/criteria_projection_spec.rb +1 -4
- data/spec/mongoid/criteria_spec.rb +5 -9
- data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
- data/spec/mongoid/extensions/time_spec.rb +8 -43
- data/spec/mongoid/extensions/time_with_zone_spec.rb +7 -52
- data/spec/mongoid/fields/localized_spec.rb +46 -28
- data/spec/mongoid/fields_spec.rb +136 -34
- data/spec/mongoid/findable_spec.rb +391 -34
- data/spec/mongoid/indexable_spec.rb +16 -10
- data/spec/mongoid/interceptable_spec.rb +15 -3
- data/spec/mongoid/persistable/deletable_spec.rb +26 -6
- data/spec/mongoid/persistable/destroyable_spec.rb +26 -6
- data/spec/mongoid/persistable/incrementable_spec.rb +37 -0
- data/spec/mongoid/persistable/logical_spec.rb +37 -0
- data/spec/mongoid/persistable/poppable_spec.rb +36 -0
- data/spec/mongoid/persistable/pullable_spec.rb +72 -0
- data/spec/mongoid/persistable/pushable_spec.rb +72 -0
- data/spec/mongoid/persistable/renamable_spec.rb +36 -0
- data/spec/mongoid/persistable/savable_spec.rb +96 -0
- data/spec/mongoid/persistable/settable_spec.rb +37 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +36 -0
- data/spec/mongoid/persistable/updatable_spec.rb +20 -28
- data/spec/mongoid/persistable/upsertable_spec.rb +80 -6
- data/spec/mongoid/persistence_context_spec.rb +7 -57
- data/spec/mongoid/query_cache_spec.rb +56 -61
- data/spec/mongoid/reloadable_spec.rb +24 -4
- data/spec/mongoid/scopable_spec.rb +70 -0
- data/spec/mongoid/serializable_spec.rb +9 -30
- data/spec/mongoid/shardable_models.rb +14 -0
- data/spec/mongoid/shardable_spec.rb +153 -61
- data/spec/mongoid/stateful_spec.rb +122 -8
- data/spec/mongoid/tasks/database_rake_spec.rb +74 -0
- data/spec/mongoid/tasks/database_spec.rb +127 -0
- data/spec/mongoid/timestamps_spec.rb +9 -11
- data/spec/mongoid/touchable_spec.rb +277 -5
- data/spec/mongoid/touchable_spec_models.rb +3 -1
- data/spec/mongoid/traversable_spec.rb +9 -24
- data/spec/mongoid/validatable/uniqueness_spec.rb +2 -3
- data/spec/mongoid_spec.rb +35 -9
- data/spec/shared/lib/mrss/docker_runner.rb +7 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +15 -5
- data/spec/shared/lib/mrss/lite_constraints.rb +10 -2
- data/spec/shared/lib/mrss/server_version_registry.rb +16 -23
- data/spec/shared/lib/mrss/utils.rb +28 -6
- data/spec/shared/share/Dockerfile.erb +36 -40
- data/spec/shared/shlib/server.sh +32 -8
- data/spec/shared/shlib/set_env.sh +4 -4
- data/spec/spec_helper.rb +5 -0
- data/spec/support/immutable_ids.rb +118 -0
- data/spec/support/macros.rb +47 -15
- data/spec/support/models/artist.rb +0 -1
- data/spec/support/models/band.rb +1 -0
- data/spec/support/models/book.rb +1 -0
- data/spec/support/models/building.rb +2 -0
- data/spec/support/models/cover.rb +10 -0
- data/spec/support/models/product.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +700 -656
- metadata.gz.sig +0 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -60
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -60
|
@@ -2,11 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
require "spec_helper"
|
|
4
4
|
|
|
5
|
+
module RefHasManySpec
|
|
6
|
+
module OverrideInitialize
|
|
7
|
+
class Parent
|
|
8
|
+
include Mongoid::Document
|
|
9
|
+
has_many :children, inverse_of: :parent
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class Child
|
|
13
|
+
include Mongoid::Document
|
|
14
|
+
belongs_to :parent
|
|
15
|
+
field :name, type: String
|
|
16
|
+
|
|
17
|
+
def initialize(*args)
|
|
18
|
+
super
|
|
19
|
+
self.name ||= "default"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
5
25
|
describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
26
|
+
config_override :raise_not_found_error, true
|
|
6
27
|
|
|
7
28
|
before :all do
|
|
8
|
-
Mongoid.raise_not_found_error = true
|
|
9
|
-
|
|
10
29
|
Drug.belongs_to :person, primary_key: :username
|
|
11
30
|
Person.has_many :drugs, validate: false, primary_key: :username
|
|
12
31
|
end
|
|
@@ -877,6 +896,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
877
896
|
[ :build, :new ].each do |method|
|
|
878
897
|
|
|
879
898
|
describe "##{method}" do
|
|
899
|
+
context 'when model has #initialize' do
|
|
900
|
+
let(:parent) { RefHasManySpec::OverrideInitialize::Parent.create }
|
|
901
|
+
let(:child) { parent.children.send(method) }
|
|
902
|
+
|
|
903
|
+
it 'should call #initialize' do
|
|
904
|
+
expect(child.name).to be == "default"
|
|
905
|
+
end
|
|
906
|
+
end
|
|
880
907
|
|
|
881
908
|
context "when the association is not polymorphic" do
|
|
882
909
|
|
|
@@ -2077,154 +2104,114 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2077
2104
|
end
|
|
2078
2105
|
end
|
|
2079
2106
|
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
Person.create!(username: 'arthurnn')
|
|
2084
|
-
end
|
|
2107
|
+
%i[ delete delete_one ].each do |method|
|
|
2108
|
+
describe "##{method}" do
|
|
2109
|
+
let!(:person) { Person.create!(username: 'arthurnn') }
|
|
2085
2110
|
|
|
2086
|
-
|
|
2111
|
+
context 'when the document is found' do
|
|
2112
|
+
context 'when no dependent option is set' do
|
|
2113
|
+
context 'when we are assigning attributes' do
|
|
2114
|
+
let!(:drug) { person.drugs.create! }
|
|
2115
|
+
let(:deleted) { person.drugs.send(method, drug) }
|
|
2087
2116
|
|
|
2088
|
-
|
|
2117
|
+
before do
|
|
2118
|
+
Mongoid::Threaded.begin_execution(:assign)
|
|
2119
|
+
end
|
|
2089
2120
|
|
|
2090
|
-
|
|
2121
|
+
after do
|
|
2122
|
+
Mongoid::Threaded.exit_execution(:assign)
|
|
2123
|
+
end
|
|
2091
2124
|
|
|
2092
|
-
|
|
2093
|
-
|
|
2125
|
+
it 'does not cascade' do
|
|
2126
|
+
expect(deleted.changes.keys).to eq([ 'person_id' ])
|
|
2127
|
+
end
|
|
2094
2128
|
end
|
|
2095
2129
|
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2130
|
+
context 'when the document is loaded' do
|
|
2131
|
+
let!(:drug) { person.drugs.create! }
|
|
2132
|
+
let!(:deleted) { person.drugs.send(method, drug) }
|
|
2099
2133
|
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2134
|
+
it 'returns the document' do
|
|
2135
|
+
expect(deleted).to eq(drug)
|
|
2136
|
+
end
|
|
2103
2137
|
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2138
|
+
it 'deletes the foreign key' do
|
|
2139
|
+
expect(drug.person_id).to be_nil
|
|
2140
|
+
end
|
|
2107
2141
|
|
|
2108
|
-
|
|
2109
|
-
|
|
2142
|
+
it 'removes the document from the association' do
|
|
2143
|
+
expect(person.drugs).not_to include(drug)
|
|
2144
|
+
end
|
|
2110
2145
|
end
|
|
2111
|
-
end
|
|
2112
2146
|
|
|
2113
|
-
|
|
2147
|
+
context 'when the document is not loaded' do
|
|
2148
|
+
let!(:drug) { Drug.create!(person_id: person.username) }
|
|
2149
|
+
let!(:deleted) { person.drugs.send(method, drug) }
|
|
2114
2150
|
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2151
|
+
it 'returns the document' do
|
|
2152
|
+
expect(deleted).to eq(drug)
|
|
2153
|
+
end
|
|
2118
2154
|
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2155
|
+
it 'deletes the foreign key' do
|
|
2156
|
+
expect(drug.person_id).to be_nil
|
|
2157
|
+
end
|
|
2122
2158
|
|
|
2123
|
-
|
|
2124
|
-
|
|
2159
|
+
it 'removes the document from the association' do
|
|
2160
|
+
expect(person.drugs).not_to include(drug)
|
|
2161
|
+
end
|
|
2125
2162
|
end
|
|
2163
|
+
end
|
|
2126
2164
|
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2165
|
+
context 'when dependent is delete' do
|
|
2166
|
+
context 'when the document is loaded' do
|
|
2167
|
+
let!(:post) { person.posts.create!(title: 'test') }
|
|
2168
|
+
let!(:deleted) { person.posts.send(method, post) }
|
|
2130
2169
|
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
end
|
|
2170
|
+
it 'returns the document' do
|
|
2171
|
+
expect(deleted).to eq(post)
|
|
2172
|
+
end
|
|
2135
2173
|
|
|
2136
|
-
|
|
2174
|
+
it 'deletes the document' do
|
|
2175
|
+
expect(post).to be_destroyed
|
|
2176
|
+
end
|
|
2137
2177
|
|
|
2138
|
-
|
|
2139
|
-
|
|
2178
|
+
it 'removes the document from the association' do
|
|
2179
|
+
expect(person.posts).not_to include(post)
|
|
2180
|
+
end
|
|
2140
2181
|
end
|
|
2141
2182
|
|
|
2142
|
-
|
|
2143
|
-
person.
|
|
2144
|
-
|
|
2183
|
+
context 'when the document is not loaded' do
|
|
2184
|
+
let!(:post) { Post.create!(title: 'foo', person_id: person.id) }
|
|
2185
|
+
let!(:deleted) { person.posts.send(method, post) }
|
|
2145
2186
|
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2187
|
+
it 'returns the document' do
|
|
2188
|
+
expect(deleted).to eq(post)
|
|
2189
|
+
end
|
|
2149
2190
|
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2191
|
+
it 'deletes the document' do
|
|
2192
|
+
expect(post).to be_destroyed
|
|
2193
|
+
end
|
|
2153
2194
|
|
|
2154
|
-
|
|
2155
|
-
|
|
2195
|
+
it 'removes the document from the association' do
|
|
2196
|
+
expect(person.posts).not_to include(post)
|
|
2197
|
+
end
|
|
2156
2198
|
end
|
|
2157
2199
|
end
|
|
2158
2200
|
end
|
|
2159
2201
|
|
|
2160
|
-
context
|
|
2161
|
-
|
|
2162
|
-
|
|
2202
|
+
context 'when the document is not found' do
|
|
2203
|
+
let!(:post) { Post.create!(title: 'foo') }
|
|
2204
|
+
let!(:deleted) { person.posts.send(method, post) }
|
|
2163
2205
|
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
end
|
|
2167
|
-
|
|
2168
|
-
let!(:deleted) do
|
|
2169
|
-
person.posts.delete(post)
|
|
2170
|
-
end
|
|
2171
|
-
|
|
2172
|
-
it "returns the document" do
|
|
2173
|
-
expect(deleted).to eq(post)
|
|
2174
|
-
end
|
|
2175
|
-
|
|
2176
|
-
it "deletes the document" do
|
|
2177
|
-
expect(post).to be_destroyed
|
|
2178
|
-
end
|
|
2179
|
-
|
|
2180
|
-
it "removes the document from the association" do
|
|
2181
|
-
expect(person.posts).to_not include(post)
|
|
2182
|
-
end
|
|
2206
|
+
it 'returns nil' do
|
|
2207
|
+
expect(deleted).to be_nil
|
|
2183
2208
|
end
|
|
2184
2209
|
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
let!(:post) do
|
|
2188
|
-
Post.create!(title: "foo", person_id: person.id)
|
|
2189
|
-
end
|
|
2190
|
-
|
|
2191
|
-
let!(:deleted) do
|
|
2192
|
-
person.posts.delete(post)
|
|
2193
|
-
end
|
|
2194
|
-
|
|
2195
|
-
it "returns the document" do
|
|
2196
|
-
expect(deleted).to eq(post)
|
|
2197
|
-
end
|
|
2198
|
-
|
|
2199
|
-
it "deletes the document" do
|
|
2200
|
-
expect(post).to be_destroyed
|
|
2201
|
-
end
|
|
2202
|
-
|
|
2203
|
-
it "removes the document from the association" do
|
|
2204
|
-
expect(person.posts).to_not include(post)
|
|
2205
|
-
end
|
|
2210
|
+
it 'does not delete the document' do
|
|
2211
|
+
expect(post).to be_persisted
|
|
2206
2212
|
end
|
|
2207
2213
|
end
|
|
2208
2214
|
end
|
|
2209
|
-
|
|
2210
|
-
context "when the document is not found" do
|
|
2211
|
-
|
|
2212
|
-
let!(:post) do
|
|
2213
|
-
Post.create!(title: "foo")
|
|
2214
|
-
end
|
|
2215
|
-
|
|
2216
|
-
let!(:deleted) do
|
|
2217
|
-
person.posts.delete(post)
|
|
2218
|
-
end
|
|
2219
|
-
|
|
2220
|
-
it "returns nil" do
|
|
2221
|
-
expect(deleted).to be_nil
|
|
2222
|
-
end
|
|
2223
|
-
|
|
2224
|
-
it "does not delete the document" do
|
|
2225
|
-
expect(post).to be_persisted
|
|
2226
|
-
end
|
|
2227
|
-
end
|
|
2228
2215
|
end
|
|
2229
2216
|
|
|
2230
2217
|
[ :delete_all, :destroy_all ].each do |method|
|
|
@@ -2547,10 +2534,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2547
2534
|
context "when the id does not match" do
|
|
2548
2535
|
|
|
2549
2536
|
context "when config set to raise error" do
|
|
2550
|
-
|
|
2551
|
-
before do
|
|
2552
|
-
Mongoid.raise_not_found_error = true
|
|
2553
|
-
end
|
|
2537
|
+
config_override :raise_not_found_error, true
|
|
2554
2538
|
|
|
2555
2539
|
it "raises an error" do
|
|
2556
2540
|
expect {
|
|
@@ -2560,19 +2544,12 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2560
2544
|
end
|
|
2561
2545
|
|
|
2562
2546
|
context "when config set not to raise error" do
|
|
2547
|
+
config_override :raise_not_found_error, false
|
|
2563
2548
|
|
|
2564
2549
|
let(:post) do
|
|
2565
2550
|
person.posts.find(BSON::ObjectId.new)
|
|
2566
2551
|
end
|
|
2567
2552
|
|
|
2568
|
-
before do
|
|
2569
|
-
Mongoid.raise_not_found_error = false
|
|
2570
|
-
end
|
|
2571
|
-
|
|
2572
|
-
after do
|
|
2573
|
-
Mongoid.raise_not_found_error = true
|
|
2574
|
-
end
|
|
2575
|
-
|
|
2576
2553
|
it "returns nil" do
|
|
2577
2554
|
expect(post).to be_nil
|
|
2578
2555
|
end
|
|
@@ -2596,10 +2573,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2596
2573
|
context "when the ids do not match" do
|
|
2597
2574
|
|
|
2598
2575
|
context "when config set to raise error" do
|
|
2599
|
-
|
|
2600
|
-
before do
|
|
2601
|
-
Mongoid.raise_not_found_error = true
|
|
2602
|
-
end
|
|
2576
|
+
config_override :raise_not_found_error, true
|
|
2603
2577
|
|
|
2604
2578
|
it "raises an error" do
|
|
2605
2579
|
expect {
|
|
@@ -2609,19 +2583,12 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2609
2583
|
end
|
|
2610
2584
|
|
|
2611
2585
|
context "when config set not to raise error" do
|
|
2586
|
+
config_override :raise_not_found_error, false
|
|
2612
2587
|
|
|
2613
2588
|
let(:posts) do
|
|
2614
2589
|
person.posts.find([ BSON::ObjectId.new ])
|
|
2615
2590
|
end
|
|
2616
2591
|
|
|
2617
|
-
before do
|
|
2618
|
-
Mongoid.raise_not_found_error = false
|
|
2619
|
-
end
|
|
2620
|
-
|
|
2621
|
-
after do
|
|
2622
|
-
Mongoid.raise_not_found_error = true
|
|
2623
|
-
end
|
|
2624
|
-
|
|
2625
2592
|
it "returns an empty array" do
|
|
2626
2593
|
expect(posts).to be_empty
|
|
2627
2594
|
end
|
|
@@ -2660,10 +2627,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2660
2627
|
context "when the id does not match" do
|
|
2661
2628
|
|
|
2662
2629
|
context "when config set to raise error" do
|
|
2663
|
-
|
|
2664
|
-
before do
|
|
2665
|
-
Mongoid.raise_not_found_error = true
|
|
2666
|
-
end
|
|
2630
|
+
config_override :raise_not_found_error, true
|
|
2667
2631
|
|
|
2668
2632
|
it "raises an error" do
|
|
2669
2633
|
expect {
|
|
@@ -2673,19 +2637,12 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2673
2637
|
end
|
|
2674
2638
|
|
|
2675
2639
|
context "when config set not to raise error" do
|
|
2640
|
+
config_override :raise_not_found_error, false
|
|
2676
2641
|
|
|
2677
2642
|
let(:rating) do
|
|
2678
2643
|
movie.ratings.find(BSON::ObjectId.new)
|
|
2679
2644
|
end
|
|
2680
2645
|
|
|
2681
|
-
before do
|
|
2682
|
-
Mongoid.raise_not_found_error = false
|
|
2683
|
-
end
|
|
2684
|
-
|
|
2685
|
-
after do
|
|
2686
|
-
Mongoid.raise_not_found_error = true
|
|
2687
|
-
end
|
|
2688
|
-
|
|
2689
2646
|
it "returns nil" do
|
|
2690
2647
|
expect(rating).to be_nil
|
|
2691
2648
|
end
|
|
@@ -2717,10 +2674,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2717
2674
|
context "when the ids do not match" do
|
|
2718
2675
|
|
|
2719
2676
|
context "when config set to raise error" do
|
|
2720
|
-
|
|
2721
|
-
before do
|
|
2722
|
-
Mongoid.raise_not_found_error = true
|
|
2723
|
-
end
|
|
2677
|
+
config_override :raise_not_found_error, true
|
|
2724
2678
|
|
|
2725
2679
|
it "raises an error" do
|
|
2726
2680
|
expect {
|
|
@@ -2730,19 +2684,12 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2730
2684
|
end
|
|
2731
2685
|
|
|
2732
2686
|
context "when config set not to raise error" do
|
|
2687
|
+
config_override :raise_not_found_error, false
|
|
2733
2688
|
|
|
2734
2689
|
let(:ratings) do
|
|
2735
2690
|
movie.ratings.find([ BSON::ObjectId.new ])
|
|
2736
2691
|
end
|
|
2737
2692
|
|
|
2738
|
-
before do
|
|
2739
|
-
Mongoid.raise_not_found_error = false
|
|
2740
|
-
end
|
|
2741
|
-
|
|
2742
|
-
after do
|
|
2743
|
-
Mongoid.raise_not_found_error = true
|
|
2744
|
-
end
|
|
2745
|
-
|
|
2746
2693
|
it "returns an empty array" do
|
|
2747
2694
|
expect(ratings).to be_empty
|
|
2748
2695
|
end
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
require "spec_helper"
|
|
4
4
|
|
|
5
5
|
describe "Syncable Association" do
|
|
6
|
+
config_override :raise_not_found_error, true
|
|
6
7
|
|
|
7
8
|
before(:all) do
|
|
8
|
-
Mongoid.raise_not_found_error = true
|
|
9
9
|
Person._synced(Person.relations["preferences"])
|
|
10
10
|
Person.has_and_belongs_to_many :preferences
|
|
11
11
|
Preference.has_and_belongs_to_many :people
|
|
@@ -393,11 +393,10 @@ describe Mongoid::Attributes do
|
|
|
393
393
|
end
|
|
394
394
|
|
|
395
395
|
context "when reloaded" do
|
|
396
|
+
config_override :raise_not_found_error, false
|
|
396
397
|
|
|
397
398
|
before do
|
|
398
|
-
Mongoid.raise_not_found_error = false
|
|
399
399
|
person.reload
|
|
400
|
-
Mongoid.raise_not_found_error = true
|
|
401
400
|
end
|
|
402
401
|
|
|
403
402
|
it "returns the default value" do
|
|
@@ -1030,14 +1029,13 @@ describe Mongoid::Attributes do
|
|
|
1030
1029
|
end
|
|
1031
1030
|
|
|
1032
1031
|
context "when the attribute does not exist" do
|
|
1032
|
+
config_override :raise_not_found_error, false
|
|
1033
1033
|
|
|
1034
1034
|
before do
|
|
1035
1035
|
person.collection
|
|
1036
1036
|
.find({ _id: person.id })
|
|
1037
1037
|
.update_one({ "$unset" => { age: 1 }})
|
|
1038
|
-
Mongoid.raise_not_found_error = false
|
|
1039
1038
|
person.reload
|
|
1040
|
-
Mongoid.raise_not_found_error = true
|
|
1041
1039
|
end
|
|
1042
1040
|
|
|
1043
1041
|
it "returns the default value" do
|
|
@@ -1161,14 +1159,13 @@ describe Mongoid::Attributes do
|
|
|
1161
1159
|
end
|
|
1162
1160
|
|
|
1163
1161
|
context "when the attribute does not exist" do
|
|
1162
|
+
config_override :raise_not_found_error, false
|
|
1164
1163
|
|
|
1165
1164
|
before do
|
|
1166
1165
|
person.collection
|
|
1167
1166
|
.find({ _id: person.id })
|
|
1168
1167
|
.update_one({ "$unset" => { age: 1 }})
|
|
1169
|
-
Mongoid.raise_not_found_error = false
|
|
1170
1168
|
person.reload
|
|
1171
|
-
Mongoid.raise_not_found_error = true
|
|
1172
1169
|
end
|
|
1173
1170
|
|
|
1174
1171
|
it "returns true" do
|
|
@@ -2499,7 +2496,7 @@ describe Mongoid::Attributes do
|
|
|
2499
2496
|
end
|
|
2500
2497
|
end
|
|
2501
2498
|
|
|
2502
|
-
context "when doing
|
|
2499
|
+
context "when doing _remove" do
|
|
2503
2500
|
let(:doc) { NestedBook.create! }
|
|
2504
2501
|
let(:page) { NestedPage.new }
|
|
2505
2502
|
before do
|
|
@@ -2507,7 +2504,7 @@ describe Mongoid::Attributes do
|
|
|
2507
2504
|
doc.pages << NestedPage.new
|
|
2508
2505
|
doc.pages << NestedPage.new
|
|
2509
2506
|
|
|
2510
|
-
doc.pages.
|
|
2507
|
+
doc.pages._remove(page)
|
|
2511
2508
|
end
|
|
2512
2509
|
|
|
2513
2510
|
it "updates the attributes" do
|