Skip to content

Commit ef41527

Browse files
committed
Fix specs
1 parent ea5b794 commit ef41527

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/mongoid/fields/field_types.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class << self
5050
def get(field_type)
5151
case field_type
5252
when Module
53-
field_type
53+
module_field_type(field_type)
5454
when Symbol, String
5555
mapping[field_type]
5656
else
@@ -83,6 +83,13 @@ def define_type(field_type, klass)
8383
def mapping
8484
@mapping ||= DEFAULT_MAPPING.dup
8585
end
86+
87+
private
88+
89+
def module_field_type(field_type)
90+
return Mongoid::Boolean if field_type.to_s == "Boolean"
91+
field_type
92+
end
8693
end
8794
end
8895
end

spec/mongoid/fields/field_types_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
end
2323

2424
context 'when value is a default mapped string' do
25-
let(:type) { 'double' }
25+
let(:type) { 'float' }
2626

2727
it 'uses the default mapped type' do
2828
is_expected.to eq Float
2929
end
3030
end
3131

3232
context 'when value is a custom mapped symbol' do
33-
before { described_class.define('number', Integer) }
33+
before { described_class.define_type('number', Integer) }
3434
let(:type) { :number }
3535

3636
it 'uses the custom mapped type' do
@@ -39,7 +39,7 @@
3939
end
4040

4141
context 'when value is a custom mapped string' do
42-
before { described_class.define(:number, Float) }
42+
before { described_class.define_type(:number, Float) }
4343
let(:type) { 'number' }
4444

4545
it 'uses the custom mapped type' do
@@ -94,25 +94,25 @@
9494
describe '.define' do
9595

9696
it 'can define a new type' do
97-
described_class.define(:my_string, String)
97+
described_class.define_type(:my_string, String)
9898
expect(described_class.get(:my_string)).to eq String
9999
end
100100

101101
it 'can override a default type' do
102-
described_class.define(:integer, String)
102+
described_class.define_type(:integer, String)
103103
expect(described_class.get(:integer)).to eq String
104104
end
105105

106106
it 'does not alter the DEFAULT_MAPPING constant' do
107-
described_class.define(:integer, String)
107+
described_class.define_type(:integer, String)
108108
expect(described_class::DEFAULT_MAPPING[:integer]).to eq Integer
109109
end
110110
end
111111

112112
describe '.delete' do
113113

114114
it 'can delete a custom type' do
115-
described_class.define(:my_string, String)
115+
described_class.define_type(:my_string, String)
116116
expect(described_class.get(:my_string)).to eq String
117117
described_class.delete('my_string')
118118
expect(described_class.get(:my_string)).to eq nil
@@ -136,7 +136,7 @@
136136
end
137137

138138
it 'can add a type' do
139-
described_class.define(:my_string, String)
139+
described_class.define_type(:my_string, String)
140140
expect(described_class.mapping[:my_string]).to eq(String)
141141
end
142142

0 commit comments

Comments
 (0)