ramaze 2012.12.08b → 2023.01.06

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -1
  3. data/README.md +1 -0
  4. data/examples/app/whywiki/spec/whywiki.rb +22 -24
  5. data/examples/app/whywiki/start.rb +10 -9
  6. data/examples/app/whywiki/{template → view}/edit.xhtml +2 -2
  7. data/examples/app/whywiki/view/show.xhtml +20 -0
  8. data/examples/app/wikore/spec/wikore.rb +1 -1
  9. data/guide/AUTHORS +11 -3
  10. data/guide/CHANGELOG +3803 -3592
  11. data/guide/general/sessions.md +42 -0
  12. data/guide/general/upgrading.md +85 -0
  13. data/lib/proto/Gemfile +2 -2
  14. data/lib/ramaze/cache/memcache.rb +3 -3
  15. data/lib/ramaze/cache/moneta.rb +143 -0
  16. data/lib/ramaze/cache/redis.rb +8 -11
  17. data/lib/ramaze/cache/sequel.rb +2 -2
  18. data/lib/ramaze/cache.rb +1 -0
  19. data/lib/ramaze/files.rb +1 -1
  20. data/lib/ramaze/helper/paginate.rb +5 -0
  21. data/lib/ramaze/helper/request_accessor.rb +3 -1
  22. data/lib/ramaze/helper/stack.rb +1 -1
  23. data/lib/ramaze/helper/upload.rb +1 -1
  24. data/lib/ramaze/log/syslog.rb +1 -1
  25. data/lib/ramaze/request.rb +2 -2
  26. data/lib/ramaze/snippets.rb +0 -1
  27. data/lib/ramaze/version.rb +3 -1
  28. data/lib/ramaze/view/nagoro/render_partial.rb +1 -1
  29. data/lib/ramaze.rb +1 -1
  30. data/ramaze.gemspec +19 -15
  31. data/spec/ramaze/cache/moneta.rb +53 -0
  32. data/spec/ramaze/cache/redis.rb +1 -1
  33. data/spec/ramaze/cache/sequel.rb +2 -0
  34. data/spec/ramaze/dispatcher/directory.rb +24 -14
  35. data/spec/ramaze/dispatcher/file.rb +0 -5
  36. data/spec/ramaze/error.rb +13 -17
  37. data/spec/ramaze/helper/paginate.rb +41 -13
  38. data/spec/ramaze/log/syslog.rb +75 -63
  39. data/spec/ramaze/session/redis.rb +2 -2
  40. data/spec/ramaze/session/sequel.rb +2 -0
  41. data/spec/ramaze/view/haml.rb +3 -3
  42. data/spec/ramaze/view/slim.rb +1 -1
  43. metadata +95 -164
  44. data/.gems +0 -28
  45. data/.gitignore +0 -14
  46. data/.mailmap +0 -34
  47. data/.rvmrc +0 -2
  48. data/.travis.yml +0 -16
  49. data/.yardopts +0 -14
  50. data/examples/app/blog/public/.htaccess +0 -24
  51. data/examples/app/whywiki/template/show.xhtml +0 -18
  52. data/lib/ramaze/cache/localmemcache.rb +0 -53
  53. data/lib/ramaze/snippets/ramaze/lru_hash.rb +0 -247
  54. data/spec/ramaze/cache/localmemcache.rb +0 -50
  55. data/spec/ramaze/session/localmemcache.rb +0 -58
@@ -3,7 +3,7 @@
3
3
 
4
4
  require File.expand_path('../../../../spec/helper', __FILE__)
5
5
 
6
- spec_require 'hpricot'
6
+ spec_require 'nokogiri'
7
7
 
8
8
  Ramaze.middleware(:spec) do
9
9
  run Rack::ETag.new(
@@ -36,37 +36,47 @@ describe 'Directory listing' do
36
36
  get('path').body
37
37
  end
38
38
 
39
- def check(url, title, list)
39
+ def check(url, title, list, ignore_order = false)
40
40
  got = get(url)
41
- got.status.should == 200
41
+
42
+ got.status.should == 200
42
43
  got['Content-Type'].should == 'text/html; charset=utf-8'
43
44
 
44
- doc = Hpricot(got.body)
45
+ doc = Nokogiri::HTML(got.body)
46
+
45
47
  doc.at(:title).inner_text.should == title
46
48
 
47
- (doc/'td.name/a').map{|a| [a[:href], a.inner_text] }.should == list
49
+ urls = doc.css('td.name a').map do |a|
50
+ ["/#{a[:href]}".squeeze('/'), a.inner_text]
51
+ end
52
+ if ignore_order
53
+ urls.flatten.sort.should == list.flatten.sort
54
+ else
55
+ urls.should == list
56
+ end
48
57
  end
49
58
 
50
59
  should 'dry serve root directory' do
51
- files = [
52
- ["../", "Parent Directory"],
53
- ["/favicon.ico", "favicon.ico"],
54
- ["/file+name.txt", "file name.txt"],
55
- ["/test/", "test/"],
56
- ["/test_download.css", "test_download.css"]
57
- ]
60
+ files = [
61
+ # ["/../", "Parent Directory"],
62
+ ["/favicon.ico", "favicon.ico"],
63
+ ["/test/", "test/"],
64
+ ["/test_download.css", "test_download.css"],
65
+ ["/file%20name.txt", "file name.txt"]
66
+ ]
58
67
 
59
68
  check '/', '/', files
60
69
  end
61
70
 
62
71
  should 'serve hierarchies' do
63
72
  files = [
64
- ["../", "Parent Directory"],
73
+ ["/test/../", "Parent Directory"],
65
74
  ["/test/deep/", "deep/"],
66
75
  ["/test/five.txt", "five.txt"],
67
76
  ["/test/six.txt", "six.txt"]
68
77
  ]
69
- check '/test', '/test', files
78
+
79
+ check '/test', '/test', files, true
70
80
  end
71
81
 
72
82
  FileUtils.rm_rf(__DIR__('public/test'))
@@ -3,11 +3,6 @@
3
3
 
4
4
  require File.expand_path('../../../../spec/helper', __FILE__)
5
5
 
6
- # This spec more or less tries to ensure that we integrate with rack and
7
- # rack-contrib in regards to static file serving.
8
-
9
- spec_require 'rack/contrib'
10
-
11
6
  Ramaze.middleware(:spec) do
12
7
  use Rack::ConditionalGet
13
8
  use Rack::ETag
data/spec/ramaze/error.rb CHANGED
@@ -2,8 +2,7 @@
2
2
  # All files in this distribution are subject to the terms of the MIT license.
3
3
 
4
4
  require File.expand_path('../../../spec/helper', __FILE__)
5
- require 'rexml/document'
6
- require 'rexml/xpath'
5
+ require 'nokogiri'
7
6
 
8
7
  class SpecError < Ramaze::Controller
9
8
  map '/'
@@ -40,15 +39,14 @@ describe 'Error handling' do
40
39
  Ramaze.options.mode = :dev
41
40
 
42
41
  it 'uses Rack::ShowException to display errors' do
43
- got = get('/raises')
44
- [got.status, got['Content-Type']].should == [500, 'text/html']
45
-
46
- # we use this xpath notation because otherwise rexml is really slow...
47
- doc = REXML::Document.new(got.body)
48
- REXML::XPath.first(doc, "/html/body/div[1]/h1").text.
49
- should == "NameError at /raises"
50
- REXML::XPath.first(doc, "/html/body/div[4]/p/code").text.
51
- should == "Rack::ShowExceptions"
42
+ got = get('/raises', {}, {'HTTP_ACCEPT' => 'text/html'})
43
+ got.status.should == 500
44
+ got['Content-Type'].should == 'text/html'
45
+
46
+ doc = Nokogiri::HTML(got.body)
47
+ doc.at("#summary").text.should.match(/NameError at \/raises/)
48
+ doc.at("#explanation").text.strip.should ==
49
+ "You're seeing this error because you use Rack::ShowExceptions."
52
50
  end
53
51
 
54
52
  it 'uses original action_missing when no action was found' do
@@ -78,11 +76,9 @@ describe 'Error handling' do
78
76
  got = get('/empty')
79
77
  [got.status, got['Content-Type']].should == [404, 'text/html']
80
78
 
81
- # we use this xpath notation because otherwise rexml is really slow...
82
- doc = REXML::Document.new(got.body)
83
- REXML::XPath.first(doc, "/html/body/div[1]/h1").text.strip.
84
- should == "Not Found"
85
- REXML::XPath.first(doc, "/html/body/div[3]/p/code").text.
86
- should == "Rack::ShowStatus"
79
+ doc = Nokogiri::HTML(got.body)
80
+ doc.at("#info").text.strip.should == "Not Found"
81
+ doc.at("#explanation").text.strip.should ==
82
+ "You're seeing this error because you use Rack::ShowStatus."
87
83
  end
88
84
  end
@@ -2,7 +2,8 @@
2
2
  # All files in this distribution are subject to the terms of the MIT license.
3
3
 
4
4
  require File.expand_path('../../../../spec/helper', __FILE__)
5
- spec_require 'hpricot'
5
+
6
+ spec_require 'nokogiri'
6
7
 
7
8
  class SpecHelperPaginateArray < Ramaze::Controller
8
9
  map '/array'
@@ -31,6 +32,13 @@ class SpecHelperPaginateArray < Ramaze::Controller
31
32
  pager.each{|item| out << item }
32
33
  out.inspect
33
34
  end
35
+
36
+ def preserve_params
37
+ request.params['single'] = 'zero'
38
+ request.params['multiple'] = %w[ one two three ]
39
+ pager = paginate(ALPHA)
40
+ pager.navigation
41
+ end
34
42
  end
35
43
 
36
44
  describe Ramaze::Helper::Paginate do
@@ -38,8 +46,9 @@ describe Ramaze::Helper::Paginate do
38
46
  behaves_like :rack_test
39
47
 
40
48
  it 'shows navigation for page 1' do
41
- doc = Hpricot(get("/array/navigation").body)
42
- (doc/:a).map{|a| [a.inner_text, a[:href]] }.
49
+ doc = Nokogiri::HTML(get("/array/navigation").body)
50
+
51
+ doc.css('a').map{|a| [a.inner_text, a[:href]] }.
43
52
  should == [
44
53
  ['1', '/array/navigation?pager=1'],
45
54
  ['2', '/array/navigation?pager=2'],
@@ -49,8 +58,9 @@ describe Ramaze::Helper::Paginate do
49
58
  end
50
59
 
51
60
  it 'shows navigation for page 2' do
52
- doc = Hpricot(get("/array/navigation?pager=2").body)
53
- (doc/:a).map{|a| [a.inner_text, a[:href]] }.
61
+ doc = Nokogiri::HTML(get("/array/navigation?pager=2").body)
62
+
63
+ doc.css('a').map{|a| [a.inner_text, a[:href]] }.
54
64
  should == [
55
65
  ['<<', '/array/navigation?pager=1'],
56
66
  ['<', '/array/navigation?pager=1'],
@@ -62,8 +72,8 @@ describe Ramaze::Helper::Paginate do
62
72
  end
63
73
 
64
74
  it 'shows navigation for page 3' do
65
- doc = Hpricot(get("/array/navigation?pager=3").body)
66
- (doc/:a).map{|a| [a.inner_text, a[:href]] }.
75
+ doc = Nokogiri::HTML(get("/array/navigation?pager=3").body)
76
+ doc.css('a').map{|a| [a.inner_text, a[:href]] }.
67
77
  should == [
68
78
  ['<<', '/array/navigation?pager=1'],
69
79
  ['<', '/array/navigation?pager=2'],
@@ -78,7 +88,7 @@ describe Ramaze::Helper::Paginate do
78
88
  end
79
89
 
80
90
  it 'sets default css elements on page 1' do
81
- doc = Hpricot(get('/array/navigation').body)
91
+ doc = Nokogiri::HTML(get('/array/navigation').body)
82
92
  # Paginator outputs spans for disabled elements
83
93
  # Since we're on the first page, the first two
84
94
  # elements are spans, then a's
@@ -109,7 +119,7 @@ describe Ramaze::Helper::Paginate do
109
119
  end
110
120
 
111
121
  it 'sets default css elements on page 2' do
112
- doc = Hpricot(get('/array/navigation?pager=2').body)
122
+ doc = Nokogiri::HTML(get('/array/navigation?pager=2').body)
113
123
  # Paginator outputs spans for disabled elements
114
124
  # Since we're on the second page, none are disabled
115
125
  # Note that this is only valid for the second page since
@@ -140,7 +150,7 @@ describe Ramaze::Helper::Paginate do
140
150
  end
141
151
 
142
152
  it 'sets default css elements on page 3' do
143
- doc = Hpricot(get('/array/navigation?pager=3').body)
153
+ doc = Nokogiri::HTML(get('/array/navigation?pager=3').body)
144
154
  # Paginator outputs spans for disabled elements
145
155
  # Since we're on the last page, last and next will be disabled
146
156
  # Note that this is only valid for the third page
@@ -173,7 +183,7 @@ describe Ramaze::Helper::Paginate do
173
183
  end
174
184
 
175
185
  it 'sets our custom css elements for page 1' do
176
- doc = Hpricot(get('/array/custom_navigation').body)
186
+ doc = Nokogiri::HTML(get('/array/custom_navigation').body)
177
187
  # Paginator outputs spans for disabled elements
178
188
  # Since we're on the first page, the first two
179
189
  # elements are spans, then a's
@@ -209,7 +219,7 @@ describe Ramaze::Helper::Paginate do
209
219
  end
210
220
 
211
221
  it 'sets our custom css elements on page 2' do
212
- doc = Hpricot(get('/array/custom_navigation?pager=2').body)
222
+ doc = Nokogiri::HTML(get('/array/custom_navigation?pager=2').body)
213
223
  # Paginator outputs spans for disabled elements
214
224
  # Since we're on the second page, none are disabled
215
225
  # Note that this is only valid for the second page since
@@ -240,7 +250,7 @@ describe Ramaze::Helper::Paginate do
240
250
  end
241
251
 
242
252
  it 'sets our custom css elements on page 3' do
243
- doc = Hpricot(get('/array/custom_navigation?pager=3').body)
253
+ doc = Nokogiri::HTML(get('/array/custom_navigation?pager=3').body)
244
254
  # Paginator outputs spans for disabled elements
245
255
  # Since we're on the last page, last and next will be disabled
246
256
  # Note that this is only valid for the third page
@@ -272,5 +282,23 @@ describe Ramaze::Helper::Paginate do
272
282
 
273
283
  end
274
284
 
285
+ it 'preserves single value params' do
286
+ doc = Nokogiri::HTML(get("/array/preserve_params").body)
287
+ params = doc.search("//a").first[:href].split('?').last.split('&')
288
+ params.should.include 'single=zero'
289
+ params.should.not.include 'single[]'.escape(:cgi) + '=zero'
290
+ end
291
+
292
+ it 'preserves multi value params' do
293
+ doc = Nokogiri::HTML(get("/array/preserve_params").body)
294
+ params = doc.search("//a").first[:href].split('?').last.split('&')
295
+ params.should.not.include 'multiple=one'
296
+ params.should.not.include 'multiple=two'
297
+ params.should.not.include 'multiple=three'
298
+ params.should.include 'multiple[]'.escape(:cgi) + '=one'
299
+ params.should.include 'multiple[]'.escape(:cgi) + '=two'
300
+ params.should.include 'multiple[]'.escape(:cgi) + '=three'
301
+ end
302
+
275
303
  end
276
304
  end
@@ -4,9 +4,9 @@
4
4
 
5
5
  require File.expand_path('../../../../spec/helper', __FILE__)
6
6
 
7
- spec_precondition 'Syslog should be supported' do
7
+ spec_precondition 'Process.fork should be supported' do
8
8
  if RUBY_DESCRIPTION.include?('jruby')
9
- should.flunk 'Forking/Syslog is not supported'
9
+ should.flunk 'These tests use Process.fork which does not work on jruby'
10
10
  end
11
11
  end
12
12
 
@@ -14,70 +14,82 @@ require 'ramaze/log/syslog'
14
14
 
15
15
  describe 'Syslog' do
16
16
 
17
- # close the syslog, if it was open for some reason before we
18
- # start a test.
19
- before do
20
- if ( Syslog.opened? )
21
- ::Syslog.close
22
- end
23
- end
17
+ # close the syslog, if it was open for some reason before we
18
+ # start a test.
19
+ before do
20
+ Syslog.close if Syslog.opened?
21
+ end
22
+
23
+ it 'should default initialize correctly' do
24
+ syslog = Ramaze::Logger::Syslog.new
25
+ ::Syslog.opened?.should == true
26
+ ::Syslog.ident.should == $0
27
+ ::Syslog.options.should == ( ::Syslog::LOG_PID | ::Syslog::LOG_CONS )
28
+ ::Syslog.facility.should == ::Syslog::LOG_USER
29
+ end
30
+
31
+ it 'should handle non default initialization' do
32
+ syslog = Ramaze::Logger::Syslog.new( 'ramaze_syslog_test',
33
+ ::Syslog::LOG_NDELAY | ::Syslog::LOG_NOWAIT,
34
+ ::Syslog::LOG_DAEMON )
35
+ ::Syslog.opened?.should == true
36
+ ::Syslog.ident.should == 'ramaze_syslog_test'
37
+ ::Syslog.options.should == ( ::Syslog::LOG_NDELAY | ::Syslog::LOG_NOWAIT )
38
+ ::Syslog.facility.should == ::Syslog::LOG_DAEMON
39
+ end
40
+
41
+ # We test the actual logging using a trick found in te test code of the
42
+ # syslog module. We create a pipe, fork a child, reroute the childs
43
+ # stderr to the pipe. Then we open the logging using LOG_PERROR, so all
44
+ # log messages are written to stderror. In the parent we read the messages
45
+ # from the pipe and compare them to what we expected.
46
+ def test_log_msg( type, priority, msg )
47
+ logpipe = IO::pipe
48
+ child = fork {
49
+ logpipe[0].close
50
+ STDERR.reopen(logpipe[1])
51
+ syslog = Ramaze::Logger::Syslog.new( 'ramaze_syslog_test',
52
+ ::Syslog::LOG_PID | ::Syslog::LOG_NDELAY | ::Syslog::LOG_PERROR,
53
+ ::Syslog::LOG_USER )
54
+ syslog.send priority, msg
55
+ Process.exit!( 0 )
56
+ }
57
+ logpipe[1].close
58
+ Process.waitpid(child)
59
+ label = case priority
60
+ # when 'debug', 'info', 'error'
61
+ # priority
62
+ when :dev
63
+ 'debug'
64
+ when :warn
65
+ 'warning'
66
+ else
67
+ priority.to_s
68
+ end
69
+ logpipe[0].gets.slice(/ramaze.*/).should == "ramaze_syslog_test[#{child}] <#{label.capitalize}>: #{msg}"
70
+ end
24
71
 
25
- it 'should default initialize correctly' do
26
- syslog = Ramaze::Logger::Syslog.new
27
- ::Syslog.opened?.should == true
28
- ::Syslog.ident.should == $0
29
- ::Syslog.options.should == ( ::Syslog::LOG_PID | ::Syslog::LOG_CONS )
30
- ::Syslog.facility.should == ::Syslog::LOG_USER
31
- end
72
+ it 'should handle debug' do
73
+ test_log_msg :direct, :debug, "Hello Debug World"
74
+ end
32
75
 
33
- it 'should handle non default initialization' do
34
- syslog = Ramaze::Logger::Syslog.new( 'ramaze_syslog_test',
35
- ::Syslog::LOG_NDELAY | ::Syslog::LOG_NOWAIT,
36
- ::Syslog::LOG_DAEMON )
37
- ::Syslog.opened?.should == true
38
- ::Syslog.ident.should == 'ramaze_syslog_test'
39
- ::Syslog.options.should == ( ::Syslog::LOG_NDELAY | ::Syslog::LOG_NOWAIT )
40
- ::Syslog.facility.should == ::Syslog::LOG_DAEMON
41
- end
76
+ it 'should handle dev' do
77
+ test_log_msg :direct, :dev, "Hello Dev World"
78
+ end
42
79
 
43
- # We test the actual logging using a trick found in te test code of the
44
- # syslog module. We create a pipe, fork a child, reroute the childs
45
- # stderr to the pipe. Then we open the logging using LOG_PERROR, so all
46
- # log messages are written to stderror. In the parent we read the messages
47
- # from the pipe and compare them to what we expected.
48
- def test_log_msg( type, priority, msg )
49
- logpipe = IO::pipe
50
- child = fork {
51
- logpipe[0].close
52
- STDERR.reopen(logpipe[1])
53
- syslog = Ramaze::Logger::Syslog.new( 'ramaze_syslog_test',
54
- ::Syslog::LOG_PID | ::Syslog::LOG_NDELAY | ::Syslog::LOG_PERROR,
55
- ::Syslog::LOG_USER )
56
- syslog.send priority, msg
57
- Process.exit!( 0 )
58
- }
59
- logpipe[1].close
60
- Process.waitpid(child)
80
+ it 'should handle info' do
81
+ test_log_msg :direct, :info, 'Hello Info World!'
82
+ end
61
83
 
62
- logpipe[0].gets.should == "ramaze_syslog_test[#{child}]: #{msg}\n"
63
- end
84
+ it 'should handle warn' do
85
+ test_log_msg :direct, :warn, 'Hello Warn World!'
86
+ end
64
87
 
65
- it 'should handle debug' do
66
- test_log_msg :direct, :debug, "Hello Debug World"
67
- end
68
- it 'should handle dev' do
69
- test_log_msg :direct, :dev, "Hello Dev World"
70
- end
71
- it 'should handle info' do
72
- test_log_msg :direct, :info, 'Hello Info World!'
73
- end
74
- it 'should handle warn' do
75
- test_log_msg :direct, :warn, 'Hello Warn World!'
76
- end
77
- it 'should handle error' do
78
- test_log_msg :direct, :error, 'Hello Error World!'
79
- end
80
- it 'should escape % sequences' do
81
- test_log_msg :direct, :info, "Hello Cruel |évil| 戈 REAL %s World"
82
- end
88
+ it 'should handle error' do
89
+ test_log_msg :direct, :error, 'Hello Error World!'
90
+ end
91
+
92
+ it 'should escape % sequences' do
93
+ test_log_msg :direct, :info, "Hello Cruel |évil| 戈 REAL %s World"
94
+ end
83
95
  end
@@ -2,8 +2,8 @@ require File.expand_path('../../../../spec/helper', __FILE__)
2
2
  spec_require 'redis'
3
3
 
4
4
  spec_precondition 'Redis is running' do
5
- cache = Redis.new
6
- cache['active'] = true
5
+ cache = Redis.new
6
+ "OK" == cache.set('testkey', 'testval')
7
7
  end
8
8
 
9
9
  class SpecSession < Ramaze::Controller
@@ -1,4 +1,6 @@
1
1
  require File.expand_path('../../../../spec/helper', __FILE__)
2
+
3
+ spec_require 'sqlite3'
2
4
  spec_require 'sequel'
3
5
 
4
6
  class SpecSession < Ramaze::Controller
@@ -72,7 +72,7 @@ describe Ramaze::View::Haml do
72
72
  <li>
73
73
  <a href='/external'>External template</a>
74
74
  </li>
75
- </ul>"
75
+ </ul>".gsub(/\n\s+/, "\n")
76
76
  end
77
77
 
78
78
  should 'render external template' do
@@ -87,7 +87,7 @@ describe Ramaze::View::Haml do
87
87
  <body>
88
88
  <h1>Haml Template</h1>
89
89
  </body>
90
- </html>"
90
+ </html>".gsub(/\n\s+/, "\n")
91
91
  end
92
92
 
93
93
  should 'render external template with instance variables' do
@@ -97,7 +97,7 @@ describe Ramaze::View::Haml do
97
97
  got.body.strip.should ==
98
98
  "<div>
99
99
  3
100
- </div>"
100
+ </div>".gsub(/\n\s+/, "\n")
101
101
  end
102
102
 
103
103
  should 'render the wrapped view twice even with caching' do
@@ -39,7 +39,7 @@ describe 'Ramaze::View::Slim' do
39
39
  end
40
40
 
41
41
  should 'render an external template with variables' do
42
- got = get('/external')
42
+ got = get('/external_vars')
43
43
 
44
44
  got.status.should == 200
45
45
  got['Content-Type'].should == 'text/html'