@@ -69,31 +69,36 @@ def to_xml
6969
7070 context 'Accept header detection' do
7171 it 'should detect from the Accept header' do
72- subject . call ( { 'PATH_INFO' => '/info' , 'Accept ' => 'application/xml' } )
72+ subject . call ( { 'PATH_INFO' => '/info' , 'HTTP_ACCEPT ' => 'application/xml' } )
7373 subject . env [ 'api.format' ] . should == :xml
7474 end
7575
7676 it 'should look for case-indifferent headers' do
77- subject . call ( { 'PATH_INFO' => '/info' , 'accept ' => 'application/xml' } )
77+ subject . call ( { 'PATH_INFO' => '/info' , 'http_accept ' => 'application/xml' } )
7878 subject . env [ 'api.format' ] . should == :xml
7979 end
8080
8181 it 'should use quality rankings to determine formats' do
82- subject . call ( { 'PATH_INFO' => '/info' , 'Accept ' => 'application/json; q=0.3,application/xml; q=1.0' } )
82+ subject . call ( { 'PATH_INFO' => '/info' , 'HTTP_ACCEPT ' => 'application/json; q=0.3,application/xml; q=1.0' } )
8383 subject . env [ 'api.format' ] . should == :xml
84- subject . call ( { 'PATH_INFO' => '/info' , 'Accept ' => 'application/json; q=1.0,application/xml; q=0.3' } )
84+ subject . call ( { 'PATH_INFO' => '/info' , 'HTTP_ACCEPT ' => 'application/json; q=1.0,application/xml; q=0.3' } )
8585 subject . env [ 'api.format' ] . should == :json
8686 end
8787
8888 it 'should handle quality rankings mixed with nothing' do
89- subject . call ( { 'PATH_INFO' => '/info' , 'Accept ' => 'application/json,application/xml; q=1.0' } )
89+ subject . call ( { 'PATH_INFO' => '/info' , 'HTTP_ACCEPT ' => 'application/json,application/xml; q=1.0' } )
9090 subject . env [ 'api.format' ] . should == :xml
9191 end
9292
9393 it 'should properly parse headers with other attributes' do
94- subject . call ( { 'PATH_INFO' => '/info' , 'Accept ' => 'application/json; abc=2.3; q=1.0,application/xml; q=0.7' } )
94+ subject . call ( { 'PATH_INFO' => '/info' , 'HTTP_ACCEPT ' => 'application/json; abc=2.3; q=1.0,application/xml; q=0.7' } )
9595 subject . env [ 'api.format' ] . should == :json
9696 end
97+
98+ it 'should properly parse headers with vendor and api version' do
99+ subject . call ( { 'PATH_INFO' => '/info' , 'HTTP_ACCEPT' => 'application/vnd.test-v1+xml' } )
100+ subject . env [ 'api.format' ] . should == :xml
101+ end
97102 end
98103
99104 context 'Content-type' do
@@ -137,16 +142,16 @@ def to_xml
137142
138143 context 'Input' do
139144 it 'should parse the body from a POST/PUT and put the contents into rack.request.form_hash' do
140- subject . call ( { 'PATH_INFO' => '/info' , 'Accept ' => 'application/json' , 'rack.input' => StringIO . new ( '{"is_boolean":true,"string":"thing"}' ) } )
145+ subject . call ( { 'PATH_INFO' => '/info' , 'HTTP_ACCEPT ' => 'application/json' , 'rack.input' => StringIO . new ( '{"is_boolean":true,"string":"thing"}' ) } )
141146 subject . env [ 'rack.request.form_hash' ] [ 'is_boolean' ] . should be_true
142147 subject . env [ 'rack.request.form_hash' ] [ 'string' ] . should == 'thing'
143148 end
144149 it 'should parse the body from an xml POST/PUT and put the contents into rack.request.from_hash' do
145- subject . call ( { 'PATH_INFO' => '/info.xml' , 'Accept ' => 'application/xml' , 'rack.input' => StringIO . new ( '<thing><name>Test</name></thing>' ) } )
150+ subject . call ( { 'PATH_INFO' => '/info.xml' , 'HTTP_ACCEPT ' => 'application/xml' , 'rack.input' => StringIO . new ( '<thing><name>Test</name></thing>' ) } )
146151 subject . env [ 'rack.request.form_hash' ] [ 'thing' ] [ 'name' ] . should == 'Test'
147152 end
148153 it 'should be able to fail gracefully if the body is regular POST content' do
149- subject . call ( { 'PATH_INFO' => '/info' , 'Accept ' => 'application/json' , 'rack.input' => StringIO . new ( 'name=Other+Test+Thing' ) } )
154+ subject . call ( { 'PATH_INFO' => '/info' , 'HTTP_ACCEPT ' => 'application/json' , 'rack.input' => StringIO . new ( 'name=Other+Test+Thing' ) } )
150155 subject . env [ 'rack.request.form_hash' ] . should be_nil
151156 end
152157 end
0 commit comments