@@ -10,52 +10,48 @@ class User
1010 attribute :name , String
1111 end
1212
13- end
13+ class API < Grape ::API
14+ default_format :json
1415
1516
16- class CoerceAPI < Grape ::API
17- default_format :json
18-
19-
20- params do
21- requires :int , :coerce => Integer
22- end
23- get '/single' do
24- end
25-
26- params do
27- requires :ids , type : Array [ Integer ]
28- end
29- get '/arr' do
30- end
31-
32- params do
33- requires :user , type : CoerceTest ::User
34- end
35- get '/user' do
36- end
37-
38- params do
39- requires :int , :coerce => Integer
40- optional :arr , :coerce => Array [ Integer ]
41- optional :bool , :coerce => Array [ Boolean ]
42- end
43- get '/coerce' do
44- {
45- :int => params [ :int ] . class ,
46- :arr => params [ :arr ] ? params [ :arr ] [ 0 ] . class : nil ,
47- :bool => params [ :bool ] ? ( params [ :bool ] [ 0 ] == true ) && ( params [ :bool ] [ 1 ] == false ) : nil
48- }
17+ params do
18+ requires :int , :coerce => Integer
19+ end
20+ get '/single' do
21+ end
22+
23+ params do
24+ requires :ids , type : Array [ Integer ]
25+ end
26+ get '/arr' do
27+ end
28+
29+ params do
30+ requires :user , type : CoerceTest ::User
31+ end
32+ get '/user' do
33+ end
34+
35+ params do
36+ requires :int , :coerce => Integer
37+ optional :arr , :coerce => Array [ Integer ]
38+ optional :bool , :coerce => Array [ Boolean ]
39+ end
40+ get '/coerce' do
41+ {
42+ :int => params [ :int ] . class ,
43+ :arr => params [ :arr ] ? params [ :arr ] [ 0 ] . class : nil ,
44+ :bool => params [ :bool ] ? ( params [ :bool ] [ 0 ] == true ) && ( params [ :bool ] [ 1 ] == false ) : nil
45+ }
46+ end
4947 end
5048end
5149
5250describe Grape ::Validations ::CoerceValidator do
53- def app ; @app ; end
54-
55- before do
56- @app = CoerceAPI
51+ def app
52+ CoerceTest ::API
5753 end
58-
54+
5955 it "should return an error on malformed input" do
6056 get '/single' , :int => "43a"
6157 last_response . status . should == 400
0 commit comments