-
Notifications
You must be signed in to change notification settings - Fork 470
/
extensions_spec.rb
185 lines (155 loc) · 5.43 KB
/
extensions_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# frozen_string_literal: true
require 'spec_helper'
describe GrapeSwagger::DocMethods::Extensions do
context 'it should not break method introspection' do
describe '.method' do
describe 'method introspection' do
specify do
expect(described_class.method(described_class.methods.first)).to be_a(Method)
end
end
end
end
describe '#find_definition' do
subject { described_class }
let(:method) { :get }
let(:status) { 200 }
before { allow(subject).to receive(:method).and_return(method) }
describe 'no response for status' do
let(:path) { { get: { responses: {} } } }
specify do
definition = subject.find_definition(status, path)
expect(definition).to be_nil
end
end
describe 'response found' do
let(:model) { 'Item' }
describe 'ref given' do
let(:path) do
{ get: { responses: { 200 => { schema: { '$ref' => "#/definitions/#{model}" } } } } }
end
specify do
definition = subject.find_definition(status, path)
expect(definition).to eql model
end
end
describe 'items given' do
let(:path) do
{ get: { responses: { 200 => { schema: { 'items' => { '$ref' => "#/definitions/#{model}" } } } } } }
end
specify do
definition = subject.find_definition(status, path)
expect(definition).to eql model
end
end
end
end
describe '#extended? and extension' do
subject { described_class }
describe 'return false (default)' do
let(:part) { { foo: 'bar', bar: 'foo' } }
specify do
expect(subject.extended?(part)).to be false
expect(subject.extension(part)).to be_empty
end
end
describe 'return true' do
specify do
part = { foo: 'bar', bar: 'foo', x: 'something' }
expect(subject.extended?(part)).to be true
expect(subject.extension(part)).to eql(x: 'something')
expect(subject.extended?(part, :x)).to be true
expect(subject.extension(part, :x)).to eql(x: 'something')
end
specify do
part = { foo: 'bar', bar: 'foo', x_path: 'something' }
expect(subject.extended?(part, :x_path)).to be true
expect(subject.extension(part, :x_path)).to eql(x_path: 'something')
end
specify do
part = { foo: 'bar', bar: 'foo', x_def: 'something' }
expect(subject.extended?(part, :x_def)).to be true
expect(subject.extension(part, :x_def)).to eql(x_def: 'something')
end
specify do
part = { foo: 'bar', bar: 'foo', x_path: 'something', x_def: 'something' }
expect(subject.extended?(part, :x_path)).to be true
expect(subject.extension(part, :x_path)).to eql(x_path: 'something')
expect(subject.extended?(part, :x_def)).to be true
expect(subject.extension(part, :x_def)).to eql(x_def: 'something')
end
end
end
describe 'concatenate' do
describe 'not nested' do
describe 'simple' do
let(:extensions) { { x: { key_1: 'foo' } } }
let(:result) { { 'x-key_1' => 'foo' } }
subject { described_class.concatenate(extensions) }
specify do
expect(subject).to eql result
end
end
describe 'multiple' do
let(:extensions) { { x: { key_1: 'foo', key_2: 'bar' } } }
let(:result) { { 'x-key_1' => 'foo', 'x-key_2' => 'bar' } }
subject { described_class.concatenate(extensions) }
specify do
expect(subject).to eql result
end
end
end
describe 'nested' do
describe 'simple' do
let(:extensions) { { x: { key_1: { key_2: 'foo' } } } }
let(:result) { { 'x-key_1' => { key_2: 'foo' } } }
subject { described_class.concatenate(extensions) }
specify do
expect(subject).to eql result
end
end
describe 'simple multiple' do
let(:extensions) { { x: { key_1: { key_2: 'foo', key_3: 'bar' } } } }
let(:result) { { 'x-key_1' => { key_2: 'foo', key_3: 'bar' } } }
subject { described_class.concatenate(extensions) }
specify do
expect(subject).to eql result
end
end
describe 'simple deeper' do
let(:extensions) { { x: { key_1: { key_2: { key_3: 'foo' } } } } }
let(:result) { { 'x-key_1' => { key_2: { key_3: 'foo' } } } }
subject { described_class.concatenate(extensions) }
specify do
expect(subject).to eql result
end
end
describe 'multiple' do
let(:extensions) { { x: { key_1: { key_3: 'foo' }, key_2: { key_3: 'bar' } } } }
let(:result) { { 'x-key_1' => { key_3: 'foo' }, 'x-key_2' => { key_3: 'bar' } } }
subject { described_class.concatenate(extensions) }
specify do
expect(subject).to eql result
end
end
end
describe 'real example' do
let(:extensions) do
{ x: {
'amazon-apigateway-auth' => { type: 'none' },
'amazon-apigateway-integration' => { type: 'aws', uri: 'foo_bar_uri', httpMethod: 'get' }
} }
end
let(:result) do
{
'x-amazon-apigateway-auth' => { type: 'none' },
'x-amazon-apigateway-integration' => { type: 'aws', uri: 'foo_bar_uri', httpMethod: 'get' }
}
end
subject { described_class.concatenate(extensions) }
specify do
expect(subject).to eql result
end
end
end
end