Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 73 lines (62 sloc) 2.519 kB
e001d62 @rkh adjust require lines for test helper, so it also works properly on 1.9.2
rkh authored
1 require File.expand_path('../helper', __FILE__)
a05d1fa @rkh require stringio in request_test, fixes GH #51
rkh authored
2 require 'stringio'
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
3
ff0d068 @sr Use contest instead of test/spec/mini
sr authored
4 class RequestTest < Test::Unit::TestCase
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
5 it 'responds to #user_agent' do
6 request = Sinatra::Request.new({'HTTP_USER_AGENT' => 'Test'})
72a6e01 @rtomayko use Test::Unit style assertions in Sinatra specs
rtomayko authored
7 assert request.respond_to?(:user_agent)
8 assert_equal 'Test', request.user_agent
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
9 end
4a75d9e @rtomayko Fix Request#params on PUT requests [#72]
rtomayko authored
10
11 it 'parses POST params when Content-Type is form-dataish' do
12 request = Sinatra::Request.new(
13 'REQUEST_METHOD' => 'PUT',
14 'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
15 'rack.input' => StringIO.new('foo=bar')
16 )
17 assert_equal 'bar', request.params['foo']
18 end
0f030b6 @adamwiggins request.secure? to check for ssl encrypted connection
adamwiggins authored
19
20 it 'is secure when the url scheme is https' do
21 request = Sinatra::Request.new('rack.url_scheme' => 'https')
22 assert request.secure?
23 end
24
25 it 'is not secure when the url scheme is http' do
26 request = Sinatra::Request.new('rack.url_scheme' => 'http')
27 assert !request.secure?
28 end
29
30 it 'respects X-Forwarded-Proto header for proxied SSL' do
31 request = Sinatra::Request.new('HTTP_X_FORWARDED_PROTO' => 'https')
32 assert request.secure?
33 end
38ad411 @rkh spec checking wether Marshal.dump(params) is possible
rkh authored
34
35 it 'is possible to marshal params' do
36 request = Sinatra::Request.new(
37 'REQUEST_METHOD' => 'PUT',
38 'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
39 'rack.input' => StringIO.new('foo=bar')
40 )
1d9034f @rkh use new! rather than new for tests testing instance method
rkh authored
41 params = Sinatra::Base.new!.send(:indifferent_hash).replace(request.params)
38ad411 @rkh spec checking wether Marshal.dump(params) is possible
rkh authored
42 dumped = Marshal.dump(request.params)
43 assert_equal 'bar', Marshal.load(dumped)['foo']
44 end
b7c615c @pvande Exposing Accept header parameters.
pvande authored
45
46 it "exposes the preferred type's parameters" do
47 request = Sinatra::Request.new(
48 'HTTP_ACCEPT' => 'image/jpeg; compress=0.25'
49 )
50 assert_equal({ 'compress' => '0.25' }, request.preferred_type.params)
51 end
52
a045a3f @rkh make AcceptEntry behave like string
rkh authored
53 it "makes accept types behave like strings" do
54 request = Sinatra::Request.new('HTTP_ACCEPT' => 'image/jpeg; compress=0.25')
55 assert_equal 'image/jpeg', request.preferred_type.to_s
56 assert_equal 'image/jpeg', request.preferred_type.to_str
57 assert_equal 'image', request.preferred_type.split('/').first
58
59 String.instance_methods.each do |method|
84a0da3 @rkh fix test for Ruby 2.0
rkh authored
60 next unless "".respond_to? method
61 assert request.preferred_type.respond_to?(method), "responds to #{method}"
a045a3f @rkh make AcceptEntry behave like string
rkh authored
62 end
63 end
64
b7c615c @pvande Exposing Accept header parameters.
pvande authored
65 it "properly decodes MIME type parameters" do
66 request = Sinatra::Request.new(
67 'HTTP_ACCEPT' => 'image/jpeg;unquoted=0.25;quoted="0.25";chartest="\";,\x"'
68 )
69 expected = { 'unquoted' => '0.25', 'quoted' => '0.25', 'chartest' => '";,x' }
70 assert_equal(expected, request.preferred_type.params)
71 end
a734cf3 @rtomayko I knew I shoulda taken that left turn at Hoboken
rtomayko authored
72 end
Something went wrong with that request. Please try again.