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 6
6
7
7
#### Fixes
8
8
9
- * Your contribution here .
9
+ * [ # 1971 ] ( https://github.com/ruby-grape/grape/pull/1971 ) : Fix BigDecimal coercion - [ @ FlickStuart ] ( https://github.com/FlickStuart ) .
10
10
* [ #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 ) .
11
11
12
12
### 1.3.0 (2020/01/11)
Original file line number Diff line number Diff line change @@ -12,11 +12,13 @@ class PrimitiveCoercer < DryTypeCoercer
12
12
Grape ::API ::Boolean => DryTypes ::Params ::Bool ,
13
13
14
14
# unfortunatelly, a +Params+ scope doesn't contain String
15
- String => DryTypes ::Coercible ::String
15
+ String => DryTypes ::Coercible ::String ,
16
+ BigDecimal => DryTypes ::Coercible ::Decimal
16
17
} . freeze
17
18
18
19
STRICT_MAPPING = {
19
- Grape ::API ::Boolean => DryTypes ::Strict ::Bool
20
+ Grape ::API ::Boolean => DryTypes ::Strict ::Bool ,
21
+ BigDecimal => DryTypes ::Strict ::Decimal
20
22
} . freeze
21
23
22
24
def initialize ( type , strict = false )
Original file line number Diff line number Diff line change @@ -154,6 +154,19 @@ def self.parsed?(value)
154
154
end
155
155
156
156
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
+
157
170
it 'Integer' do
158
171
subject . params do
159
172
requires :int , coerce : Integer
You can’t perform that action at this time.
0 commit comments