Skip to content

Commit 6664977

Browse files
committed
Rename InvalidFieldType --> UnknownFieldType
1 parent 89571ac commit 6664977

File tree

7 files changed

+30
-30
lines changed

7 files changed

+30
-30
lines changed

docs/release-notes/mongoid-8.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ Mongoid 8 behavior:
288288
include Mongoid::Document
289289

290290
field :name, type: :bogus
291-
# => raises Mongoid::Errors::InvalidFieldType
291+
# => raises Mongoid::Errors::UnknownFieldType
292292
end
293293

294294
Mongoid 7 behavior:

lib/config/locales/en.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,6 @@ en:
175175
\_\_end\n\n
176176
Refer to:
177177
https://docs.mongodb.com/mongoid/current/reference/fields/#custom-field-options"
178-
invalid_field_type:
179-
message: "Invalid field type %{type_inspection} for field '%{field}' on model '%{klass}'."
180-
summary: "Model '%{klass}' declares a field '%{field}' with an unknown type value
181-
%{type_inspection}. This value is neither present in Mongoid's default type mapping,
182-
nor defined in a custom field type mapping."
183-
resolution: "Please provide a valid type value for the field. If you
184-
meant to define a custom field type, please do so first as follows:\n\n
185-
\_\_Mongoid::Fields.configure do\n
186-
\_\_\_\_define_type %{type_inspection}, YourTypeClass
187-
\_\_end\n
188-
\_\_class %{klass}\n
189-
\_\_\_\_include Mongoid::Document\n
190-
\_\_\_\_field :%{field}, type: %{type_inspection}\n
191-
\_\_end\n\n
192-
Refer to:
193-
https://docs.mongodb.com/mongoid/current/reference/fields/#custom-field-types"
194178
invalid_includes:
195179
message: "Invalid includes directive: %{klass}.includes(%{args})"
196180
summary: "Eager loading in Mongoid only supports providing arguments
@@ -572,6 +556,22 @@ en:
572556
resolution: "Define the field '%{name}' in %{klass}, or include
573557
Mongoid::Attributes::Dynamic in %{klass} if you intend to
574558
store values in fields that are not explicitly defined."
559+
unknown_field_type:
560+
message: "Unknown field type %{type_inspection} for field '%{field}' on model '%{klass}'."
561+
summary: "Model '%{klass}' declares a field '%{field}' with an unknown type value
562+
%{type_inspection}. This value is neither present in Mongoid's default type mapping,
563+
nor defined in a custom field type mapping."
564+
resolution: "Please provide a known type value for the field. If you
565+
meant to define a custom field type, please do so first as follows:\n\n
566+
\_\_Mongoid::Fields.configure do\n
567+
\_\_\_\_define_type %{type_inspection}, YourTypeClass
568+
\_\_end\n
569+
\_\_class %{klass}\n
570+
\_\_\_\_include Mongoid::Document\n
571+
\_\_\_\_field :%{field}, type: %{type_inspection}\n
572+
\_\_end\n\n
573+
Refer to:
574+
https://docs.mongodb.com/mongoid/current/reference/fields/#custom-field-types"
575575
unknown_model:
576576
message: "Attempted to instantiate an object of the unknown model '%{klass}'."
577577
summary: "A document with the value '%{value}' at the key '_type' was used to

lib/mongoid/errors/invalid_field_type.rb renamed to lib/mongoid/errors/unknown_field_type.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ module Errors
55

66
# This error is raised when trying to define a field using a :type option value
77
# that is not present in the field type mapping.
8-
class InvalidFieldType < MongoidError
8+
class UnknownFieldType < MongoidError
99

1010
# Create the new error.
1111
#
1212
# @example Instantiate the error.
13-
# InvalidFieldType.new('Person', 'first_name', 'stringgy')
13+
# UnknownFieldType.new('Person', 'first_name', 'stringgy')
1414
#
1515
# @param [ String ] klass The model class.
1616
# @param [ String ] field The field on which the invalid type is used.
1717
# @param [ Symbol | String ] type The value of the field :type option.
1818
def initialize(klass, field, type)
1919
super(
20-
compose_message('invalid_field_type',
20+
compose_message('unknown_field_type',
2121
klass: klass, field: field, type_inspection: type.inspect)
2222
)
2323
end

lib/mongoid/fields.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ def field_for(name, options)
742742
if type = options[:type]
743743
type = Fields::FieldTypes.get(type)
744744
unless type
745-
raise Mongoid::Errors::InvalidFieldType.new(self.name, field, type)
745+
raise Mongoid::Errors::UnknownFieldType.new(self.name, field, type)
746746
end
747747
opts[:type] = type
748748
end

lib/mongoid/fields/field_types.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def get(field_type)
5454
when Symbol, String
5555
mapping[field_type]
5656
else
57-
raise Mongoid::Errors::InvalidFieldType.new(self.name, field, field_type)
57+
raise Mongoid::Errors::UnknownFieldType.new(self.name, field, field_type)
5858
end
5959
end
6060

spec/mongoid/errors/invalid_field_type_spec.rb renamed to spec/mongoid/errors/unknown_field_type_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "spec_helper"
44

5-
describe Mongoid::Errors::InvalidFieldType do
5+
describe Mongoid::Errors::UnknownFieldType do
66

77
describe "#message" do
88

@@ -17,7 +17,7 @@
1717

1818
it "contains the problem in the message" do
1919
expect(error.message).to include(
20-
"Invalid field type :stringgy for field 'first_name' on model 'Person'."
20+
"Unknown field type :stringgy for field 'first_name' on model 'Person'."
2121
)
2222
end
2323

@@ -35,7 +35,7 @@
3535

3636
it "contains the problem in the message" do
3737
expect(error.message).to include(
38-
%q,Invalid field type "stringgy" for field 'first_name' on model 'Person'.,
38+
%q,Unknown field type "stringgy" for field 'first_name' on model 'Person'.,
3939
)
4040
end
4141

@@ -48,7 +48,7 @@
4848

4949
it "contains the resolution in the message" do
5050
expect(error.message).to include(
51-
'Please provide a valid type value for the field.'
51+
'Please provide a known type value for the field.'
5252
)
5353
end
5454
end

spec/mongoid/fields_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,18 +363,18 @@
363363
end
364364

365365
context 'when using an unknown symbol' do
366-
it 'raises InvalidFieldType' do
366+
it 'raises UnknownFieldType' do
367367
lambda do
368368
klass.field(:test, type: :bogus)
369-
end.should raise_error(Mongoid::Errors::InvalidFieldType, /declares a field 'test' with an unknown type value :bogus/)
369+
end.should raise_error(Mongoid::Errors::UnknownFieldType, /declares a field 'test' with an unknown type value :bogus/)
370370
end
371371
end
372372

373373
context 'when using an unknown string' do
374-
it 'raises InvalidFieldType' do
374+
it 'raises UnknownFieldType' do
375375
lambda do
376376
klass.field(:test, type: 'bogus')
377-
end.should raise_error(Mongoid::Errors::InvalidFieldType, /declares a field 'test' with an unknown type value "bogus"/)
377+
end.should raise_error(Mongoid::Errors::UnknownFieldType, /declares a field 'test' with an unknown type value "bogus"/)
378378
end
379379
end
380380
end

0 commit comments

Comments
 (0)