-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathdocumentation_spec.rb
57 lines (44 loc) · 1.45 KB
/
documentation_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true
describe Grape::API do
subject { Class.new(described_class) }
let(:app) { subject }
context 'an endpoint with documentation' do
it 'documents parameters' do
subject.params do
requires 'price', type: Float, desc: 'Sales price'
end
subject.get '/'
expect(subject.routes.first.params['price']).to eq(required: true,
type: 'Float',
desc: 'Sales price')
end
it 'allows documentation with a hash' do
documentation = { example: 'Joe' }
subject.params do
requires 'first_name', documentation: documentation
end
subject.get '/'
expect(subject.routes.first.params['first_name'][:documentation]).to eq(documentation)
end
end
context 'an endpoint without documentation' do
before do
subject.do_not_document!
subject.params do
requires :city, type: String, desc: 'Should be ignored'
optional :postal_code, type: Integer
end
subject.post '/' do
declared(params).to_json
end
end
it 'does not document parameters for the endpoint' do
expect(subject.routes.first.params).to eq({})
end
it 'still declares params internally' do
data = { city: 'Berlin', postal_code: 10_115 }
post '/', data
expect(last_response.body).to eq(data.to_json)
end
end
end