File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed
lib/grape/validations/types
spec/grape/validations/validators Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 66
77#### Fixes
88
9- * Your contribution here .
9+ * [ # 1971 ] ( https://github.com/ruby-grape/grape/pull/1971 ) : Fix BigDecimal coercion - [ @ FlickStuart ] ( https://github.com/FlickStuart ) .
1010* [ #1968 ] ( https://github.com/ruby-grape/grape/pull/1968 ) : Fix args forwarding in Grape::Middleware::Stack#merge_with for ruby 2.7.0 - [ @dm1try ] ( https://github.com/dm1try ) .
1111
1212### 1.3.0 (2020/01/11)
Original file line number Diff line number Diff line change @@ -12,11 +12,13 @@ class PrimitiveCoercer < DryTypeCoercer
1212 Grape ::API ::Boolean => DryTypes ::Params ::Bool ,
1313
1414 # unfortunatelly, a +Params+ scope doesn't contain String
15- String => DryTypes ::Coercible ::String
15+ String => DryTypes ::Coercible ::String ,
16+ BigDecimal => DryTypes ::Coercible ::Decimal
1617 } . freeze
1718
1819 STRICT_MAPPING = {
19- Grape ::API ::Boolean => DryTypes ::Strict ::Bool
20+ Grape ::API ::Boolean => DryTypes ::Strict ::Bool ,
21+ BigDecimal => DryTypes ::Strict ::Decimal
2022 } . freeze
2123
2224 def initialize ( type , strict = false )
Original file line number Diff line number Diff line change @@ -154,6 +154,19 @@ def self.parsed?(value)
154154 end
155155
156156 context 'coerces' do
157+ it 'BigDecimal' do
158+ subject . params do
159+ requires :bigdecimal , coerce : BigDecimal
160+ end
161+ subject . get '/bigdecimal' do
162+ params [ :bigdecimal ] . class
163+ end
164+
165+ get '/bigdecimal' , bigdecimal : '45'
166+ expect ( last_response . status ) . to eq ( 200 )
167+ expect ( last_response . body ) . to eq ( 'BigDecimal' )
168+ end
169+
157170 it 'Integer' do
158171 subject . params do
159172 requires :int , coerce : Integer
You can’t perform that action at this time.
0 commit comments