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 102 103 104 105 106 107 108 109 110
|
require 'test_helper'
require 'camping'
Camping.goes :Simple
module Simple::Controllers
class Index
def get
"Hello World!"
end
def post
"Hello Post!"
end
def custom
"Hello Custom!"
end
end
class PostN
def get(id)
"Post ##{id}"
end
end
class MultipleComplexX
def get(str)
"Complex: #{str}"
end
end
class DateNNN
def get(year, month, day)
[year, month, day] * "-"
end
end
class Regexp < R '/ohmy/([a-f]+)'
def get(value)
value
end
end
class Optional < R '/optional', '/optional/([^/]+)'
def get(value = "default")
"Optional: #{value}"
end
end
class Weird
def get
redirect MultipleComplexX, 'hello%#/world'
end
end
end
class Simple::Test < TestCase
def test_index
get '/'
assert_body "Hello World!"
assert_equal "text/html", last_response.headers['content-type']
post '/'
assert_body "Hello Post!"
end
def test_post
get '/post/1'
assert_body "Post #1"
get '/post/2'
assert_body "Post #2"
get '/post/2-oh-no'
assert_status 404
end
def test_complex
get '/multiple/complex/Hello'
assert_body "Complex: Hello"
end
def test_date
get '/date/2010/04/01'
assert_body "2010-04-01"
end
def test_regexp
get '/ohmy/cafebabe'
assert_body "cafebabe"
get '/ohmy/CAFEBABE'
assert_status 404
end
def test_optional
get '/optional'
assert_body "Optional: default"
get '/optional/override'
assert_body "Optional: override"
end
def test_weird
get '/weird'
follow_redirect!
assert_body 'Complex: hello%#/world'
end
end
|