File tree Expand file tree Collapse file tree 2 files changed +22
-19
lines changed
Expand file tree Collapse file tree 2 files changed +22
-19
lines changed Original file line number Diff line number Diff line change 1- Boolean = Virtus ::Attribute ::Boolean
21
32module Grape
3+ class API
4+ Boolean = Virtus ::Attribute ::Boolean
5+ end
6+
47 module Validations
58
69 class CoerceValidator < SingleOptionValidator
Original file line number Diff line number Diff line change 11require 'spec_helper'
22
3+ class CoerceAPI < Grape ::API
4+ default_format :json
5+
6+ params do
7+ requires :int , :coerce => Integer
8+ optional :arr , :coerce => Array [ Integer ]
9+ optional :bool , :coerce => Array [ Boolean ]
10+ end
11+ get '/coerce' do
12+ {
13+ :int => params [ :int ] . class ,
14+ :arr => params [ :arr ] ? params [ :arr ] [ 0 ] . class : nil ,
15+ :bool => params [ :bool ] ? ( params [ :bool ] [ 0 ] == true ) && ( params [ :bool ] [ 1 ] == false ) : nil
16+ }
17+ end
18+ end
19+
320describe Grape ::Validations ::CoerceValidator do
421 def app ; @app ; end
522
623 before do
7- @app = Class . new ( Grape ::API ) do
8- default_format :json
9-
10- params do
11- requires :int , :coerce => Integer
12- optional :arr , :coerce => Array [ Integer ]
13- optional :bool , :coerce => Array [ Boolean ]
14- end
15- get '/coerce' do
16- {
17- :int => params [ :int ] . class ,
18- :arr => params [ :arr ] ? params [ :arr ] [ 0 ] . class : nil ,
19- :bool => params [ :bool ] ? ( params [ :bool ] [ 0 ] == true ) && ( params [ :bool ] [ 1 ] == false ) : nil
20- }
21- end
22-
23- end
24-
24+ @app = CoerceAPI
2525 end
2626
2727 # TOOD: Later when virtus can tell us that an input IS invalid
You can’t perform that action at this time.
0 commit comments