-
Notifications
You must be signed in to change notification settings - Fork 476
/
Copy pathpath_string_spec.rb
101 lines (89 loc) · 4.94 KB
/
path_string_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
# frozen_string_literal: true
require 'spec_helper'
describe GrapeSwagger::DocMethods::PathString do
subject { described_class }
specify { expect(subject).to eql GrapeSwagger::DocMethods::PathString }
specify { expect(subject).to respond_to :build }
describe 'path_string_object' do
specify 'The original route path is not mutated' do
route = Struct.new(:version, :path).new
route.path = '/foo/:dynamic/bar'
subject.build(route, route.path.dup, add_version: true)
expect(route.path).to eq '/foo/:dynamic/bar'
end
describe 'version' do
describe 'defaults: given, true' do
let(:options) { { add_version: true } }
let(:route) { Struct.new(:version, :path).new('v1') }
specify 'The returned path includes version' do
route.path = '/{version}/thing(.json)'
expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/v1/thing']
route.path = '/{version}/thing/foo(.json)'
expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/v1/thing/foo']
route.path = '/{version}/thing(.:format)'
expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/v1/thing']
route.path = '/{version}/thing/foo(.:format)'
expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/v1/thing/foo']
route.path = '/{version}/thing/:id'
expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/v1/thing/{id}']
route.path = '/{version}/thing/foo/:id'
expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/v1/thing/foo/{id}']
end
end
describe 'defaults: not given, both false' do
let(:options) { { add_version: false } }
let(:route) { Struct.new(:version, :path).new }
specify 'The returned path does not include version' do
route.path = '/{version}/thing(.json)'
expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing']
route.path = '/{version}/thing/foo(.json)'
expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo']
route.path = '/{version}/thing(.:format)'
expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing']
route.path = '/{version}/thing/foo(.:format)'
expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo']
route.path = '/{version}/thing/:id'
expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing/{id}']
route.path = '/{version}/thing/foo/:id'
expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo/{id}']
end
end
describe 'defaults: add_version false' do
let(:options) { { add_version: false } }
let(:route) { Struct.new(:version, :path).new('v1') }
specify 'The returned path does not include version' do
route.path = '/{version}/thing(.json)'
expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing']
route.path = '/{version}/thing/foo(.json)'
expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo']
route.path = '/{version}/thing(.:format)'
expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing']
route.path = '/{version}/thing/foo(.:format)'
expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo']
route.path = '/{version}/thing/:id'
expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing/{id}']
route.path = '/{version}/thing/foo/:id'
expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo/{id}']
end
end
describe 'defaults: root_version nil' do
let(:options) { { add_version: true } }
let(:route) { Struct.new(:version, :path).new }
specify 'The returned path does not include version' do
route.path = '/{version}/thing(.json)'
expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing']
route.path = '/{version}/thing/foo(.json)'
expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo']
route.path = '/{version}/thing(.:format)'
expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing']
route.path = '/{version}/thing/foo(.:format)'
expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo']
route.path = '/{version}/thing/:id'
expect(subject.build(route, route.path.dup, options)).to eql ['Thing', '/thing/{id}']
route.path = '/{version}/thing/foo/:id'
expect(subject.build(route, route.path.dup, options)).to eql ['Foo', '/thing/foo/{id}']
end
end
end
end
end