Skip to content

Commit 9647e35

Browse files
committed
Deprecate Mongoid::Fields::TYPE_MAPPINGS
1 parent ae79f02 commit 9647e35

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

lib/mongoid/fields.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ module Mongoid
1212
module Fields
1313
extend ActiveSupport::Concern
1414

15+
# @deprecated Use Mongoid::Fields::FieldTypes.mapping instead
16+
TYPE_MAPPINGS = ::Mongoid::Fields::FieldTypes::DEFAULT_MAPPING
17+
1518
StringifiedSymbol = Mongoid::StringifiedSymbol
1619
Boolean = Mongoid::Boolean
1720

lib/mongoid/fields/field_types.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ def define(type, klass)
6464

6565
delegate :delete, to: :mapping
6666

67-
private
68-
6967
# The memoized mapping of field type definitions to classes.
7068
#
7169
# @return [ ActiveSupport::HashWithIndifferentAccess<Symbol, Class> ] The memoized field mapping.
7270
def mapping
7371
@mapping ||= DEFAULT_MAPPING.dup
7472
end
7573

74+
private
75+
7676
# Handles fallback for case where mapping does not contain the
7777
# requested type.
7878
#

spec/mongoid/fields/field_types_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,21 @@
128128
expect(described_class::DEFAULT_MAPPING[:integer]).to eq Integer
129129
end
130130
end
131+
132+
describe '.mapping' do
133+
134+
it 'returns the default mapping by default' do
135+
expect(described_class.mapping).to eq described_class::DEFAULT_MAPPING
136+
end
137+
138+
it 'can add a type' do
139+
described_class.define(:my_string, String)
140+
expect(described_class.mapping[:my_string]).to eq(String)
141+
end
142+
143+
it 'can delete a default type' do
144+
described_class.delete(:integer)
145+
expect(described_class.mapping).to_not have_key(:integer)
146+
end
147+
end
131148
end

spec/mongoid/fields_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,4 +1838,10 @@ def self.model_name
18381838
end
18391839
end
18401840
end
1841+
1842+
describe '::TYPE_MAPPINGS' do
1843+
it 'returns the default mapping' do
1844+
expect(described_class::TYPE_MAPPINGS).to eq ::Mongoid::Fields::FieldTypes::DEFAULT_MAPPING
1845+
end
1846+
end
18411847
end

0 commit comments

Comments
 (0)