File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe Grape ::Endpoint do
4
+ subject { Class . new ( Grape ::API ) }
5
+
6
+ def app
7
+ subject
8
+ end
9
+
10
+ before do
11
+ subject . namespace do
12
+ format :json
13
+ content_type :json , 'application/json'
14
+ params do
15
+ requires :id , desc : 'Identifier.'
16
+ end
17
+ get ':id' do
18
+ {
19
+ id : params [ :id ] ,
20
+ format : params [ :format ]
21
+ }
22
+ end
23
+ end
24
+ end
25
+
26
+ context 'get' do
27
+ it 'no format' do
28
+ get '/foo'
29
+ expect ( last_response . status ) . to eq 200
30
+ expect ( last_response . body ) . to eq ( MultiJson . dump ( id : 'foo' , format : nil ) )
31
+ end
32
+ it 'json format' do
33
+ get '/foo.json'
34
+ expect ( last_response . status ) . to eq 200
35
+ expect ( last_response . body ) . to eq ( MultiJson . dump ( id : 'foo' , format : 'json' ) )
36
+ end
37
+ it 'invalid format' do
38
+ get '/foo.invalid'
39
+ expect ( last_response . status ) . to eq 200
40
+ expect ( last_response . body ) . to eq ( MultiJson . dump ( id : 'foo' , format : 'invalid' ) )
41
+ end
42
+ end
43
+ end
You can’t perform that action at this time.
0 commit comments