File tree Expand file tree Collapse file tree 4 files changed +28
-2
lines changed Expand file tree Collapse file tree 4 files changed +28
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 #
Original file line number Diff line number Diff line change 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
131148end
Original file line number Diff line number Diff 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
18411847end
You can’t perform that action at this time.
0 commit comments