ramaze 2008.06 → 2008.11

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 (184) hide show
  1. data/README.markdown +6 -6
  2. data/Rakefile +33 -3
  3. data/bin/ramaze +18 -0
  4. data/doc/CHANGELOG +960 -0
  5. data/doc/LEGAL +5 -1
  6. data/doc/meta/announcement.txt +20 -36
  7. data/doc/tutorial/todolist.html +421 -313
  8. data/doc/tutorial/todolist.mkd +33 -16
  9. data/examples/app/blog/spec/blog.rb +3 -3
  10. data/examples/app/rapaste/controller/paste.rb +8 -1
  11. data/examples/app/rapaste/model/paste.rb +3 -0
  12. data/examples/app/rapaste/spec/rapaste.rb +3 -1
  13. data/examples/app/rapaste/start.rb +3 -2
  14. data/examples/app/sourceview/public/sourceview.js +2 -2
  15. data/examples/app/todolist/spec/todolist.rb +6 -6
  16. data/examples/app/todolist/template/index.xhtml +1 -1
  17. data/examples/app/whywiki/spec/whywiki.rb +2 -2
  18. data/examples/app/wikore/spec/wikore.rb +2 -2
  19. data/examples/app/wikore/src/model.rb +4 -3
  20. data/examples/app/wiktacular/spec/wiktacular.rb +7 -7
  21. data/examples/basic/simple.rb +2 -2
  22. data/examples/helpers/paginate.rb +71 -0
  23. data/examples/misc/simple_auth.rb +20 -8
  24. data/lib/proto/controller/init.rb +10 -0
  25. data/lib/proto/controller/main.rb +1 -3
  26. data/lib/proto/model/init.rb +4 -0
  27. data/lib/proto/public/dispatch.fcgi +1 -1
  28. data/lib/proto/spec/main.rb +2 -1
  29. data/lib/proto/start.rb +3 -3
  30. data/lib/proto/start.ru +1 -1
  31. data/lib/proto/view/error.xhtml +4 -4
  32. data/lib/ramaze.rb +8 -3
  33. data/lib/ramaze/action.rb +6 -6
  34. data/lib/ramaze/adapter.rb +1 -6
  35. data/lib/ramaze/adapter/base.rb +30 -27
  36. data/lib/ramaze/adapter/cgi.rb +1 -0
  37. data/lib/ramaze/cache.rb +1 -3
  38. data/lib/ramaze/cache/memcached.rb +3 -5
  39. data/lib/ramaze/contrib/auto_params.rb +2 -2
  40. data/lib/ramaze/contrib/auto_params/get_args.rb +2 -1
  41. data/lib/ramaze/contrib/gems.rb +17 -18
  42. data/lib/ramaze/contrib/gzip_filter.rb +22 -9
  43. data/lib/ramaze/contrib/maruku_uv.rb +59 -0
  44. data/lib/ramaze/contrib/profiling.rb +1 -1
  45. data/lib/ramaze/contrib/rest.rb +16 -13
  46. data/lib/ramaze/contrib/sequel/create_join.rb +25 -0
  47. data/lib/ramaze/contrib/sequel/form_field.rb +129 -0
  48. data/lib/ramaze/contrib/sequel/image.rb +198 -0
  49. data/lib/ramaze/contrib/sequel/relation.rb +82 -0
  50. data/lib/ramaze/controller.rb +33 -34
  51. data/lib/ramaze/controller/resolve.rb +29 -9
  52. data/lib/ramaze/current.rb +60 -20
  53. data/lib/ramaze/current/request.rb +8 -7
  54. data/lib/ramaze/current/response.rb +15 -3
  55. data/lib/ramaze/current/session/flash.rb +8 -0
  56. data/lib/ramaze/dispatcher.rb +17 -9
  57. data/lib/ramaze/dispatcher/action.rb +4 -5
  58. data/lib/ramaze/dispatcher/directory.rb +1 -1
  59. data/lib/ramaze/dispatcher/error.rb +4 -4
  60. data/lib/ramaze/dispatcher/file.rb +4 -4
  61. data/lib/ramaze/gestalt.rb +15 -20
  62. data/lib/ramaze/helper/cgi.rb +7 -15
  63. data/lib/ramaze/helper/formatting.rb +41 -1
  64. data/lib/ramaze/helper/httpdigest.rb +20 -7
  65. data/lib/ramaze/helper/link.rb +4 -6
  66. data/lib/ramaze/helper/paginate.rb +233 -0
  67. data/lib/ramaze/helper/redirect.rb +1 -1
  68. data/lib/ramaze/helper/rest.rb +1 -1
  69. data/lib/ramaze/helper/thread.rb +17 -0
  70. data/lib/ramaze/helper/ultraviolet.rb +44 -0
  71. data/lib/ramaze/helper/user.rb +4 -9
  72. data/lib/ramaze/log.rb +2 -2
  73. data/lib/ramaze/log/analogger.rb +21 -23
  74. data/lib/ramaze/log/growl.rb +21 -23
  75. data/lib/ramaze/log/hub.rb +1 -1
  76. data/lib/ramaze/log/informer.rb +97 -99
  77. data/lib/ramaze/log/knotify.rb +14 -16
  78. data/lib/ramaze/log/logger.rb +11 -13
  79. data/lib/ramaze/log/logging.rb +61 -63
  80. data/lib/ramaze/log/rotatinginformer.rb +168 -0
  81. data/lib/ramaze/log/syslog.rb +41 -31
  82. data/lib/ramaze/log/xosd.rb +70 -72
  83. data/lib/ramaze/option.rb +9 -6
  84. data/lib/ramaze/option/holder.rb +5 -27
  85. data/lib/ramaze/reloader.rb +186 -0
  86. data/lib/ramaze/setup.rb +1 -1
  87. data/lib/ramaze/snippets.rb +13 -0
  88. data/lib/ramaze/snippets/array/put_within.rb +31 -24
  89. data/lib/ramaze/snippets/binding/locals.rb +23 -11
  90. data/lib/ramaze/snippets/dictionary.rb +2 -2
  91. data/lib/ramaze/snippets/fiber.rb +63 -0
  92. data/lib/ramaze/snippets/kernel/constant.rb +36 -21
  93. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +12 -6
  94. data/lib/ramaze/snippets/numeric/filesize_format.rb +24 -17
  95. data/lib/ramaze/snippets/numeric/time.rb +63 -0
  96. data/lib/ramaze/snippets/object/__dir__.rb +29 -0
  97. data/lib/ramaze/snippets/object/acquire.rb +40 -0
  98. data/lib/ramaze/snippets/object/instance_variable_defined.rb +16 -5
  99. data/lib/ramaze/snippets/object/pretty.rb +14 -4
  100. data/lib/ramaze/snippets/object/scope.rb +14 -7
  101. data/lib/ramaze/snippets/ordered_set.rb +25 -14
  102. data/lib/ramaze/snippets/proc/locals.rb +17 -9
  103. data/lib/ramaze/snippets/ramaze/deprecated.rb +13 -0
  104. data/lib/ramaze/snippets/ramaze/fiber.rb +24 -0
  105. data/lib/ramaze/snippets/ramaze/state.rb +86 -0
  106. data/lib/ramaze/snippets/ramaze/struct.rb +45 -0
  107. data/lib/ramaze/snippets/string/camel_case.rb +13 -8
  108. data/lib/ramaze/snippets/string/color.rb +24 -20
  109. data/lib/ramaze/snippets/string/each.rb +14 -3
  110. data/lib/ramaze/snippets/string/end_with.rb +20 -0
  111. data/lib/ramaze/snippets/string/esc.rb +26 -21
  112. data/lib/ramaze/snippets/string/ord.rb +12 -6
  113. data/lib/ramaze/snippets/string/snake_case.rb +13 -7
  114. data/lib/ramaze/snippets/string/start_with.rb +16 -5
  115. data/lib/ramaze/snippets/string/unindent.rb +23 -15
  116. data/lib/ramaze/snippets/thread/into.rb +3 -3
  117. data/lib/ramaze/spec/helper/bacon.rb +5 -5
  118. data/lib/ramaze/spec/helper/mock_http.rb +1 -1
  119. data/lib/ramaze/spec/helper/pretty_output.rb +2 -2
  120. data/lib/ramaze/spec/helper/snippets.rb +8 -0
  121. data/lib/ramaze/template.rb +4 -1
  122. data/lib/ramaze/template/ezamar/textpow.syntax +34 -0
  123. data/lib/ramaze/template/maruku.rb +34 -0
  124. data/lib/ramaze/template/tagz.rb +2 -2
  125. data/lib/ramaze/template/xslt.rb +2 -2
  126. data/lib/ramaze/tool/create.rb +27 -53
  127. data/lib/ramaze/tool/localize.rb +8 -4
  128. data/lib/ramaze/tool/mime.rb +11 -1
  129. data/lib/ramaze/tool/project_creator.rb +110 -0
  130. data/lib/ramaze/trinity.rb +4 -1
  131. data/lib/ramaze/version.rb +1 -1
  132. data/lib/vendor/bacon.rb +323 -0
  133. data/rake_tasks/gem.rake +10 -1
  134. data/rake_tasks/maintenance.rake +40 -2
  135. data/rake_tasks/metric.rake +24 -0
  136. data/rake_tasks/release.rake +17 -4
  137. data/rake_tasks/spec.rake +1 -2
  138. data/ramaze.gemspec +549 -495
  139. data/spec/contrib/auto_params.rb +3 -3
  140. data/spec/contrib/profiling.rb +2 -2
  141. data/spec/examples/simple_auth.rb +2 -2
  142. data/spec/examples/templates/template_haml.rb +0 -2
  143. data/spec/ramaze/action/file_cache.rb +22 -0
  144. data/spec/ramaze/adapter.rb +2 -2
  145. data/spec/ramaze/controller/actionless_templates.rb +1 -1
  146. data/spec/ramaze/controller/subclass.rb +15 -0
  147. data/spec/ramaze/controller/template_resolving.rb +1 -1
  148. data/spec/ramaze/controller/view/bar.xhtml +1 -0
  149. data/spec/ramaze/controller/view/base/another.xhtml +1 -0
  150. data/spec/ramaze/current/session.rb +1 -1
  151. data/spec/ramaze/dispatcher/file.rb +2 -2
  152. data/spec/ramaze/helper/aspect.rb +26 -17
  153. data/spec/ramaze/helper/formatting.rb +13 -0
  154. data/spec/ramaze/log/informer.rb +10 -10
  155. data/spec/ramaze/log/syslog.rb +67 -4
  156. data/spec/ramaze/rewrite.rb +1 -1
  157. data/spec/ramaze/route.rb +1 -1
  158. data/spec/ramaze/struct.rb +47 -0
  159. data/spec/ramaze/template/markaby.rb +1 -1
  160. data/spec/ramaze/template/tagz.rb +1 -1
  161. data/spec/snippets/binding/locals.rb +9 -0
  162. data/spec/snippets/numeric/time.rb +12 -0
  163. data/spec/snippets/{kernel → object}/__dir__.rb +0 -0
  164. data/spec/snippets/{kernel → object}/acquire.rb +0 -0
  165. metadata +90 -81
  166. data/cache.yaml +0 -7
  167. data/examples/app/rammit/spec/rammit.rb +0 -31
  168. data/examples/app/rammit/src/controller/main.rb +0 -3
  169. data/examples/app/rammit/src/controller/page.rb +0 -16
  170. data/examples/app/rammit/src/model.rb +0 -33
  171. data/examples/app/rammit/start.rb +0 -8
  172. data/examples/app/rammit/template/index.xhtml +0 -14
  173. data/examples/app/rammit/template/page/view.xhtml +0 -4
  174. data/lib/ramaze/snippets/kernel/__dir__.rb +0 -23
  175. data/lib/ramaze/snippets/kernel/acquire.rb +0 -34
  176. data/lib/ramaze/snippets/object/thread_accessor.rb +0 -5
  177. data/lib/ramaze/snippets/ramaze/thread_accessor.rb +0 -58
  178. data/lib/ramaze/snippets/struct/fill.rb +0 -23
  179. data/lib/ramaze/snippets/struct/values_at.rb +0 -39
  180. data/lib/ramaze/snippets/symbol/to_proc.rb +0 -24
  181. data/lib/ramaze/sourcereload.rb +0 -176
  182. data/spec/snippets/struct/fill.rb +0 -26
  183. data/spec/snippets/struct/values_at.rb +0 -52
  184. data/spec/snippets/symbol/to_proc.rb +0 -13
@@ -1,5 +1,5 @@
1
1
  require 'spec/helper'
2
- spec_require 'ruby2ruby'
2
+ spec_require 'parse_tree', 'ruby2ruby'
3
3
 
4
4
  Ramaze.contrib :auto_params
5
5
 
@@ -100,7 +100,7 @@ describe 'Parameterized actions' do
100
100
  end if method(:puts).respond_to? :get_args
101
101
 
102
102
  describe 'Normal behavior' do
103
- extend MockHTTP
103
+ behaves_like 'http'
104
104
  ramaze
105
105
 
106
106
  it 'should work with no arguments' do
@@ -108,7 +108,7 @@ describe 'Normal behavior' do
108
108
  end
109
109
 
110
110
  it 'should raise no action' do
111
- get('/none').body.should =~ /^No Action found/
111
+ get('/none').body.should =~ /No Action found/
112
112
  end
113
113
 
114
114
  it 'should work with included actions' do
@@ -11,7 +11,7 @@ class MainController < Ramaze::Controller
11
11
  end
12
12
 
13
13
  output = StringIO.new
14
- Ramaze::Log.loggers << Ramaze::Logging::Logger::Informer.new(output)
14
+ Ramaze::Log.loggers << Ramaze::Logger::Informer.new(output)
15
15
 
16
16
  describe 'Profiling' do
17
17
  behaves_like "http"
@@ -19,7 +19,7 @@ describe 'Profiling' do
19
19
 
20
20
  it "should profile" do
21
21
  output = StringIO.new
22
- Ramaze::Log.loggers << Ramaze::Logging::Logger::Informer.new(output)
22
+ Ramaze::Log.loggers << Ramaze::Logger::Informer.new(output)
23
23
 
24
24
  get('/')
25
25
  output.string.should =~ /Thread ID:\s\d+/
@@ -7,12 +7,12 @@ describe "SimpleAuth" do
7
7
 
8
8
  it 'should show start page' do
9
9
  Browser.new do
10
- http.basic_authentication "username", "password"
10
+ http.basic_authentication "jill", "password1"
11
11
  get('/').should == "Secret Info"
12
12
  end
13
13
 
14
14
  Browser.new do
15
- http.basic_authentication "admin", "secret"
15
+ http.basic_authentication "jack", "password2"
16
16
  get('/').should == "Secret Info"
17
17
  end
18
18
  end
@@ -21,5 +21,3 @@ describe 'Template Haml' do
21
21
  end
22
22
  end
23
23
  end
24
-
25
-
@@ -22,6 +22,18 @@ class TCOtherCache < Ramaze::Controller
22
22
  cache :index
23
23
  end
24
24
 
25
+ class TCIndexCache < Ramaze::Controller
26
+ map '/withparams'
27
+ helper :cache
28
+
29
+ def index(somearg = nil)
30
+ rand + somearg.to_f
31
+ end
32
+ alias :nonindex :index
33
+
34
+ cache :index, :nonindex
35
+ end
36
+
25
37
  describe 'Action rendering' do
26
38
  behaves_like 'http'
27
39
 
@@ -44,5 +56,15 @@ describe 'Action rendering' do
44
56
  File.file?(public_root/'other/index').should == true
45
57
  end
46
58
 
59
+ should 'cache action with params' do
60
+ lambda{ req('/withparams/nonindex/42') }.should.not.change{ req('/withparams/nonindex/42') }
61
+ File.file?(public_root/'withparams/nonindex/42').should == true
62
+ end
63
+
64
+ should 'cache index action with params' do
65
+ lambda{ req('/withparams/42') }.should.not.change{ req('/withparams/42') }
66
+ File.file?(public_root/'withparams/42').should == true
67
+ end
68
+
47
69
  FileUtils.rm_rf public_root
48
70
  end
@@ -12,7 +12,7 @@ class TCAdapterController < Ramaze::Controller
12
12
  end
13
13
 
14
14
  $output = StringIO.new
15
- Ramaze::Log.loggers << Ramaze::Logging::Logger::Informer.new($output)
15
+ Ramaze::Log.loggers << Ramaze::Logger::Informer.new($output)
16
16
 
17
17
  describe "Adapter" do
18
18
  ramaze ramaze_options ||= {}
@@ -46,4 +46,4 @@ describe "Adapter" do
46
46
  ret.status.should == 200
47
47
  ret.body.should == 'i am before'
48
48
  end
49
- end
49
+ end
@@ -19,7 +19,7 @@ end
19
19
  describe "Testing Actionless Templates" do
20
20
  behaves_like 'http'
21
21
  ramaze :actionless_templates => false,
22
- :view_root => __DIR__/:view
22
+ :view_root => __DIR__/:view, :error_page => true
23
23
 
24
24
  it "should not find template file for non existant method" do
25
25
  get('/non_existant_method').status.should == 404
@@ -4,6 +4,9 @@
4
4
  require 'spec/helper'
5
5
 
6
6
  class BaseController < Ramaze::Controller
7
+ template :foo, :bar
8
+ template :one, self, :another
9
+
7
10
  def test() 'test' end
8
11
  end
9
12
 
@@ -18,4 +21,16 @@ describe 'Controller' do
18
21
  it 'should allow sub-classing MainController' do
19
22
  get('/test').body.should == 'test'
20
23
  end
24
+
25
+ it 'should respect template mappings set in superclass, with no explicit controller' do
26
+ # The template file it should use is view/bar.xhtml, as the template mapping doesn't
27
+ # specify a controller, so it will be implicitly relative to MainController.
28
+ get('/foo').body.should == 'bar'
29
+ end
30
+
31
+ it 'should respect template mappings set in superclass, with an explicit controller' do
32
+ # Note that the template file it should use is view/base/another.xhtml, because
33
+ # BaseController explicitly specifies the template mapping in relation to self.
34
+ get('/one').body.should == 'another'
35
+ end
21
36
  end
@@ -44,7 +44,7 @@ class OtherController < MainController
44
44
 
45
45
  end
46
46
 
47
- class AnotherController < Ramaze::Controller
47
+ class AnotherController < MainController
48
48
  Root = __DIR__/:view
49
49
  Absolute = lambda{|path| File.join Root, path}
50
50
  Relative = lambda{|path| path}
@@ -35,7 +35,7 @@ describe "Session" do
35
35
  (Ramaze::Session::IP_COUNT_LIMIT + 2).times do
36
36
  r = get('/')
37
37
  r.body.should == "nothing"
38
- r.headers.should == {'Content-Type' => 'text/html'}
38
+ r.headers['Content-Type'].should == 'text/html'
39
39
  end
40
40
  end
41
41
  end
@@ -37,7 +37,7 @@ describe 'Dispatcher::File' do
37
37
  it 'should send Last-Modified' do
38
38
  res = get '/test_download.css'
39
39
  res.headers['Last-Modified'].should.not.be == nil
40
- res.headers['Last-Modified'].should == File.stat(@public_root/'test_download.css').mtime.httpdate
40
+ res.headers['Last-Modified'].should == File.mtime(@public_root/'test_download.css').httpdate
41
41
  end
42
42
 
43
43
  it 'should respect ETag with IF_NONE_MATCHES' do
@@ -57,4 +57,4 @@ describe 'Dispatcher::File' do
57
57
  res.status.should == 304
58
58
  res.body.should == ''
59
59
  end
60
- end
60
+ end
@@ -8,14 +8,14 @@ class TCAspectController < Ramaze::Controller
8
8
  trait :foo => :bar
9
9
  helper :aspect
10
10
 
11
- def test_before() request[:before] += 2 end
12
- before(:test_before){ request[:before] = 40 }
11
+ def test_before() $helper_aspect_spec_test_before += 2 end
12
+ before(:test_before){ $helper_aspect_spec_test_before = 40 }
13
13
 
14
- def test_after() request[:after] = 40 end
15
- after(:test_after){ request[:after] += 2 }
14
+ def test_after() $helper_aspect_spec_test_after = 40 end
15
+ after(:test_after){ $helper_aspect_spec_test_after += 2 }
16
16
 
17
17
  def test_wrap() end
18
- wrap(:test_wrap){ request[:wrap] ||= 0; request[:wrap] += 21 }
18
+ wrap(:test_wrap){ $helper_aspect_spec_test_wrap ||= 0; $helper_aspect_spec_test_wrap += 21 }
19
19
 
20
20
  wrap(:test_template) { '<aspect>' }
21
21
  end
@@ -29,8 +29,8 @@ class TCAspectAllController < Ramaze::Controller
29
29
  def test_all_first() 'first' end
30
30
  def test_all_second() 'second' end
31
31
 
32
- before_all{ request[:all] = 40 }
33
- after_all{ request[:all] += 2 }
32
+ before_all{ $helper_aspect_spec_all = 40 }
33
+ after_all{ $helper_aspect_spec_all += 2 }
34
34
 
35
35
  def test_all_after() 'after' end
36
36
 
@@ -42,51 +42,60 @@ end
42
42
  describe "AspectHelper" do
43
43
  behaves_like 'http'
44
44
  ramaze :error_page => false
45
- extend Ramaze::Trinity
46
45
 
47
46
  it "shouldn't overwrite traits on inclusion" do
48
47
  TCAspectController.trait[:foo].should == :bar
49
48
  end
50
49
 
51
50
  it 'should use before' do
51
+ $helper_aspect_spec_test_before = nil
52
52
  get('/test_before')
53
- request[:before].should == 42
53
+ $helper_aspect_spec_test_before.should == 42
54
54
  end
55
55
 
56
56
  it 'should use after' do
57
+ $helper_aspect_spec_test_after = nil
57
58
  get('/test_after')
58
- request[:after].should == 42
59
+ $helper_aspect_spec_test_after.should == 42
59
60
  end
60
61
 
61
62
  it 'should use wrap' do
63
+ $helper_aspect_spec_test_wrap = nil
62
64
  get('/test_wrap')
63
- request[:wrap].should == 42
65
+ $helper_aspect_spec_test_wrap.should == 42
64
66
  end
65
67
 
66
68
  it 'should before_all and after_all' do
69
+ $helper_aspect_spec_all = nil
67
70
  get('/all/test_all_first')
68
- request[:all].should == 42
71
+ $helper_aspect_spec_all.should == 42
72
+
73
+ $helper_aspect_spec_all = nil
69
74
  get('/all/test_all_second')
70
- request[:all].should == 42
75
+ $helper_aspect_spec_all.should == 42
71
76
  end
72
77
 
73
78
  it 'should before_all and after_all for templates' do
79
+ $helper_aspect_spec_all = nil
74
80
  get('/all/test_template')
75
- request[:all].should == 42
81
+ $helper_aspect_spec_all.should == 42
76
82
  end
77
83
 
78
84
  it 'should before_all and after_all for all defined actions' do
85
+ $helper_aspect_spec_all = nil
79
86
  get('/all/test_all_after')
80
- request[:all].should == 42
87
+ $helper_aspect_spec_all.should == 42
81
88
  end
82
89
 
83
90
  it 'should not apply aspects to render_template' do
91
+ $helper_aspect_spec_all = nil
84
92
  get('/all/loop').body.gsub(/\s/,'').should == '12345'
85
- request[:all].should == 42
93
+ $helper_aspect_spec_all.should == 42
86
94
  end
87
95
 
88
96
  it 'should not apply aspects to layouts' do
97
+ $helper_aspect_spec_all = nil
89
98
  get('/all/loop_with_layout').body.gsub(/\s/,'').should == '<div>12345</div>'
90
- request[:all].should == 42
99
+ $helper_aspect_spec_all.should == 42
91
100
  end
92
101
  end
@@ -26,6 +26,11 @@ describe 'Helper::Formatting' do
26
26
  "<a href=\"http://ramaze.net\" target='_blank'>http://ramaze.net</a>"
27
27
  end
28
28
 
29
+ it 'should auto_link urls, setting the result of the given block as the link text' do
30
+ auto_link('http://ramaze.net rocks, so does http://rubyonrails.org.') { |url| url.sub!(%r{http://}, '') }.should ==
31
+ '<a href="http://ramaze.net">ramaze.net</a> rocks, so does <a href="http://rubyonrails.org">rubyonrails.org</a>.'
32
+ end
33
+
29
34
  should 'ordinalize numbers' do
30
35
  ordinal(1).should == '1st'
31
36
  ordinal(2).should == '2nd'
@@ -38,4 +43,12 @@ describe 'Helper::Formatting' do
38
43
  ordinal(100).should == '100th'
39
44
  ordinal(133).should == '133rd'
40
45
  end
46
+
47
+ should 'generate tagclouds' do
48
+ tags = %w[ruby ruby code ramaze]
49
+ tagcloud(tags).should ==
50
+ {"code"=>0.75, "ramaze"=>0.75, "ruby"=>1.0}
51
+ tagcloud(tags, 0.5, 2.0).should ==
52
+ {"code"=>0.875, "ramaze"=>0.875, "ruby"=>1.25}
53
+ end
41
54
  end
@@ -4,8 +4,8 @@ describe 'Informer' do
4
4
  before do
5
5
  @out = []
6
6
  def @out.puts(*args) push(*args) end
7
- Ramaze::Logging::Logger::Informer.trait[:colorize] = false
8
- @inform = Ramaze::Logging::Logger::Informer.new(@out)
7
+ Ramaze::Logger::Informer.trait[:colorize] = false
8
+ @inform = Ramaze::Logger::Informer.new(@out)
9
9
  end
10
10
 
11
11
  def format(tag, string)
@@ -39,27 +39,27 @@ describe 'Informer' do
39
39
  end
40
40
 
41
41
  it 'should choose stdout on init(stdout,:stdout,STDOUT)' do
42
- a = Ramaze::Logging::Logger::Informer.new(STDOUT)
43
- b = Ramaze::Logging::Logger::Informer.new(:stdout)
44
- c = Ramaze::Logging::Logger::Informer.new('stdout')
42
+ a = Ramaze::Logger::Informer.new(STDOUT)
43
+ b = Ramaze::Logger::Informer.new(:stdout)
44
+ c = Ramaze::Logger::Informer.new('stdout')
45
45
  [a,b,c].each { |x| x.out.should == $stdout}
46
46
  end
47
47
 
48
48
  it 'should choose stderr on init(stderr,:stderr,STDERR)' do
49
- a = Ramaze::Logging::Logger::Informer.new(STDERR)
50
- b = Ramaze::Logging::Logger::Informer.new(:stderr)
51
- c = Ramaze::Logging::Logger::Informer.new('stderr')
49
+ a = Ramaze::Logger::Informer.new(STDERR)
50
+ b = Ramaze::Logger::Informer.new(:stderr)
51
+ c = Ramaze::Logger::Informer.new('stderr')
52
52
  [a,b,c].each { |x| x.out.should == $stderr}
53
53
  end
54
54
 
55
55
  it 'should use IO when supplied' do
56
- i = Ramaze::Logging::Logger::Informer.new(s = StringIO.new)
56
+ i = Ramaze::Logger::Informer.new(s = StringIO.new)
57
57
  i.out.should == s
58
58
  end
59
59
 
60
60
  it 'should open file otherwise' do
61
61
  begin
62
- i = Ramaze::Logging::Logger::Informer.new('tmp.dummy')
62
+ i = Ramaze::Logger::Informer.new('tmp.dummy')
63
63
  out = i.out
64
64
  out.should.be.instance_of(File)
65
65
  out.path.should == 'tmp.dummy'
@@ -1,10 +1,73 @@
1
+ # Copyright (c) 2008 rob@rebeltechnologies.nl
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
1
4
  require 'spec/helper'
2
5
 
3
6
  require 'ramaze/log/syslog'
4
7
 
5
8
  describe 'Syslog' do
6
- it 'should do something' do
7
- syslog = Ramaze::Logging::Logger::Syslog.new
8
- syslog.send(:ident).should =~ /#{Regexp.escape(__FILE__)}$/
9
- end
9
+
10
+ # close the syslog, if it was open for some reason before we
11
+ # start a test.
12
+ before do
13
+ if ( Syslog.opened? )
14
+ ::Syslog.close
15
+ end
16
+ end
17
+
18
+ it 'should default initialize correctly' do
19
+ syslog = Ramaze::Logger::Syslog.new
20
+ ::Syslog.opened?.should == true
21
+ ::Syslog.ident.should == $0
22
+ ::Syslog.options.should == ( ::Syslog::LOG_PID | ::Syslog::LOG_CONS )
23
+ ::Syslog.facility.should == ::Syslog::LOG_USER
24
+ end
25
+
26
+ it 'should handle non default initialization' do
27
+ syslog = Ramaze::Logger::Syslog.new( 'ramaze_syslog_test',
28
+ ::Syslog::LOG_NDELAY | ::Syslog::LOG_NOWAIT,
29
+ ::Syslog::LOG_DAEMON )
30
+ ::Syslog.opened?.should == true
31
+ ::Syslog.ident.should == 'ramaze_syslog_test'
32
+ ::Syslog.options.should == ( ::Syslog::LOG_NDELAY | ::Syslog::LOG_NOWAIT )
33
+ ::Syslog.facility.should == ::Syslog::LOG_DAEMON
34
+ end
35
+
36
+ # We test the actual logging using a trick found in te test code of the
37
+ # syslog module. We create a pipe, fork a child, reroute the childs
38
+ # stderr to the pipe. Then we open the logging using LOG_PERROR, so all
39
+ # log messages are written to stderror. In the parent we read the messages
40
+ # from the pipe and compare them to what we expected.
41
+ def test_log_msg( type, priority, msg )
42
+ logpipe = IO::pipe
43
+ child = fork {
44
+ logpipe[0].close
45
+ STDERR.reopen(logpipe[1])
46
+ syslog = Ramaze::Logger::Syslog.new( 'ramaze_syslog_test',
47
+ ::Syslog::LOG_PID | ::Syslog::LOG_NDELAY | ::Syslog::LOG_PERROR,
48
+ ::Syslog::LOG_USER )
49
+ syslog.send priority, msg
50
+ Process.exit!( 0 )
51
+ }
52
+ logpipe[1].close
53
+ Process.waitpid(child)
54
+
55
+ logpipe[0].gets.should == "ramaze_syslog_test[#{child}]: #{msg}\n"
56
+ end
57
+
58
+ it 'should handle debug' do
59
+ test_log_msg :direct, :debug, "Hello Debug World"
60
+ end
61
+ it 'should handle dev' do
62
+ test_log_msg :direct, :dev, "Hello Dev World"
63
+ end
64
+ it 'should handle info' do
65
+ test_log_msg :direct, :info, 'Hello Info World!'
66
+ end
67
+ it 'should handle warn' do
68
+ test_log_msg :direct, :warn, 'Hello Warn World!'
69
+ end
70
+ it 'should handle error' do
71
+ test_log_msg :direct, :error, 'Hello Error World!'
72
+ end
10
73
  end
@@ -33,4 +33,4 @@ describe 'Route' do
33
33
  r = get('/index.php/file.css')
34
34
  [ r.status, r.body ].should == [ 200, 'this is css' ]
35
35
  end
36
- end
36
+ end