Skip to content

Commit 9756c15

Browse files
MONGOID-5055 Improve error message for UnknownAttribute. Fix various typos in errors. (#5031)
Co-authored-by: shields <[email protected]>
1 parent 25fb2d3 commit 9756c15

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

lib/config/locales/en.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ en:
101101
options are: %{options}."
102102
resolution: "Remove the invalid option or fix the typo. If you were
103103
expecting the option to be there, please consult the following page
104-
with repect to Mongoid's configuration:\n\n
104+
with respect to Mongoid's configuration:\n\n
105105
\_\_http://mongoid.org/en/mongoid/docs/installation.html"
106106
invalid_dependent_strategy:
107107
message: "Invalid dependent strategy: %{invalid_strategy}."
@@ -124,7 +124,7 @@ en:
124124
invalid_estimated_count_criteria:
125125
message: "Invalid criteria for estimated_count."
126126
summary: "Estimated count is strictly a collection-level operation and cannot be called
127-
on a filtered critera."
127+
on a filtered criteria."
128128
resolution: "Try calling estimated_count directly on the class: %{class_name}.estimated_count.\n\n
129129
\_If the class defines a default scope, use unscoped: %{class_name}.unscoped.estimated_count."
130130
invalid_expression_operator:
@@ -255,7 +255,7 @@ en:
255255
message: "Defining a scope of value %{value} on %{klass} is not
256256
allowed."
257257
summary: "Scopes in Mongoid must be procs that wrap criteria objects."
258-
resolution: "Change the scope to be a proc wrapped critera.\n\n
258+
resolution: "Change the scope to be a proc wrapped criteria.\n\n
259259
Example:\n
260260
\_\_class Band\n
261261
\_\_\_\_include Mongoid::Document\n
@@ -400,7 +400,7 @@ en:
400400
resolution: "Make sure some environment is set from the mentioned
401401
options. Mongoid cannot load configuration from the yaml without
402402
knowing which environment it is in, and we have considered
403-
defaulting to development an undesireable side effect of this not
403+
defaulting to development an undesirable side effect of this not
404404
being defined."
405405
no_map_reduce_output:
406406
message: "No output location was specified for the map/reduce
@@ -450,7 +450,7 @@ en:
450450
to connect."
451451
resolution: "Double check your mongoid.yml to make sure under the
452452
clients key that a configuration exists for '%{name}'. If you
453-
have set the configuration programatically, ensure that '%{name}'
453+
have set the configuration programmatically, ensure that '%{name}'
454454
exists in the configuration hash."
455455
no_clients_config:
456456
message: "No clients configuration provided."
@@ -542,13 +542,14 @@ en:
542542
unknown_attribute:
543543
message: "Attempted to set a value for '%{name}' which is not
544544
allowed on the model %{klass}."
545-
summary: "Without including Mongoid::Attributes::Dynamic in your model
546-
and the attribute does not already exist in the attributes hash,
547-
attempting to call %{klass}#%{name}= for it is not allowed. This is
548-
also triggered by passing the attribute to any method that accepts an
549-
attributes hash, and is raised instead of getting a NoMethodError."
550-
resolution: "You can include Mongoid::Attributes::Dynamic if you
551-
expect to be writing values for undefined fields often."
545+
summary: "%{klass}#%{name}= was called but there is no '%{name}'
546+
field defined in the model, and Mongoid::Attributes::Dynamic is
547+
not included. This error is also raised instead of NoMethodError
548+
if the unknown attribute is passed to any method that accepts an
549+
attributes hash, such as #attributes=."
550+
resolution: "Define the field '%{name}' in %{klass}, or include
551+
Mongoid::Attributes::Dynamic in %{klass} if you intend to
552+
store values in fields that are not explicitly defined."
552553
unknown_model:
553554
message: "Attempted to instantiate an object of the unknown Model '%{klass}'."
554555
summary: "A document with the value '%{value}' at the key '_type' was used to

spec/mongoid/errors/invalid_scope_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
it "contains the resolution in the message" do
2727
expect(error.message).to include(
28-
"Change the scope to be a proc wrapped critera."
28+
"Change the scope to be a proc wrapped criteria."
2929
)
3030
end
3131
end

spec/mongoid/errors/unknown_attribute_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
it "contains the summary in the message" do
2121
expect(error.message).to include(
22-
"Without including Mongoid::Attributes::Dynamic in your model"
22+
"Person#gender= was called but there is no 'gender'"
2323
)
2424
end
2525

2626
it "contains the resolution in the message" do
2727
expect(error.message).to include(
28-
"You can include Mongoid::Attributes::Dynamic"
28+
"Define the field 'gender' in Person, or include"
2929
)
3030
end
3131
end

0 commit comments

Comments
 (0)