forked from ruby-grape/grape-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extensions_spec.rb
131 lines (111 loc) · 4.05 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
require 'spec_helper'
describe GrapeSwagger::DocMethods::Extensions do
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