raw 0.49.0
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/CONTRIBUTORS +106 -0
- data/doc/LICENSE +32 -0
- data/doc/coding_conventions.txt +11 -0
- data/lib/raw.rb +42 -0
- data/lib/raw/adapter.rb +113 -0
- data/lib/raw/adapter/cgi.rb +41 -0
- data/lib/raw/adapter/fastcgi.rb +48 -0
- data/lib/raw/adapter/mongrel.rb +146 -0
- data/lib/raw/adapter/script.rb +94 -0
- data/lib/raw/adapter/webrick.rb +144 -0
- data/lib/raw/adapter/webrick/vcr.rb +91 -0
- data/lib/raw/cgi.rb +323 -0
- data/lib/raw/cgi/cookie.rb +47 -0
- data/lib/raw/cgi/http.rb +62 -0
- data/lib/raw/compiler.rb +138 -0
- data/lib/raw/compiler/filter/cleanup.rb +21 -0
- data/lib/raw/compiler/filter/elements.rb +166 -0
- data/lib/raw/compiler/filter/elements/element.rb +210 -0
- data/lib/raw/compiler/filter/localization.rb +23 -0
- data/lib/raw/compiler/filter/markup.rb +32 -0
- data/lib/raw/compiler/filter/morph.rb +123 -0
- data/lib/raw/compiler/filter/morph/each.rb +34 -0
- data/lib/raw/compiler/filter/morph/for.rb +11 -0
- data/lib/raw/compiler/filter/morph/if.rb +26 -0
- data/lib/raw/compiler/filter/morph/selected_if.rb +43 -0
- data/lib/raw/compiler/filter/morph/standard.rb +55 -0
- data/lib/raw/compiler/filter/morph/times.rb +27 -0
- data/lib/raw/compiler/filter/script.rb +116 -0
- data/lib/raw/compiler/filter/squeeze.rb +16 -0
- data/lib/raw/compiler/filter/static_include.rb +74 -0
- data/lib/raw/compiler/filter/template.rb +121 -0
- data/lib/raw/compiler/reloader.rb +96 -0
- data/lib/raw/context.rb +154 -0
- data/lib/raw/context/flash.rb +157 -0
- data/lib/raw/context/global.rb +88 -0
- data/lib/raw/context/request.rb +338 -0
- data/lib/raw/context/response.rb +57 -0
- data/lib/raw/context/session.rb +198 -0
- data/lib/raw/context/session/drb.rb +11 -0
- data/lib/raw/context/session/file.rb +15 -0
- data/lib/raw/context/session/memcached.rb +13 -0
- data/lib/raw/context/session/memory.rb +12 -0
- data/lib/raw/context/session/og.rb +15 -0
- data/lib/raw/context/session/pstore.rb +13 -0
- data/lib/raw/control.rb +18 -0
- data/lib/raw/control/attribute.rb +91 -0
- data/lib/raw/control/attribute/checkbox.rb +25 -0
- data/lib/raw/control/attribute/datetime.rb +21 -0
- data/lib/raw/control/attribute/file.rb +20 -0
- data/lib/raw/control/attribute/fixnum.rb +26 -0
- data/lib/raw/control/attribute/float.rb +26 -0
- data/lib/raw/control/attribute/options.rb +38 -0
- data/lib/raw/control/attribute/password.rb +16 -0
- data/lib/raw/control/attribute/text.rb +16 -0
- data/lib/raw/control/attribute/textarea.rb +16 -0
- data/lib/raw/control/none.rb +16 -0
- data/lib/raw/control/relation.rb +59 -0
- data/lib/raw/control/relation/belongs_to.rb +0 -0
- data/lib/raw/control/relation/has_many.rb +97 -0
- data/lib/raw/control/relation/joins_many.rb +0 -0
- data/lib/raw/control/relation/many_to_many.rb +0 -0
- data/lib/raw/control/relation/refers_to.rb +29 -0
- data/lib/raw/controller.rb +37 -0
- data/lib/raw/controller/publishable.rb +160 -0
- data/lib/raw/dispatcher.rb +209 -0
- data/lib/raw/dispatcher/format.rb +108 -0
- data/lib/raw/dispatcher/format/atom.rb +31 -0
- data/lib/raw/dispatcher/format/css.rb +0 -0
- data/lib/raw/dispatcher/format/html.rb +42 -0
- data/lib/raw/dispatcher/format/json.rb +31 -0
- data/lib/raw/dispatcher/format/rss.rb +33 -0
- data/lib/raw/dispatcher/format/xoxo.rb +31 -0
- data/lib/raw/dispatcher/mounter.rb +60 -0
- data/lib/raw/dispatcher/router.rb +111 -0
- data/lib/raw/errors.rb +19 -0
- data/lib/raw/helper.rb +86 -0
- data/lib/raw/helper/benchmark.rb +23 -0
- data/lib/raw/helper/buffer.rb +60 -0
- data/lib/raw/helper/cookie.rb +32 -0
- data/lib/raw/helper/debug.rb +28 -0
- data/lib/raw/helper/default.rb +16 -0
- data/lib/raw/helper/feed.rb +451 -0
- data/lib/raw/helper/form.rb +284 -0
- data/lib/raw/helper/javascript.rb +59 -0
- data/lib/raw/helper/layout.rb +40 -0
- data/lib/raw/helper/navigation.rb +87 -0
- data/lib/raw/helper/pager.rb +305 -0
- data/lib/raw/helper/table.rb +247 -0
- data/lib/raw/helper/xhtml.rb +218 -0
- data/lib/raw/helper/xml.rb +125 -0
- data/lib/raw/mixin/magick.rb +35 -0
- data/lib/raw/mixin/sweeper.rb +71 -0
- data/lib/raw/mixin/thumbnails.rb +1 -0
- data/lib/raw/mixin/webfile.rb +165 -0
- data/lib/raw/render.rb +271 -0
- data/lib/raw/render/builder.rb +26 -0
- data/lib/raw/render/caching.rb +81 -0
- data/lib/raw/render/call.rb +43 -0
- data/lib/raw/render/send_file.rb +46 -0
- data/lib/raw/render/stream.rb +39 -0
- data/lib/raw/scaffold.rb +13 -0
- data/lib/raw/scaffold/controller.rb +25 -0
- data/lib/raw/scaffold/model.rb +157 -0
- data/lib/raw/test.rb +5 -0
- data/lib/raw/test/assertions.rb +169 -0
- data/lib/raw/test/context.rb +55 -0
- data/lib/raw/test/testcase.rb +79 -0
- data/lib/raw/util/attr.rb +128 -0
- data/lib/raw/util/encode_uri.rb +149 -0
- data/lib/raw/util/html_filter.rb +538 -0
- data/lib/raw/util/markup.rb +130 -0
- data/test/glue/tc_webfile.rb +1 -0
- data/test/nitro/CONFIG.rb +3 -0
- data/test/nitro/adapter/raw_post1.bin +9 -0
- data/test/nitro/adapter/tc_webrick.rb +16 -0
- data/test/nitro/cgi/tc_cookie.rb +14 -0
- data/test/nitro/cgi/tc_request.rb +61 -0
- data/test/nitro/compiler/tc_client_morpher.rb +47 -0
- data/test/nitro/compiler/tc_compiler.rb +25 -0
- data/test/nitro/dispatcher/tc_mounter.rb +47 -0
- data/test/nitro/helper/tc_feed.rb +135 -0
- data/test/nitro/helper/tc_navbar.rb +74 -0
- data/test/nitro/helper/tc_pager.rb +35 -0
- data/test/nitro/helper/tc_table.rb +68 -0
- data/test/nitro/helper/tc_xhtml.rb +19 -0
- data/test/nitro/tc_caching.rb +19 -0
- data/test/nitro/tc_cgi.rb +222 -0
- data/test/nitro/tc_context.rb +17 -0
- data/test/nitro/tc_controller.rb +103 -0
- data/test/nitro/tc_controller_aspect.rb +32 -0
- data/test/nitro/tc_controller_params.rb +885 -0
- data/test/nitro/tc_dispatcher.rb +109 -0
- data/test/nitro/tc_element.rb +85 -0
- data/test/nitro/tc_flash.rb +59 -0
- data/test/nitro/tc_helper.rb +47 -0
- data/test/nitro/tc_render.rb +119 -0
- data/test/nitro/tc_router.rb +61 -0
- data/test/nitro/tc_server.rb +35 -0
- data/test/nitro/tc_session.rb +66 -0
- data/test/nitro/tc_template.rb +71 -0
- data/test/nitro/util/tc_encode_url.rb +87 -0
- data/test/nitro/util/tc_markup.rb +31 -0
- data/test/public/blog/another/very_litle/index.xhtml +1 -0
- data/test/public/blog/inc1.xhtml +2 -0
- data/test/public/blog/inc2.xhtml +1 -0
- data/test/public/blog/list.xhtml +9 -0
- data/test/public/dummy_mailer/registration.xhtml +5 -0
- metadata +244 -0
@@ -0,0 +1,109 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
require 'nitro/dispatcher'
|
6
|
+
|
7
|
+
class TC_Dispatcher < Test::Unit::TestCase # :nodoc: all
|
8
|
+
include Nitro
|
9
|
+
|
10
|
+
class Link
|
11
|
+
end
|
12
|
+
|
13
|
+
class Link::Comment
|
14
|
+
end
|
15
|
+
|
16
|
+
class Link::Controller
|
17
|
+
def index
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(oid)
|
21
|
+
end
|
22
|
+
|
23
|
+
def update(oid)
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.respond_to_action_or_template?(a)
|
30
|
+
instance_methods.include?(a)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Link::Comment::Controller
|
35
|
+
def self.respond_to_action_or_template?(a)
|
36
|
+
instance_methods.include?(a)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class RootController
|
41
|
+
def index
|
42
|
+
end
|
43
|
+
|
44
|
+
def feed(category)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.respond_to_action_or_template?(a)
|
48
|
+
instance_methods.include?(a)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Template.root = File.expand_path(File.join('..', 'public'))
|
53
|
+
|
54
|
+
def setup
|
55
|
+
@d = Dispatcher.new
|
56
|
+
|
57
|
+
@d['/'] = RootController
|
58
|
+
@d['/links'] = Link::Controller
|
59
|
+
@d['/links/comments'] = Link::Comment::Controller
|
60
|
+
end
|
61
|
+
|
62
|
+
def teardown
|
63
|
+
@d = nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_initialize
|
67
|
+
dis = Dispatcher.new(RootController)
|
68
|
+
assert_equal RootController, dis['/']
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_dispatch
|
72
|
+
r = [Link::Controller, "index_action", "category=1", [], ".html"]
|
73
|
+
assert_equal r, @d.dispatch('/links/index.html?category=1')
|
74
|
+
|
75
|
+
r = [RootController, "feed_action", nil, ["world"], ""]
|
76
|
+
assert_equal r, @d.dispatch('/feed/world')
|
77
|
+
|
78
|
+
r = [RootController, "feed_action", nil, ["zuper", "duper", "world"], ".xml"]
|
79
|
+
assert_equal r, @d.dispatch('/feed/zuper/duper/world.xml')
|
80
|
+
|
81
|
+
r = [RootController, "feed_action", "oid=2;test=1", ["zuper", "duper", "world"], ".xml"]
|
82
|
+
assert_equal r, @d.dispatch('/feed/zuper/duper/world.xml?oid=2;test=1')
|
83
|
+
|
84
|
+
r = [Link::Controller, "delete_action", nil, ["1"], ""]
|
85
|
+
assert_equal r, @d.dispatch('/tralala?oid=1') rescue nil
|
86
|
+
|
87
|
+
r = [Link::Controller, "delete_action", nil, ["1"], ""]
|
88
|
+
assert_equal r, @d.dispatch('/links/1', :delete)
|
89
|
+
|
90
|
+
r = [Link::Controller, "update_action", nil, ["1"], ""]
|
91
|
+
assert_equal r, @d.dispatch('/links/1', :put)
|
92
|
+
|
93
|
+
r = [Link::Controller, "index_action", nil, [], ""]
|
94
|
+
assert_equal r, @d.dispatch('/links', :get)
|
95
|
+
|
96
|
+
r = [Link::Controller, "index_action", nil, [], ".xml"]
|
97
|
+
assert_equal r, @d.dispatch('/links/index.xml', :get)
|
98
|
+
|
99
|
+
r = [Link::Controller, "create_action", nil, [], ""]
|
100
|
+
assert_equal r, @d.dispatch('/links', :post)
|
101
|
+
|
102
|
+
r = [Link::Controller, "create_action", "great=2;stuff=1", [], ""]
|
103
|
+
assert_equal r, @d.dispatch('/links?great=2;stuff=1', :post)
|
104
|
+
|
105
|
+
r = [RootController, "index_action", nil, [], ""]
|
106
|
+
assert_equal r, @d.dispatch('/')
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
require 'glue'
|
6
|
+
require 'nitro/compiler/elements'
|
7
|
+
|
8
|
+
include Nitro
|
9
|
+
|
10
|
+
$source = %{
|
11
|
+
<html>
|
12
|
+
<?r a = 5 ?>
|
13
|
+
Here is some text
|
14
|
+
<body style="hidden" name="1">
|
15
|
+
Some more
|
16
|
+
<Box color="#f00">
|
17
|
+
Hello World
|
18
|
+
<Box color="#ff0">
|
19
|
+
<b>nice</b>
|
20
|
+
<i>stuff</i>
|
21
|
+
<Box color="#fff">
|
22
|
+
It works
|
23
|
+
</Box>
|
24
|
+
</Box>
|
25
|
+
Text
|
26
|
+
</Box>
|
27
|
+
The End
|
28
|
+
</body>
|
29
|
+
</html>
|
30
|
+
}
|
31
|
+
|
32
|
+
$source2 = %{
|
33
|
+
<x:box color="#ff0">
|
34
|
+
xhtml mode
|
35
|
+
</x:box>
|
36
|
+
}
|
37
|
+
|
38
|
+
$source3 = %{
|
39
|
+
<Page>
|
40
|
+
<Box>Hello</Box>
|
41
|
+
<Box>World</Box>
|
42
|
+
<Bar>Foo</Bar>
|
43
|
+
</Page>
|
44
|
+
}
|
45
|
+
|
46
|
+
class Page < Nitro::Element
|
47
|
+
def render
|
48
|
+
%~
|
49
|
+
<html id="2">
|
50
|
+
#{content}
|
51
|
+
#{content :bar}
|
52
|
+
</html>
|
53
|
+
~
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Box < Nitro::Element
|
58
|
+
def open
|
59
|
+
%|<div style="color: #@color">|
|
60
|
+
end
|
61
|
+
|
62
|
+
def close
|
63
|
+
"</div>"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Bar < Nitro::Element
|
68
|
+
def render
|
69
|
+
%~
|
70
|
+
This is a great #{content}.
|
71
|
+
~
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class TC_Element < Test::Unit::TestCase # :nodoc: all
|
76
|
+
def test_all
|
77
|
+
compiler_mock = Struct.new(:controller).new
|
78
|
+
|
79
|
+
res = ElementCompiler.transform($source, compiler_mock)
|
80
|
+
assert_match /div style/, res
|
81
|
+
res = ElementCompiler.transform($source2, compiler_mock)
|
82
|
+
assert_match /div style/, res
|
83
|
+
res = ElementCompiler.transform($source3, compiler_mock)
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
require 'nitro'
|
7
|
+
require 'nitro/controller'
|
8
|
+
require 'nitro/flash'
|
9
|
+
|
10
|
+
class TC_Flash < Test::Unit::TestCase # :nodoc: all
|
11
|
+
include Nitro
|
12
|
+
|
13
|
+
class MyController < Controller
|
14
|
+
attr_accessor :flag
|
15
|
+
|
16
|
+
def action1
|
17
|
+
flash[:msg] = 'Hello world!'
|
18
|
+
end
|
19
|
+
|
20
|
+
def action2
|
21
|
+
@flag = flash[:msg]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@conf = OpenStruct.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
@conf = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_all
|
34
|
+
ctx = Context.new(@conf)
|
35
|
+
ctx.headers = {}
|
36
|
+
ctx.params = {}
|
37
|
+
ctx.instance_eval '@session = {}'
|
38
|
+
c = MyController.new(ctx)
|
39
|
+
c.action1
|
40
|
+
c.action2
|
41
|
+
assert_equal 'Hello world!', c.flag
|
42
|
+
c.action2
|
43
|
+
assert_equal 'Hello world!', c.flag
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_push
|
47
|
+
f = Flashing::Flash.new
|
48
|
+
f.push :errors, 'Error 1'
|
49
|
+
f.push :errors, 'Error 2'
|
50
|
+
|
51
|
+
assert_equal 2, f[:errors].size
|
52
|
+
|
53
|
+
f.push :errors, 'Error 3'
|
54
|
+
|
55
|
+
assert_equal 3, f[:errors].size
|
56
|
+
|
57
|
+
assert_equal 'Error 3', f[:errors].pop
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
require 'nitro/helper'
|
7
|
+
|
8
|
+
class Base
|
9
|
+
include Nitro::Helpers
|
10
|
+
end
|
11
|
+
|
12
|
+
module MyHelper
|
13
|
+
def hello_world
|
14
|
+
return 5
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module AnotherHelper
|
19
|
+
def bye_world
|
20
|
+
return 0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module Funny
|
25
|
+
def funny_world
|
26
|
+
return 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class MyBase < Base
|
31
|
+
helper :my
|
32
|
+
helper AnotherHelper
|
33
|
+
end
|
34
|
+
|
35
|
+
class TC_Helper < Test::Unit::TestCase # :nodoc: all
|
36
|
+
def test_all
|
37
|
+
assert !MyBase.public_instance_methods.include?('hello_world')
|
38
|
+
assert MyBase.private_instance_methods.include?('hello_world')
|
39
|
+
assert !MyBase.public_instance_methods.include?('bye_world')
|
40
|
+
assert MyBase.private_instance_methods.include?('bye_world')
|
41
|
+
|
42
|
+
# test a bug.
|
43
|
+
MyBase.helper(Funny)
|
44
|
+
assert !MyBase.public_instance_methods.include?('funny_world')
|
45
|
+
assert MyBase.private_instance_methods.include?('funny_world')
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
require 'nitro'
|
6
|
+
require 'nitro/render'
|
7
|
+
require 'nitro/session'
|
8
|
+
require 'nitro/context'
|
9
|
+
require 'facets/more/mock'
|
10
|
+
|
11
|
+
class TestRender < Test::Unit::TestCase # :nodoc: all
|
12
|
+
include Nitro
|
13
|
+
|
14
|
+
class ContextMock < Mock
|
15
|
+
mock :response_headers, {}
|
16
|
+
mock :host_url, 'http://www.nitroproject.org'
|
17
|
+
end
|
18
|
+
|
19
|
+
class TestController < Controller
|
20
|
+
end
|
21
|
+
|
22
|
+
class CallController < Controller
|
23
|
+
def return_session
|
24
|
+
session[:CALL_STACK].inspect
|
25
|
+
end
|
26
|
+
|
27
|
+
def needs_login
|
28
|
+
call "login"
|
29
|
+
end
|
30
|
+
|
31
|
+
def login
|
32
|
+
answer()
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
@@session = Session.new
|
37
|
+
def handle_request(url, value)
|
38
|
+
conf = OpenStruct.new
|
39
|
+
disp = Nitro::Dispatcher.new('/' => CallController)
|
40
|
+
conf.dispatcher = disp
|
41
|
+
@ctx = Nitro::Context.new(conf)
|
42
|
+
@ctx.headers = { 'REQUEST_METHOD' => 'GET' }
|
43
|
+
@ctx.params = {}
|
44
|
+
@ctx.instance_variable_set '@session', @@session
|
45
|
+
|
46
|
+
if value[:in]
|
47
|
+
@ctx.in = value.delete(:in)
|
48
|
+
@ctx.headers['CONTENT_LENGTH'] = value.delete(:in_size) || @ctx.in.size
|
49
|
+
end
|
50
|
+
|
51
|
+
if value[:method]
|
52
|
+
@ctx.headers['REQUEST_METHOD'] = value[:method].to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
if value['CONTENT_TYPE']
|
56
|
+
@ctx.headers['CONTENT_TYPE'] = value.delete('CONTENT_TYPE')
|
57
|
+
end
|
58
|
+
|
59
|
+
@ctx.headers['REQUEST_URI'] = url
|
60
|
+
|
61
|
+
if (!@ctx.query_string || @ctx.query_string.empty?) and @ctx.uri =~ /\?/
|
62
|
+
@ctx.headers['QUERY_STRING'] = @ctx.uri.split('?').last
|
63
|
+
end
|
64
|
+
|
65
|
+
Nitro::Cgi.parse_params(@ctx)
|
66
|
+
Nitro::Cgi.parse_cookies(@ctx)
|
67
|
+
|
68
|
+
@ctx.render url
|
69
|
+
|
70
|
+
#retrieve the stuff from @out again as a hash
|
71
|
+
result = @ctx.out
|
72
|
+
|
73
|
+
return result
|
74
|
+
end
|
75
|
+
|
76
|
+
def setup
|
77
|
+
ctx = ContextMock.new
|
78
|
+
@controller = TestController.new(ctx)
|
79
|
+
end
|
80
|
+
|
81
|
+
def teardown
|
82
|
+
@controller = nil
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_redirect
|
86
|
+
# relative url, the controller base_url is prepended (uh, really?)
|
87
|
+
redirect 'hello'
|
88
|
+
assert_equal 'http://www.nitroproject.org/hello', @controller.context.response_headers['location']
|
89
|
+
|
90
|
+
# absolute url, use as is.
|
91
|
+
redirect '/main'
|
92
|
+
assert_equal 'http://www.nitroproject.org/main', @controller.context.response_headers['location']
|
93
|
+
|
94
|
+
# http://, use as is.
|
95
|
+
redirect 'http://www.gmosx.com/info'
|
96
|
+
assert_equal 'http://www.gmosx.com/info', @controller.context.response_headers['location']
|
97
|
+
|
98
|
+
redirect 'edit/Home'
|
99
|
+
assert_equal 'http://www.nitroproject.org/edit/Home', @controller.context.response_headers['location']
|
100
|
+
|
101
|
+
redirect '/edit/Home'
|
102
|
+
assert_equal 'http://www.nitroproject.org/edit/Home', @controller.context.response_headers['location']
|
103
|
+
end
|
104
|
+
|
105
|
+
def redirect(*args)
|
106
|
+
begin
|
107
|
+
@controller.send :redirect, *args
|
108
|
+
rescue Nitro::RenderExit
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_call
|
113
|
+
handle_request('/needs_login', {})
|
114
|
+
assert_equal ['/needs_login'], eval(handle_request('/return_session', {}))
|
115
|
+
handle_request('/login', {})
|
116
|
+
assert_equal [], eval(handle_request('/return_session', {}))
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'CONFIG.rb')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
require 'nitro/dispatcher/router'
|
7
|
+
|
8
|
+
class IdController; end
|
9
|
+
class AdminController; end
|
10
|
+
|
11
|
+
class AbstractRouter
|
12
|
+
include Nitro::Router
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
init_routes()
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class TC_Router < Test::Unit::TestCase # :nodoc: all
|
20
|
+
include Nitro
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@r = AbstractRouter.new
|
24
|
+
|
25
|
+
@r.add_rule(:match => %r{rewritten/url/(.*)}, :controller => IdController, :action => :register, :param => :name)
|
26
|
+
@r.add_rule(:match => %r{another/zelo/(.*)/(.*)}, :controller => AdminController, :action => :kick, :params => [:name, :age])
|
27
|
+
@r.add_rule(:match => %r{cool/(.*)_(.*).html}, :controller => AdminController, :action => :long, :params => [:name, :age])
|
28
|
+
end
|
29
|
+
|
30
|
+
def teardown
|
31
|
+
@r = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_decode
|
35
|
+
c, a, params = @r.decode_route('rewritten/url/gmosx')
|
36
|
+
assert_equal IdController, c
|
37
|
+
assert_equal :register, a
|
38
|
+
assert_equal 'gmosx', params['name']
|
39
|
+
|
40
|
+
c, a, params = @r.decode_route('another/zelo/gmosx/32')
|
41
|
+
assert_equal AdminController, c
|
42
|
+
assert_equal :kick, a
|
43
|
+
assert_equal 'gmosx', params['name']
|
44
|
+
assert_equal '32', params['age']
|
45
|
+
|
46
|
+
c, a, params = @r.decode_route('cool/gmosx_32.html')
|
47
|
+
assert_equal AdminController, c
|
48
|
+
assert_equal :long, a
|
49
|
+
assert_equal 'gmosx', params['name']
|
50
|
+
assert_equal '32', params['age']
|
51
|
+
|
52
|
+
assert_equal false, @r.decode_route('this/doesnt/decode')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_encode
|
56
|
+
assert_equal 'rewritten/url/gmosx', @r.encode_route(IdController, :register, :name, 'gmosx')
|
57
|
+
assert_equal 'cool/gmosx_32.html', @r.encode_route(AdminController, :long, :name, 'gmosx', :age, 32)
|
58
|
+
assert_equal false, @r.encode_route(AdminController, :invalid, :gender, 'male')
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|