spec/angelo_spec.rb in angelo-0.1.5 vs spec/angelo_spec.rb in angelo-0.1.6
- old
+ new
@@ -120,10 +120,40 @@
end
end
end
+ describe 'headers helper' do
+
+ headers_count = 0
+
+ define_app do
+
+ put '/incr' do
+ headers 'X-Http-Angelo-Server' => 'catbutt' if headers_count % 2 == 0
+ headers_count += 1
+ ''
+ end
+
+ end
+
+ it 'sets headers for a response' do
+ put '/incr'
+ expect(last_response.headers['X-Http-Angelo-Server']).to eq('catbutt')
+ end
+
+ it 'does not carry headers over responses' do
+ headers_count = 0
+ put '/incr'
+ expect(last_response.headers['X-Http-Angelo-Server']).to eq('catbutt')
+
+ put '/incr'
+ expect(last_response.headers['X-Http-Angelo-Server']).to be_nil
+ end
+
+ end
+
describe 'content_type helper' do
describe 'when in route block' do
define_app do
@@ -309,9 +339,44 @@
end
it 'does not parse body when request content-type not set' do
post '/json', obj, {'Content-Type' => ''}
last_response_should_be_json({})
+ end
+
+ end
+
+ describe 'request_headers helper' do
+
+ define_app do
+
+ get '/rh' do
+ content_type :json
+ { values: [
+ request_headers[params[:hk_1].to_sym],
+ request_headers[params[:hk_2].to_sym],
+ request_headers[params[:hk_3].to_sym]
+ ]
+ }
+ end
+
+ end
+
+ it 'matches snakecased symbols against case insensitive header keys' do
+ ps = {
+ hk_1: 'foo_bar',
+ hk_2: 'x_http_mozilla_ie_safari_puke',
+ hk_3: 'authorization'
+ }
+
+ hs = {
+ 'Foo-BAR' => 'abcdef',
+ 'X-HTTP-Mozilla-IE-Safari-PuKe' => 'ghijkl',
+ 'Authorization' => 'Bearer oauth_token_hi'
+ }
+
+ get '/rh', ps, hs
+ last_response_should_be_json 'values' => hs.values
end
end
end