| 
									
										
										
										
											2017-03-08 16:32:31 +08:00
										 |  |  | # frozen_string_literal: true | 
					
						
							| 
									
										
										
										
											2017-03-28 17:15:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-16 08:18:07 +08:00
										 |  |  | 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 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 04:59:31 +08:00
										 |  |  |   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, add_version: true) | 
					
						
							|  |  |  |       expect(route.path).to eq '/foo/:dynamic/bar' | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-16 08:18:07 +08:00
										 |  |  |     describe 'version' do | 
					
						
							| 
									
										
										
										
											2016-05-29 06:29:31 +08:00
										 |  |  |       describe 'defaults: given, true' do | 
					
						
							|  |  |  |         let(:options) { { add_version: true } } | 
					
						
							| 
									
										
										
										
											2016-05-30 17:03:43 +08:00
										 |  |  |         let(:route) { Struct.new(:version, :path).new('v1') } | 
					
						
							| 
									
										
										
										
											2016-05-29 06:29:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         specify 'The returned path includes version' do | 
					
						
							| 
									
										
										
										
											2016-05-30 17:03:43 +08:00
										 |  |  |           route.path = '/{version}/thing(.json)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Thing', '/v1/thing'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/foo(.json)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Foo', '/v1/thing/foo'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing(.:format)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Thing', '/v1/thing'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/foo(.:format)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Foo', '/v1/thing/foo'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/:id' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Thing', '/v1/thing/{id}'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/foo/:id' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Foo', '/v1/thing/foo/{id}'] | 
					
						
							| 
									
										
										
										
											2016-05-29 06:29:31 +08:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       describe 'defaults: not given, both false' do | 
					
						
							| 
									
										
										
										
											2016-05-07 03:00:36 +08:00
										 |  |  |         let(:options) { { add_version: false } } | 
					
						
							| 
									
										
										
										
											2016-05-30 17:03:43 +08:00
										 |  |  |         let(:route) { Struct.new(:version, :path).new } | 
					
						
							| 
									
										
										
										
											2016-03-16 08:18:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 06:29:31 +08:00
										 |  |  |         specify 'The returned path does not include version' do | 
					
						
							| 
									
										
										
										
											2016-05-30 17:03:43 +08:00
										 |  |  |           route.path = '/{version}/thing(.json)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Thing', '/thing'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/foo(.json)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Foo', '/thing/foo'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing(.:format)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Thing', '/thing'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/foo(.:format)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Foo', '/thing/foo'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/:id' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Thing', '/thing/{id}'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/foo/:id' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Foo', '/thing/foo/{id}'] | 
					
						
							| 
									
										
										
										
											2016-03-16 08:18:07 +08:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 06:29:31 +08:00
										 |  |  |       describe 'defaults: add_version false' do | 
					
						
							|  |  |  |         let(:options) { { add_version: false } } | 
					
						
							| 
									
										
										
										
											2016-05-30 17:03:43 +08:00
										 |  |  |         let(:route) { Struct.new(:version, :path).new('v1') } | 
					
						
							| 
									
										
										
										
											2016-05-29 06:29:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         specify 'The returned path does not include version' do | 
					
						
							| 
									
										
										
										
											2016-05-30 17:03:43 +08:00
										 |  |  |           route.path = '/{version}/thing(.json)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Thing', '/thing'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/foo(.json)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Foo', '/thing/foo'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing(.:format)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Thing', '/thing'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/foo(.:format)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Foo', '/thing/foo'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/:id' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Thing', '/thing/{id}'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/foo/:id' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Foo', '/thing/foo/{id}'] | 
					
						
							| 
									
										
										
										
											2016-05-29 06:29:31 +08:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       describe 'defaults: root_version nil' do | 
					
						
							|  |  |  |         let(:options) { { add_version: true } } | 
					
						
							| 
									
										
										
										
											2016-05-30 17:03:43 +08:00
										 |  |  |         let(:route) { Struct.new(:version, :path).new } | 
					
						
							| 
									
										
										
										
											2016-05-29 06:29:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         specify 'The returned path does not include version' do | 
					
						
							| 
									
										
										
										
											2016-05-30 17:03:43 +08:00
										 |  |  |           route.path = '/{version}/thing(.json)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Thing', '/thing'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/foo(.json)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Foo', '/thing/foo'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing(.:format)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Thing', '/thing'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/foo(.:format)' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Foo', '/thing/foo'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/:id' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Thing', '/thing/{id}'] | 
					
						
							|  |  |  |           route.path = '/{version}/thing/foo/:id' | 
					
						
							|  |  |  |           expect(subject.build(route, options)).to eql ['Foo', '/thing/foo/{id}'] | 
					
						
							| 
									
										
										
										
											2016-03-16 08:18:07 +08:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |