File tree Expand file tree Collapse file tree
spec/requests/using_grape Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,8 +11,14 @@ class ArtworksEndpoint < Grape::API
1111 Artwork . find ( params [ :id ] )
1212 end
1313
14+ params do
15+ requires :amount_cents , type : Integer
16+ requires :artist_name , type : String
17+ requires :medium , type : String
18+ requires :title , type : String
19+ end
1420 post do
15- artwork = Artwork . new ( params )
21+ artwork = Artwork . new ( declared ( params , include_missing : false ) )
1622 if artwork . save
1723 artwork
1824 else
@@ -21,9 +27,15 @@ class ArtworksEndpoint < Grape::API
2127 end
2228 end
2329
30+ params do
31+ optional :amount_cents , type : Integer
32+ optional :artist_name , type : String
33+ optional :medium , type : String
34+ optional :title , type : String
35+ end
2436 put ":id" do
2537 artwork = Artwork . find ( params [ :id ] )
26- if artwork . update ( params )
38+ if artwork . update ( declared ( params , include_missing : false ) )
2739 artwork
2840 else
2941 errors = { errors : artwork . errors . full_messages . to_sentence }
Original file line number Diff line number Diff line change 66 params = { }
77 post "/api/using_grape/artworks" , params : params
88 expect ( response . status ) . to eq 400
9- expect ( response . parsed_body . key? ( "errors " ) ) . to eq true
9+ expect ( response . parsed_body . key? ( "error " ) ) . to eq true
1010 end
1111 end
1212
You can’t perform that action at this time.
0 commit comments