nitro 0.8.0 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. data/AUTHORS +3 -4
  2. data/ChangeLog +418 -0
  3. data/LICENSE +1 -1
  4. data/README +157 -89
  5. data/RELEASES +50 -0
  6. data/Rakefile +5 -7
  7. data/benchmark/nitro/bench.rb +5 -0
  8. data/benchmark/nitro/simple-webrick-n-200.txt +44 -0
  9. data/benchmark/nitro/static-webrick-n-200.txt +43 -0
  10. data/benchmark/nitro/tiny-lhttpd-n-200-c-5.txt +43 -0
  11. data/benchmark/nitro/tiny-webrick-n-200-c-5.txt +44 -0
  12. data/benchmark/nitro/tiny-webrick-n-200.txt +44 -0
  13. data/benchmark/nitro/tiny2-webrick-n-200.txt +44 -0
  14. data/{lib/nitro/server/cluster.rb → bin/cluster} +26 -30
  15. data/bin/proto/README +2 -2
  16. data/bin/proto/{apache.conf → conf/apache.conf} +0 -0
  17. data/bin/proto/conf/app.conf.rb +22 -0
  18. data/bin/proto/conf/lhttpd.conf +236 -0
  19. data/bin/proto/ctl +4 -0
  20. data/bin/proto/lib/README +5 -0
  21. data/bin/proto/log/README +3 -0
  22. data/bin/proto/root/fcgi.rb +6 -0
  23. data/bin/proto/root/index.xhtml +65 -7
  24. data/bin/proto/root/m/nitro.png +0 -0
  25. data/examples/blog/README +7 -5
  26. data/examples/blog/{apache.conf → conf/apache.conf} +0 -0
  27. data/examples/blog/conf/app.conf.rb +56 -0
  28. data/examples/blog/conf/lhttpd.conf +236 -0
  29. data/examples/blog/ctl +4 -0
  30. data/examples/blog/lib/blog.rb +11 -136
  31. data/examples/blog/lib/blog/controller.rb +99 -0
  32. data/examples/blog/lib/blog/model.rb +39 -0
  33. data/examples/blog/log/README +3 -0
  34. data/examples/blog/root/comments.xhtml +2 -2
  35. data/examples/blog/root/fcgi.rb +6 -0
  36. data/examples/blog/root/index.xhtml +4 -5
  37. data/examples/blog/root/login.xhtml +2 -2
  38. data/examples/blog/root/style.xsl +9 -9
  39. data/examples/blog/root/view_entry.xhtml +2 -2
  40. data/examples/flash/conf/app.conf.rb +23 -0
  41. data/examples/flash/ctl +4 -0
  42. data/examples/flash/log/README +3 -0
  43. data/examples/flash/root/index.xhtml +0 -9
  44. data/examples/flash/root/show_inline_text.xhtml +10 -5
  45. data/examples/no_xsl_blog/README +12 -0
  46. data/examples/no_xsl_blog/conf/apache.conf +0 -0
  47. data/examples/no_xsl_blog/conf/app.conf.rb +57 -0
  48. data/examples/no_xsl_blog/conf/lhttpd.conf +236 -0
  49. data/examples/no_xsl_blog/ctl +4 -0
  50. data/examples/no_xsl_blog/lib/blog.rb +20 -0
  51. data/examples/no_xsl_blog/lib/blog/controller.rb +102 -0
  52. data/examples/no_xsl_blog/lib/blog/model.rb +39 -0
  53. data/examples/no_xsl_blog/lib/blog/template.rb +134 -0
  54. data/examples/no_xsl_blog/log/README +3 -0
  55. data/examples/no_xsl_blog/root/comments.xhtml +41 -0
  56. data/examples/no_xsl_blog/root/entry_form.xhtml +22 -0
  57. data/examples/no_xsl_blog/root/fcgi.rb +6 -0
  58. data/examples/no_xsl_blog/root/index.xhtml +39 -0
  59. data/examples/no_xsl_blog/root/login.xhtml +21 -0
  60. data/examples/no_xsl_blog/root/m/bubbles.gif +0 -0
  61. data/examples/no_xsl_blog/root/m/comments_curve.gif +0 -0
  62. data/examples/no_xsl_blog/root/m/down.gif +0 -0
  63. data/examples/no_xsl_blog/root/m/footer_bg.gif +0 -0
  64. data/examples/no_xsl_blog/root/m/garrow.gif +0 -0
  65. data/examples/no_xsl_blog/root/m/gbull.gif +0 -0
  66. data/examples/no_xsl_blog/root/m/grbull.gif +0 -0
  67. data/examples/no_xsl_blog/root/m/h1_bg.gif +0 -0
  68. data/examples/no_xsl_blog/root/m/header_bg.gif +0 -0
  69. data/examples/no_xsl_blog/root/m/nitro.gif +0 -0
  70. data/examples/no_xsl_blog/root/m/obull.gif +0 -0
  71. data/examples/no_xsl_blog/root/m/page_bg.gif +0 -0
  72. data/examples/no_xsl_blog/root/m/rss.gif +0 -0
  73. data/examples/no_xsl_blog/root/m/side_title_bg.gif +0 -0
  74. data/examples/no_xsl_blog/root/m/sidebar_bg.gif +0 -0
  75. data/examples/no_xsl_blog/root/recent_posts.xhtml +14 -0
  76. data/examples/no_xsl_blog/root/style.css +301 -0
  77. data/examples/no_xsl_blog/root/view_entry.xhtml +25 -0
  78. data/examples/no_xsl_blog/root/view_entry.xml +12 -0
  79. data/examples/og/run.rb +2 -2
  80. data/examples/tiny/README +2 -2
  81. data/examples/tiny/conf/apache.conf +5 -0
  82. data/examples/tiny/conf/app.conf.rb +21 -0
  83. data/examples/tiny/conf/lhttpd.conf +236 -0
  84. data/examples/tiny/ctl +4 -0
  85. data/examples/tiny/log/README +3 -0
  86. data/examples/tiny/root/fcgi.rb +6 -0
  87. data/examples/tiny/root/index.xhtml +7 -4
  88. data/examples/tiny/root/nitro.png +0 -0
  89. data/lib/glue.rb +13 -9
  90. data/lib/glue/array.rb +1 -1
  91. data/lib/glue/cache.rb +1 -1
  92. data/lib/glue/flexob.rb +12 -0
  93. data/lib/glue/hash.rb +1 -1
  94. data/lib/glue/inflector.rb +2 -2
  95. data/lib/glue/logger.rb +4 -8
  96. data/lib/glue/misc.rb +14 -0
  97. data/lib/glue/number.rb +1 -1
  98. data/lib/glue/object.rb +26 -0
  99. data/lib/glue/pool.rb +1 -1
  100. data/lib/glue/property.rb +84 -91
  101. data/lib/glue/string.rb +1 -1
  102. data/lib/glue/time.rb +1 -1
  103. data/lib/glue/validation.rb +1 -1
  104. data/lib/nitro.rb +18 -6
  105. data/lib/nitro/adaptors/cgi.rb +291 -0
  106. data/lib/nitro/adaptors/fastcgi.rb +42 -0
  107. data/lib/nitro/adaptors/runner.rb +123 -0
  108. data/lib/nitro/adaptors/webrick.rb +110 -0
  109. data/lib/nitro/buffering.rb +43 -0
  110. data/lib/nitro/builders/form.rb +1 -1
  111. data/lib/nitro/builders/rss.rb +1 -1
  112. data/{bin → lib/nitro}/cluster.rb +26 -30
  113. data/lib/nitro/context.rb +82 -0
  114. data/lib/nitro/controller.rb +50 -0
  115. data/lib/nitro/cookie.rb +46 -0
  116. data/lib/nitro/dispatcher.rb +105 -0
  117. data/lib/nitro/filters.rb +9 -10
  118. data/lib/nitro/localization.rb +42 -0
  119. data/lib/nitro/mail.rb +11 -14
  120. data/lib/nitro/render.rb +275 -0
  121. data/lib/nitro/request.rb +128 -0
  122. data/lib/nitro/response.rb +38 -0
  123. data/lib/nitro/scaffold.rb +11 -11
  124. data/lib/nitro/session.rb +84 -0
  125. data/lib/nitro/{server/shaders.rb → shaders.rb} +56 -36
  126. data/lib/nitro/ui/pager.rb +23 -26
  127. data/lib/nitro/{sitemap.rb → ui/sitemap.rb} +4 -12
  128. data/lib/nitro/uri.rb +1 -1
  129. data/lib/nitro/version.rb +10 -8
  130. data/lib/og.rb +66 -65
  131. data/lib/og/backend.rb +1 -1
  132. data/lib/og/backends/mysql.rb +48 -52
  133. data/lib/og/backends/psql.rb +34 -37
  134. data/lib/og/connection.rb +15 -15
  135. data/lib/og/enchant.rb +16 -9
  136. data/lib/og/meta.rb +127 -54
  137. data/lib/og/mock.rb +18 -18
  138. data/lib/og/version.rb +6 -4
  139. data/lib/parts/content.rb +4 -8
  140. data/test/glue/tc_logger.rb +3 -0
  141. data/test/glue/tc_property.rb +19 -3
  142. data/test/nitro/adaptors/tc_cgi.rb +63 -0
  143. data/test/nitro/adaptors/tc_webrick.rb +15 -0
  144. data/test/nitro/builders/tc_xml.rb +2 -2
  145. data/test/nitro/tc_context.rb +13 -0
  146. data/test/nitro/tc_controller.rb +47 -0
  147. data/test/nitro/tc_dispatcher.rb +64 -0
  148. data/test/nitro/tc_session.rb +20 -0
  149. data/test/nitro/{tc_sitemap.rb → ui/tc_sitemap.rb} +1 -1
  150. data/test/root/blog/list.xhtml +6 -0
  151. data/test/tc_og.rb +41 -4
  152. metadata +115 -59
  153. data/bin/proto/app.rb +0 -20
  154. data/bin/proto/config.rb +0 -77
  155. data/examples/blog/app.rb +0 -21
  156. data/examples/blog/config.rb +0 -95
  157. data/examples/blog/env.rb +0 -22
  158. data/examples/flash/README +0 -34
  159. data/examples/flash/app.rb +0 -20
  160. data/examples/flash/config.rb +0 -38
  161. data/examples/flash/lib/flash.rb +0 -40
  162. data/examples/flash/tmp.swf +0 -0
  163. data/examples/tiny/app.rb +0 -19
  164. data/examples/tiny/config.rb +0 -29
  165. data/examples/tiny/root/nitro-small.png +0 -0
  166. data/lib/nitro/application.rb +0 -217
  167. data/lib/nitro/config.rb +0 -128
  168. data/lib/nitro/events.rb +0 -122
  169. data/lib/nitro/html.rb +0 -151
  170. data/lib/nitro/http.rb +0 -102
  171. data/lib/nitro/l10n.rb +0 -30
  172. data/lib/nitro/server.rb +0 -59
  173. data/lib/nitro/server/appserver.rb +0 -67
  174. data/lib/nitro/server/cookie.rb +0 -87
  175. data/lib/nitro/server/dispatcher.rb +0 -62
  176. data/lib/nitro/server/filters.rb +0 -75
  177. data/lib/nitro/server/filters/autologin.rb +0 -51
  178. data/lib/nitro/server/fragment.rb +0 -70
  179. data/lib/nitro/server/handlers.rb +0 -127
  180. data/lib/nitro/server/render.rb +0 -426
  181. data/lib/nitro/server/request.rb +0 -658
  182. data/lib/nitro/server/requestpart.rb +0 -54
  183. data/lib/nitro/server/script.rb +0 -387
  184. data/lib/nitro/server/server.rb +0 -57
  185. data/lib/nitro/server/session.rb +0 -220
  186. data/lib/nitro/server/user.rb +0 -46
  187. data/lib/nitro/server/webrick.rb +0 -180
  188. data/lib/nitro/service.rb +0 -26
  189. data/lib/xsl/ui.xsl +0 -51
  190. data/lib/xsl/xforms.xsl +0 -28
  191. data/test/nitro/server/tc_cookie.rb +0 -34
  192. data/test/nitro/server/tc_filters.rb +0 -38
  193. data/test/nitro/server/tc_request.rb +0 -70
  194. data/test/nitro/server/tc_requestpart.rb +0 -28
  195. data/test/nitro/server/tc_session.rb +0 -34
  196. data/test/nitro/tc_events.rb +0 -44
  197. data/test/nitro/tc_html.rb +0 -79
  198. data/test/nitro/tc_http.rb +0 -18
@@ -1,8 +1,6 @@
1
- # code:
2
1
  # * George Moschovitis <gm@navel.gr>
3
2
  # * Thomas Quas <tquas@yahoo.com>
4
- #
5
- # (c) 2004 Navel, all rights reserved.
3
+ # (c) 2004-2005 Navel, all rights reserved.
6
4
  # $Id$
7
5
 
8
6
  require 'og'
@@ -12,15 +10,12 @@ require_gem 'flexmock'
12
10
 
13
11
  class Og
14
12
 
15
- # = MockDatabase
16
- #
17
13
  # A utility object to Mock a Database in test units.
18
14
  # Extends the standard FlexMock object.
19
- #
20
15
  #--
21
16
  # TODO: Factor out common functionality with Database
22
17
  # to avoid code duplication.
23
- #++
18
+
24
19
  class MockDatabase < ::FlexMock
25
20
  include Og::Enchant
26
21
 
@@ -40,16 +35,19 @@ class MockDatabase < ::FlexMock
40
35
  end
41
36
 
42
37
  # hash of configuration options.
38
+
43
39
  attr_accessor :config
44
40
 
45
41
  # Pool of connections to the backend.
42
+
46
43
  attr_accessor :connection_pool
47
44
 
48
45
  # Managed classes.
46
+
49
47
  attr_accessor :managed_classes
50
48
 
51
49
  # Initialize the database interface.
52
- #
50
+
53
51
  def initialize
54
52
  # Initialize FlexMock
55
53
  super
@@ -61,6 +59,7 @@ class MockDatabase < ::FlexMock
61
59
  if Og.auto_manage_classes
62
60
  # automatically manage classes with properties and metadata.
63
61
  # gmosx: Any idea how to optimize this?
62
+
64
63
  classes_to_manage = []
65
64
  ObjectSpace.each_object(Class) do |c|
66
65
  if c.respond_to?(:__props) and c.__props
@@ -73,31 +72,32 @@ class MockDatabase < ::FlexMock
73
72
  end
74
73
 
75
74
  # use the newly created database.
75
+
76
76
  Og.use(self)
77
77
  end
78
78
 
79
79
  # Shutdown the database interface.
80
- #
80
+
81
81
  def shutdown
82
82
  end
83
83
  alias_method :close, :shutdown
84
84
 
85
85
  # Get a connection from the pool to access the database.
86
86
  # Stores the connection in a thread-local variable.
87
- #
87
+
88
88
  def get_connection
89
89
  # nop
90
90
  end
91
91
  alias_method :connection, :get_connection
92
92
 
93
93
  # Restore an unused connection to the pool.
94
- #
94
+
95
95
  def put_connection
96
96
  # nop
97
97
  end
98
98
 
99
99
  # Register a standard Ruby class as managed.
100
- #
100
+
101
101
  def manage(klass)
102
102
  return if managed?(klass) or klass.ancestors.include?(Og::Unmanageable)
103
103
 
@@ -111,7 +111,7 @@ class MockDatabase < ::FlexMock
111
111
  end
112
112
 
113
113
  # Helper method to set multiple managed classes.
114
- #
114
+
115
115
  def manage_classes(*klasses)
116
116
  for klass in klasses
117
117
  manage(klass)
@@ -119,19 +119,19 @@ class MockDatabase < ::FlexMock
119
119
  end
120
120
 
121
121
  # Stop managing a Ruby class
122
- #
122
+
123
123
  def unmanage(klass)
124
124
  @managed_classes.delete(klass)
125
125
  end
126
126
 
127
127
  # Is this class managed?
128
- #
128
+
129
129
  def managed?(klass)
130
130
  return @managed_classes.include?(klass)
131
131
  end
132
132
 
133
133
  # Add standard og functionality to the class
134
- #
134
+
135
135
  def convert(klass)
136
136
  klass.class_eval %{
137
137
  DBTABLE = "#{Og::Backend.table(klass)}"
@@ -144,7 +144,7 @@ class MockDatabase < ::FlexMock
144
144
  end
145
145
 
146
146
  # Automatically wrap connection methods.
147
- #
147
+
148
148
  def self.wrap_method(method, args)
149
149
  args = args.split(/,/)
150
150
  class_eval %{
@@ -163,4 +163,4 @@ class MockDatabase < ::FlexMock
163
163
  end
164
164
  end
165
165
 
166
- end # namespace
166
+ end
@@ -1,9 +1,11 @@
1
1
  #--
2
2
  # George Moschovitis <gm@navel.gr>
3
3
  # (c) 2004-2005 Navel, all rights reserved.
4
- # $Id: version.rb 198 2004-12-22 11:26:59Z gmosx $
4
+ # $Id: version.rb 248 2005-01-31 13:38:34Z gmosx $
5
5
  #++
6
6
 
7
- # The version of Og.
8
-
9
- $og_version = '0.8.0'
7
+ class Og
8
+ # The version of Og.
9
+
10
+ Version = '0.9.0'
11
+ end
@@ -1,21 +1,17 @@
1
- # = Content
2
- #
3
- # Content management foundation.
4
- #
5
- # George Moschovitis <gm@navel.gr>
1
+ # * George Moschovitis <gm@navel.gr>
6
2
  # (c) 2004 Navel, all rights reserved.
7
3
  # $Id$
8
4
 
9
5
  require 'nitro/markup'
10
6
 
11
- module N
7
+ module N
12
8
 
13
9
  # = BaseContent
14
10
  #
15
11
  # The foundamental Content Unit.
16
12
  #
17
13
  module BaseContent
18
- include N::Markup
14
+ include Markup
19
15
 
20
16
  prop_accessor :title, String
21
17
  prop_accessor :body, String, :markup => true, :ui => :textarea
@@ -57,7 +53,7 @@ end
57
53
  # = Category
58
54
 
59
55
  class Category
60
- include N::BaseContent
56
+ include BaseContent
61
57
  end
62
58
 
63
59
  # = ACL
@@ -31,6 +31,9 @@ class TC_Logger < Test::Unit::TestCase # :nodoc: all
31
31
  Logger.get.level = Logger::INFO
32
32
  Logger.debug 'world'
33
33
  assert_equal("DEBUG: hello\n", @io.string)
34
+
35
+ # bug:
36
+ Logger.error 'Have forgotten that :)'
34
37
  end
35
38
 
36
39
  end
@@ -1,8 +1,16 @@
1
- require "test/unit"
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
2
 
3
- require "glue/logger"; $log = Logger.new(STDERR) unless $log
3
+ require 'test/unit'
4
4
 
5
- require "glue/property"
5
+ require 'og'
6
+ require 'glue/logger'
7
+ require 'glue/property'
8
+
9
+ def VarChar(size)
10
+ return String, :sql => "VARCHAR(#{ size })"
11
+ end
12
+ NotNull = {:sql => "NOT NULL"}.freeze
13
+ Null = {:sql => "NULL"}.freeze
6
14
 
7
15
  module Test # :nodoc: all
8
16
 
@@ -18,6 +26,9 @@ class Msg
18
26
 
19
27
  # a marshaled property
20
28
  prop_accessor Array, :options
29
+
30
+ # property with macro arguments!
31
+ prop_accessor :address, VarChar(30), NotNull
21
32
 
22
33
  def initialize
23
34
  @create_time = Time.now
@@ -65,6 +76,11 @@ class TC_N_Properties < Test::Unit::TestCase
65
76
  @msg1.__force_count(2.4)
66
77
  assert_equal(Fixnum, @msg1.count.class)
67
78
  end
79
+
80
+ def test_macro_params
81
+ sql = Msg.__props.find { |p| :address == p.symbol }.meta[:sql]
82
+ assert_equal 'VARCHAR(30) NOT NULL', sql
83
+ end
68
84
 
69
85
  end
70
86
 
@@ -0,0 +1,63 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
+
3
+ require 'ostruct'
4
+ require 'test/unit'
5
+
6
+ require 'nitro/cookie'
7
+ require 'nitro/adaptors/cgi'
8
+
9
+ class TC_AdaptorsCgi < Test::Unit::TestCase # :nodoc: all
10
+ include N
11
+
12
+ def test_parse_query_parameters
13
+ qs = 'name=tml;id=12354'
14
+ params = CgiUtils.parse_query_string(qs)
15
+ assert_equal 2, params.size
16
+ assert_equal 'tml', params['name']
17
+
18
+ qs = ''
19
+ params = CgiUtils.parse_query_string(qs)
20
+ assert_equal 0, params.size
21
+
22
+ qs = nil
23
+ params = CgiUtils.parse_query_string(qs)
24
+ assert_equal 0, params.size
25
+
26
+ qs = 'name=tml;arr[]=1;arr[]=2;arr[]=3'
27
+ params = CgiUtils.parse_query_string(qs)
28
+ assert_equal 2, params.size
29
+ arr = params['arr']
30
+ assert_equal Array, arr.class
31
+ assert_equal 3, arr.size
32
+ end
33
+
34
+ def test_parse_cookies
35
+ context = OpenStruct.new
36
+ context.env = {}
37
+ context.env['HTTP_COOKIE'] = 'nsid=123; nauth=gmosx:passwd'
38
+ CgiUtils.parse_cookies(context)
39
+ assert_equal 2, context.cookies.size
40
+ assert_equal '123', context.cookies['nsid']
41
+
42
+ context.env = {}
43
+ context.env['HTTP_COOKIE'] = 'nsid=123; nsid=23123'
44
+ cookies = CgiUtils.parse_cookies(context)
45
+ assert_equal 1, context.cookies.size
46
+ assert_equal "123" + "\0" + "23123", context.cookies['nsid']
47
+ end
48
+
49
+ def test_response_headers
50
+ ctx = OpenStruct.new
51
+ ctx.status = 200
52
+ ctx.response_cookies = {
53
+ 'nsid' => Cookie.new('nsid', '1233'),
54
+ 'nauth' => Cookie.new('nauth', 'gmosx')
55
+ }
56
+ ctx.response_headers = {
57
+ 'Content-Type' => 'text/html'
58
+ }
59
+
60
+ res = "HTTP/1.1 200 OK \r\nContent-Type: text/html\r\nSet-Cookie: nauthnauth=gmosx\r\nSet-Cookie: nsidnsid=1233\r\n\r\n"
61
+ assert_equal res, CgiUtils.response_headers(ctx)
62
+ end
63
+ end
@@ -0,0 +1,15 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
2
+
3
+ require 'test/unit'
4
+ require 'ostruct'
5
+
6
+ require 'nitro/adaptors/webrick'
7
+
8
+ class TC_Webrick < Test::Unit::TestCase # :nodoc: all
9
+ include N
10
+
11
+ def test_adaptor
12
+ # w = WebrickAdaptor.new()
13
+ end
14
+
15
+ end
@@ -21,8 +21,8 @@ class TC_BuildersXml < Test::Unit::TestCase # :nodoc: all
21
21
  assert_equal '<b>This is bold</b>', x
22
22
 
23
23
  x = N::XmlString.new
24
- x.a('Navel', :href => 'http://www.navel.gr', :target => '_blank')
25
- assert_equal '<a target="_blank" href="http://www.navel.gr">Navel</a>', x
24
+ x.a('Navel', :href => 'http://www.navel.gr')
25
+ assert_equal '<a href="http://www.navel.gr">Navel</a>', x
26
26
 
27
27
 
28
28
  x = N::XmlString.new
@@ -0,0 +1,13 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
+
3
+ require 'test/unit'
4
+ require 'ostruct'
5
+
6
+ require 'nitro/context'
7
+
8
+ class TC_Context < Test::Unit::TestCase # :nodoc: all
9
+ include N
10
+
11
+ def test_context
12
+ end
13
+ end
@@ -0,0 +1,47 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
+
3
+ require 'test/unit'
4
+ require 'ostruct'
5
+
6
+ require 'nitro/context'
7
+ require 'nitro/dispatcher'
8
+ require 'nitro/controller'
9
+
10
+ class TC_Controller < Test::Unit::TestCase # :nodoc: all
11
+ include N
12
+
13
+ class BlogController < Controller
14
+ attr_accessor :aflag, :tflag
15
+
16
+ def list
17
+ @aflag = true
18
+ end
19
+ end
20
+
21
+ def setup
22
+ @disp = Dispatcher.new({
23
+ 'blog' => BlogController,
24
+ })
25
+ @disp.root = File.join(File.dirname(__FILE__), '..', 'root')
26
+ @conf = OpenStruct.new
27
+ @conf.dispatcher = @disp
28
+ end
29
+
30
+ def test_render
31
+ ctx = Context.new(@conf)
32
+ ctx.headers = {}
33
+ puts '=', ctx.dispatcher.root
34
+ klass, action, base = ctx.dispatcher.dispatch('/blog/list')
35
+ c = klass.new(ctx, base)
36
+ begin
37
+ c.send(action)
38
+ rescue RenderExit
39
+ # drink
40
+ end
41
+ assert_equal true, c.aflag
42
+
43
+ # the template is compiled
44
+ assert_equal true, c.tflag
45
+ end
46
+
47
+ end
@@ -0,0 +1,64 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
+
3
+ require 'test/unit'
4
+ require 'nitro/dispatcher'
5
+
6
+ class TC_Dispatcher < Test::Unit::TestCase # :nodoc: all
7
+
8
+ class MainController
9
+ end
10
+
11
+ class BlogController
12
+ end
13
+
14
+ def setup
15
+ @d = N::Dispatcher.new({
16
+ :index => MainController,
17
+ 'blog' => BlogController
18
+ })
19
+
20
+ @dxml = N::Dispatcher.new({
21
+ :index => MainController,
22
+ 'blog' => BlogController
23
+ })
24
+ @dxml.add_api('xml', 'xml')
25
+ end
26
+
27
+ def teardown
28
+ @d = @dxml = nil
29
+ end
30
+
31
+ def test_dispatch
32
+ klass, action = @d.dispatch('/blog/list')
33
+ assert_equal BlogController, klass
34
+ assert_equal '__xhtml__list', action
35
+
36
+ klass, action, base = @d.dispatch('/blog')
37
+ assert_equal BlogController, klass
38
+ assert_equal '__xhtml__index', action
39
+ assert_equal 'root/blog', base
40
+
41
+ klass, action, base = @d.dispatch('/login')
42
+ assert_equal MainController, klass
43
+ assert_equal '__xhtml__login', action
44
+ assert_equal 'root', base
45
+
46
+ klass, action, base = @d.dispatch('/')
47
+ assert_equal MainController, klass
48
+ assert_equal '__xhtml__index', action
49
+ assert_equal 'root', base
50
+
51
+ # multi-api dispatcher.
52
+
53
+ # no xml prefix, use xhtml api.
54
+ klass, action = @dxml.dispatch('/blog/list')
55
+ assert_equal BlogController, klass
56
+ assert_equal '__xhtml__list', action
57
+
58
+ # xml prefix, use xml api.
59
+ klass, action = @dxml.dispatch('/xml/blog/list')
60
+ assert_equal BlogController, klass
61
+ assert_equal '__xml__list', action
62
+ end
63
+
64
+ end