padrino-core 0.16.0.pre4 → 0.16.0
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.
- checksums.yaml +4 -4
- data/README.rdoc +8 -8
- data/Rakefile +1 -1
- data/bin/padrino +1 -1
- data/lib/padrino-core/application/application_setup.rb +28 -26
- data/lib/padrino-core/application/authenticity_token.rb +3 -2
- data/lib/padrino-core/application/flash.rb +4 -5
- data/lib/padrino-core/application/params_protection.rb +34 -37
- data/lib/padrino-core/application/routing.rb +165 -164
- data/lib/padrino-core/application/show_exceptions.rb +5 -7
- data/lib/padrino-core/application.rb +4 -4
- data/lib/padrino-core/caller.rb +6 -7
- data/lib/padrino-core/cli/adapter.rb +4 -4
- data/lib/padrino-core/cli/base.rb +31 -32
- data/lib/padrino-core/cli/binstub.rb +9 -8
- data/lib/padrino-core/cli/console.rb +1 -1
- data/lib/padrino-core/cli/launcher.rb +45 -42
- data/lib/padrino-core/cli/rake.rb +16 -14
- data/lib/padrino-core/cli/rake_tasks.rb +18 -20
- data/lib/padrino-core/command.rb +1 -1
- data/lib/padrino-core/ext/sinatra.rb +3 -2
- data/lib/padrino-core/filter.rb +3 -3
- data/lib/padrino-core/loader.rb +10 -12
- data/lib/padrino-core/logger.rb +85 -77
- data/lib/padrino-core/mounter/application_extension.rb +2 -2
- data/lib/padrino-core/mounter.rb +33 -34
- data/lib/padrino-core/path_router/compiler.rb +8 -8
- data/lib/padrino-core/path_router/matcher.rb +11 -11
- data/lib/padrino-core/path_router/route.rb +15 -15
- data/lib/padrino-core/path_router.rb +4 -3
- data/lib/padrino-core/reloader/rack.rb +1 -1
- data/lib/padrino-core/reloader/storage.rb +12 -11
- data/lib/padrino-core/reloader.rb +18 -19
- data/lib/padrino-core/router.rb +14 -14
- data/lib/padrino-core/server.rb +20 -24
- data/lib/padrino-core/tasks.rb +0 -1
- data/lib/padrino-core/version.rb +1 -1
- data/lib/padrino-core.rb +9 -10
- data/padrino-core.gemspec +18 -18
- data/test/fixtures/app_gem/app_gem.gemspec +8 -7
- data/test/fixtures/app_gem/lib/app_gem/version.rb +1 -1
- data/test/fixtures/apps/complex.rb +6 -6
- data/test/fixtures/apps/concerned/app.rb +1 -1
- data/test/fixtures/apps/custom_dependencies/custom_dependencies.rb +3 -3
- data/test/fixtures/apps/demo_app.rb +1 -1
- data/test/fixtures/apps/demo_demo.rb +1 -1
- data/test/fixtures/apps/demo_project/api/app.rb +1 -1
- data/test/fixtures/apps/demo_project/app.rb +1 -1
- data/test/fixtures/apps/helpers/class_methods_helpers.rb +1 -0
- data/test/fixtures/apps/helpers/instance_methods_helpers.rb +1 -0
- data/test/fixtures/apps/helpers/system_helpers.rb +0 -1
- data/test/fixtures/apps/lib/myklass/mysubklass.rb +2 -2
- data/test/fixtures/apps/mountable_apps/rack_apps.rb +7 -7
- data/test/fixtures/apps/precompiled_app.rb +6 -5
- data/test/fixtures/apps/simple.rb +5 -5
- data/test/fixtures/apps/static.rb +2 -2
- data/test/fixtures/apps/stealthy/app.rb +1 -1
- data/test/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb +1 -1
- data/test/fixtures/apps/system.rb +1 -1
- data/test/fixtures/apps/system_class_methods_demo.rb +1 -1
- data/test/fixtures/apps/system_instance_methods_demo.rb +1 -1
- data/test/fixtures/dependencies/a.rb +1 -1
- data/test/fixtures/dependencies/b.rb +1 -1
- data/test/fixtures/dependencies/c.rb +1 -1
- data/test/fixtures/dependencies/circular/e.rb +2 -1
- data/test/fixtures/dependencies/d.rb +1 -1
- data/test/fixtures/dependencies/linear/i.rb +1 -1
- data/test/fixtures/dependencies/nested/l.rb +2 -2
- data/test/fixtures/dependencies/nested/m.rb +1 -1
- data/test/fixtures/dependencies/nested/qqq.rb +2 -2
- data/test/fixtures/dependencies/nested/rrr.rb +1 -1
- data/test/fixtures/dependencies/nested/sss.rb +1 -1
- data/test/fixtures/reloadable_apps/external/app/app.rb +0 -1
- data/test/fixtures/reloadable_apps/external/app/controllers/base.rb +1 -2
- data/test/fixtures/reloadable_apps/main/app.rb +2 -2
- data/test/helper.rb +2 -2
- data/test/test_application.rb +59 -60
- data/test/test_configuration.rb +2 -2
- data/test/test_core.rb +13 -13
- data/test/test_csrf_protection.rb +67 -63
- data/test/test_dependencies.rb +33 -34
- data/test/test_filters.rb +46 -47
- data/test/test_flash.rb +14 -14
- data/test/test_locale.rb +2 -2
- data/test/test_logger.rb +64 -64
- data/test/test_mounter.rb +133 -123
- data/test/test_params_protection.rb +40 -40
- data/test/test_reloader_complex.rb +23 -23
- data/test/test_reloader_external.rb +10 -10
- data/test/test_reloader_simple.rb +26 -23
- data/test/test_reloader_storage.rb +9 -12
- data/test/test_reloader_system.rb +29 -29
- data/test/test_restful_routing.rb +19 -19
- data/test/test_router.rb +126 -145
- data/test/test_routing.rb +882 -894
- metadata +6 -6
data/test/test_filters.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe 'Filters' do
|
|
4
4
|
it 'should filters by accept header' do
|
|
5
5
|
mock_app do
|
|
6
|
-
get '/foo', :
|
|
6
|
+
get '/foo', provides: %i[xml js] do
|
|
7
7
|
request.env['HTTP_ACCEPT']
|
|
8
8
|
end
|
|
9
9
|
end
|
|
@@ -26,7 +26,7 @@ describe "Filters" do
|
|
|
26
26
|
assert ok?
|
|
27
27
|
assert_equal 'text/javascript;charset=utf-8', response.headers['Content-Type']
|
|
28
28
|
|
|
29
|
-
get '/foo', {}, {
|
|
29
|
+
get '/foo', {}, { 'HTTP_ACCEPT' => 'text/html' }
|
|
30
30
|
assert_equal 406, status
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -35,27 +35,27 @@ describe "Filters" do
|
|
|
35
35
|
controller do
|
|
36
36
|
before { env['QUERY_STRING'] == 'secret' or pass }
|
|
37
37
|
get :index do
|
|
38
|
-
|
|
38
|
+
'secret index'
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
controller do
|
|
43
43
|
before { env['QUERY_STRING'] == 'halt' and halt 401, 'go away!' }
|
|
44
44
|
get :index do
|
|
45
|
-
|
|
45
|
+
'index'
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
get
|
|
51
|
-
assert_equal
|
|
50
|
+
get '/?secret'
|
|
51
|
+
assert_equal 'secret index', body
|
|
52
52
|
|
|
53
|
-
get
|
|
54
|
-
assert_equal
|
|
53
|
+
get '/?halt'
|
|
54
|
+
assert_equal 'go away!', body
|
|
55
55
|
assert_equal 401, status
|
|
56
56
|
|
|
57
|
-
get
|
|
58
|
-
assert_equal
|
|
57
|
+
get '/'
|
|
58
|
+
assert_equal 'index', body
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
it 'should scope filters in the given controller' do
|
|
@@ -66,26 +66,26 @@ describe "Filters" do
|
|
|
66
66
|
controller :foo do
|
|
67
67
|
before { @foo = :foo }
|
|
68
68
|
after { @foo = nil }
|
|
69
|
-
get(
|
|
69
|
+
get('/') { [@foo, @bar, @global].compact.join(' ') }
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
-
get(
|
|
72
|
+
get('/') { [@foo, @bar, @global].compact.join(' ') }
|
|
73
73
|
|
|
74
74
|
controller :bar do
|
|
75
75
|
before { @bar = :bar }
|
|
76
76
|
after { @bar = nil }
|
|
77
|
-
get(
|
|
77
|
+
get('/') { [@foo, @bar, @global].compact.join(' ') }
|
|
78
78
|
end
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
-
get
|
|
82
|
-
assert_equal
|
|
81
|
+
get '/bar'
|
|
82
|
+
assert_equal 'bar global', body
|
|
83
83
|
|
|
84
|
-
get
|
|
85
|
-
assert_equal
|
|
84
|
+
get '/foo'
|
|
85
|
+
assert_equal 'foo global', body
|
|
86
86
|
|
|
87
|
-
get
|
|
88
|
-
assert_equal
|
|
87
|
+
get '/'
|
|
88
|
+
assert_equal 'global', body
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
it 'should be able to access params in a before filter' do
|
|
@@ -96,7 +96,7 @@ describe "Filters" do
|
|
|
96
96
|
username_from_before_filter = params[:username]
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
-
get :users, :
|
|
99
|
+
get :users, with: :username do
|
|
100
100
|
end
|
|
101
101
|
end
|
|
102
102
|
get '/users/josh'
|
|
@@ -105,7 +105,7 @@ describe "Filters" do
|
|
|
105
105
|
|
|
106
106
|
it 'should be able to access params normally when a before filter is specified' do
|
|
107
107
|
mock_app do
|
|
108
|
-
before {
|
|
108
|
+
before {}
|
|
109
109
|
get :index do
|
|
110
110
|
params.to_json
|
|
111
111
|
end
|
|
@@ -116,7 +116,7 @@ describe "Filters" do
|
|
|
116
116
|
|
|
117
117
|
it 'should be able to filter based on a path' do
|
|
118
118
|
mock_app do
|
|
119
|
-
before('/') { @test = "#{@test}before"}
|
|
119
|
+
before('/') { @test = "#{@test}before" }
|
|
120
120
|
get :index do
|
|
121
121
|
@test
|
|
122
122
|
end
|
|
@@ -132,7 +132,7 @@ describe "Filters" do
|
|
|
132
132
|
|
|
133
133
|
it 'should be able to filter based on a symbol' do
|
|
134
134
|
mock_app do
|
|
135
|
-
before(:index) { @test = 'before'}
|
|
135
|
+
before(:index) { @test = 'before' }
|
|
136
136
|
get :index do
|
|
137
137
|
@test
|
|
138
138
|
end
|
|
@@ -149,27 +149,26 @@ describe "Filters" do
|
|
|
149
149
|
it 'should be able to filter based on a symbol for a controller' do
|
|
150
150
|
mock_app do
|
|
151
151
|
controller :foo do
|
|
152
|
-
before(:test) { @test = 'foo'}
|
|
153
|
-
get
|
|
154
|
-
@test.to_s + " response"
|
|
155
|
-
end
|
|
152
|
+
before(:test) { @test = 'foo' }
|
|
153
|
+
get(:test) { "#{@test} response" }
|
|
156
154
|
end
|
|
155
|
+
|
|
157
156
|
controller :bar do
|
|
158
|
-
before(:test) { @test = 'bar'}
|
|
159
|
-
get
|
|
160
|
-
@test.to_s + " response"
|
|
161
|
-
end
|
|
157
|
+
before(:test) { @test = 'bar' }
|
|
158
|
+
get(:test) { "#{@test} response" }
|
|
162
159
|
end
|
|
163
160
|
end
|
|
161
|
+
|
|
164
162
|
get '/foo/test'
|
|
165
163
|
assert_equal 'foo response', body
|
|
164
|
+
|
|
166
165
|
get '/bar/test'
|
|
167
166
|
assert_equal 'bar response', body
|
|
168
167
|
end
|
|
169
168
|
|
|
170
169
|
it 'should be able to filter based on a symbol or path' do
|
|
171
170
|
mock_app do
|
|
172
|
-
before(:index, '/main') { @test = 'before'}
|
|
171
|
+
before(:index, '/main') { @test = 'before' }
|
|
173
172
|
get :index do
|
|
174
173
|
@test
|
|
175
174
|
end
|
|
@@ -185,7 +184,7 @@ describe "Filters" do
|
|
|
185
184
|
|
|
186
185
|
it 'should be able to filter based on a symbol or regexp' do
|
|
187
186
|
mock_app do
|
|
188
|
-
before(:index, /main/) { @test = 'before'}
|
|
187
|
+
before(:index, /main/) { @test = 'before' }
|
|
189
188
|
get :index do
|
|
190
189
|
@test
|
|
191
190
|
end
|
|
@@ -206,7 +205,7 @@ describe "Filters" do
|
|
|
206
205
|
|
|
207
206
|
it 'should be able to filter excluding based on a symbol' do
|
|
208
207
|
mock_app do
|
|
209
|
-
before(:
|
|
208
|
+
before(except: :index) { @test = 'before' }
|
|
210
209
|
get :index do
|
|
211
210
|
@test
|
|
212
211
|
end
|
|
@@ -223,8 +222,8 @@ describe "Filters" do
|
|
|
223
222
|
it 'should be able to filter excluding based on a symbol when specify the multiple routes and use nested controller' do
|
|
224
223
|
mock_app do
|
|
225
224
|
controller :test, :nested do
|
|
226
|
-
before(:
|
|
227
|
-
before(:
|
|
225
|
+
before(except: %i[test1 test2]) { @long = 'long' }
|
|
226
|
+
before(except: [:test1]) { @short = 'short' }
|
|
228
227
|
get :test1 do
|
|
229
228
|
"#{@long} #{@short} normal"
|
|
230
229
|
end
|
|
@@ -246,14 +245,14 @@ describe "Filters" do
|
|
|
246
245
|
|
|
247
246
|
it 'should be able to filter based on a request param' do
|
|
248
247
|
mock_app do
|
|
249
|
-
before(:
|
|
248
|
+
before(agent: /IE/) { @test = 'before' }
|
|
250
249
|
get :index do
|
|
251
250
|
@test
|
|
252
251
|
end
|
|
253
252
|
end
|
|
254
253
|
get '/'
|
|
255
254
|
assert_equal '', body
|
|
256
|
-
get
|
|
255
|
+
get '/', {}, { 'HTTP_USER_AGENT' => 'This is IE' }
|
|
257
256
|
assert_equal 'before', body
|
|
258
257
|
end
|
|
259
258
|
|
|
@@ -343,7 +342,7 @@ describe "Filters" do
|
|
|
343
342
|
doodle = 'Been after'
|
|
344
343
|
end
|
|
345
344
|
before do
|
|
346
|
-
raise StandardError,
|
|
345
|
+
raise StandardError, 'before'
|
|
347
346
|
end
|
|
348
347
|
get :index do
|
|
349
348
|
doodle = 'Been now'
|
|
@@ -363,11 +362,11 @@ describe "Filters" do
|
|
|
363
362
|
mock_app do
|
|
364
363
|
after do
|
|
365
364
|
doodle += ' and after'
|
|
366
|
-
raise StandardError,
|
|
365
|
+
raise StandardError, 'after'
|
|
367
366
|
end
|
|
368
367
|
get :foo do
|
|
369
368
|
doodle = 'Been now'
|
|
370
|
-
raise StandardError,
|
|
369
|
+
raise StandardError, 'now'
|
|
371
370
|
end
|
|
372
371
|
get :index do
|
|
373
372
|
doodle = 'Been now'
|
|
@@ -389,12 +388,12 @@ describe "Filters" do
|
|
|
389
388
|
|
|
390
389
|
it 'should trigger filters if superclass responds to :filters' do
|
|
391
390
|
class FilterApp < Padrino::Application
|
|
392
|
-
before { @foo =
|
|
391
|
+
before { @foo = 'foo' }
|
|
393
392
|
end
|
|
394
393
|
mock_app FilterApp do
|
|
395
|
-
get(
|
|
394
|
+
get('/') { @foo }
|
|
396
395
|
end
|
|
397
|
-
get
|
|
398
|
-
assert_equal
|
|
396
|
+
get '/'
|
|
397
|
+
assert_equal 'foo', body
|
|
399
398
|
end
|
|
400
399
|
end
|
data/test/test_flash.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
2
|
|
|
3
3
|
describe Padrino::Flash do
|
|
4
4
|
describe 'storage' do
|
|
5
5
|
before do
|
|
6
6
|
@storage = Padrino::Flash::Storage.new(
|
|
7
|
-
:
|
|
8
|
-
:
|
|
9
|
-
:
|
|
10
|
-
:
|
|
7
|
+
success: 'Success msg',
|
|
8
|
+
error: 'Error msg',
|
|
9
|
+
notice: 'Notice msg',
|
|
10
|
+
custom: 'Custom msg'
|
|
11
11
|
)
|
|
12
12
|
@storage[:one] = 'One msg'
|
|
13
13
|
@storage[:two] = 'Two msg'
|
|
@@ -72,7 +72,7 @@ describe Padrino::Flash do
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
post :index do
|
|
75
|
-
params.each { |k,v| flash[k.to_sym] = v.to_s }
|
|
75
|
+
params.each { |k, v| flash[k.to_sym] = v.to_s }
|
|
76
76
|
flash.next.to_json
|
|
77
77
|
end
|
|
78
78
|
|
|
@@ -81,7 +81,7 @@ describe Padrino::Flash do
|
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
get :redirect do
|
|
84
|
-
redirect url(:index, :
|
|
84
|
+
redirect url(:index, key: :foo), 301, foo: 'redirected!'
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
get :success do
|
|
@@ -106,7 +106,7 @@ describe Padrino::Flash do
|
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
it 'should set a flash' do
|
|
109
|
-
post '/', :
|
|
109
|
+
post '/', foo: :bar
|
|
110
110
|
assert_equal '{"foo":"bar"}', body
|
|
111
111
|
end
|
|
112
112
|
end
|
|
@@ -128,13 +128,13 @@ describe Padrino::Flash do
|
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
it 'should set a flash' do
|
|
131
|
-
post '/', :
|
|
131
|
+
post '/', foo: :bar
|
|
132
132
|
assert_equal '{"foo":"bar"}', body
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
it 'should get a flash' do
|
|
136
|
-
post '/', :
|
|
137
|
-
get '/', :
|
|
136
|
+
post '/', foo: :bar
|
|
137
|
+
get '/', key: :foo
|
|
138
138
|
assert_equal 'bar', body
|
|
139
139
|
post '/'
|
|
140
140
|
assert_equal '{}', body
|
|
@@ -149,19 +149,19 @@ describe Padrino::Flash do
|
|
|
149
149
|
|
|
150
150
|
it 'should set success' do
|
|
151
151
|
get '/success'
|
|
152
|
-
get '/', :
|
|
152
|
+
get '/', key: :success
|
|
153
153
|
assert_equal 'Yup', body
|
|
154
154
|
end
|
|
155
155
|
|
|
156
156
|
it 'should set error' do
|
|
157
157
|
get '/error'
|
|
158
|
-
get '/', :
|
|
158
|
+
get '/', key: :error
|
|
159
159
|
assert_equal 'Arg', body
|
|
160
160
|
end
|
|
161
161
|
|
|
162
162
|
it 'should set notice' do
|
|
163
163
|
get '/notice'
|
|
164
|
-
get '/', :
|
|
164
|
+
get '/', key: :notice
|
|
165
165
|
assert_equal 'Mmm', body
|
|
166
166
|
end
|
|
167
167
|
end
|
data/test/test_locale.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe 'Locales' do
|
|
4
4
|
Dir[File.expand_path('../lib/padrino-core/locale/*.yml', __dir__)].each do |file|
|
|
5
5
|
base_original = YAML.load_file(file)
|
|
6
6
|
name = File.basename(file, '.yml')
|
data/test/test_logger.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#coding:utf-8
|
|
2
|
-
|
|
1
|
+
# coding:utf-8
|
|
2
|
+
require_relative 'helper'
|
|
3
3
|
require 'logger'
|
|
4
4
|
require 'tempfile'
|
|
5
5
|
|
|
6
|
-
describe
|
|
6
|
+
describe 'PadrinoLogger' do
|
|
7
7
|
before do
|
|
8
8
|
@save_config = Padrino::Logger::Config[:test].dup
|
|
9
9
|
Padrino::Logger::Config[:test][:stream] = :null
|
|
@@ -15,9 +15,9 @@ describe "PadrinoLogger" do
|
|
|
15
15
|
Padrino::Logger.setup!
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def setup_logger(options={})
|
|
18
|
+
def setup_logger(options = {})
|
|
19
19
|
@log = StringIO.new
|
|
20
|
-
@logger = Padrino::Logger.new(options.merge(:
|
|
20
|
+
@logger = Padrino::Logger.new(options.merge(stream: @log))
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
describe 'for logger functionality' do
|
|
@@ -63,27 +63,27 @@ describe "PadrinoLogger" do
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it 'should log something' do
|
|
66
|
-
setup_logger(:
|
|
67
|
-
@logger.error
|
|
66
|
+
setup_logger(log_level: :error)
|
|
67
|
+
@logger.error 'You log this error?'
|
|
68
68
|
assert_match(/You log this error?/, @log.string)
|
|
69
69
|
@logger.debug "You don't log this error!"
|
|
70
70
|
refute_match(/You don't log this error!/, @log.string)
|
|
71
|
-
@logger <<
|
|
71
|
+
@logger << 'Yep this can be logged'
|
|
72
72
|
assert_match(/Yep this can be logged/, @log.string)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it 'should respond to #write for Rack::CommonLogger' do
|
|
76
|
-
setup_logger(:
|
|
77
|
-
@logger.error
|
|
76
|
+
setup_logger(log_level: :error)
|
|
77
|
+
@logger.error 'Error message'
|
|
78
78
|
assert_match(/Error message/, @log.string)
|
|
79
|
-
@logger <<
|
|
79
|
+
@logger << 'logged anyways'
|
|
80
80
|
assert_match(/logged anyways/, @log.string)
|
|
81
|
-
@logger.write
|
|
81
|
+
@logger.write 'log via alias'
|
|
82
82
|
assert_match(/log via alias/, @log.string)
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
it 'should not blow up on mixed or broken encodings' do
|
|
86
|
-
setup_logger(:
|
|
86
|
+
setup_logger(log_level: :error, auto_flush: false)
|
|
87
87
|
binary_data = "\xD0".force_encoding('BINARY')
|
|
88
88
|
utf8_data = 'фыв'
|
|
89
89
|
@logger.error binary_data
|
|
@@ -95,7 +95,7 @@ describe "PadrinoLogger" do
|
|
|
95
95
|
|
|
96
96
|
it 'should sanitize mixed or broken encodings if said so' do
|
|
97
97
|
encoding = 'windows-1251'
|
|
98
|
-
setup_logger(:
|
|
98
|
+
setup_logger(log_level: :error, auto_flush: false, sanitize_encoding: encoding)
|
|
99
99
|
@log.string.encode! encoding
|
|
100
100
|
binary_data = "\xD0".force_encoding('BINARY')
|
|
101
101
|
utf8_data = 'фыв'
|
|
@@ -108,71 +108,71 @@ describe "PadrinoLogger" do
|
|
|
108
108
|
it 'should log an application' do
|
|
109
109
|
mock_app do
|
|
110
110
|
enable :logging
|
|
111
|
-
get(
|
|
111
|
+
get('/') { 'Foo' }
|
|
112
112
|
end
|
|
113
|
-
get
|
|
114
|
-
assert_equal
|
|
113
|
+
get '/'
|
|
114
|
+
assert_equal 'Foo', body
|
|
115
115
|
assert_match(/GET/, Padrino.logger.log.string)
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
it 'should log an application\'s status code' do
|
|
119
119
|
mock_app do
|
|
120
120
|
enable :logging
|
|
121
|
-
get(
|
|
121
|
+
get('/') { 'Foo' }
|
|
122
122
|
end
|
|
123
|
-
get
|
|
123
|
+
get '/'
|
|
124
124
|
assert_match(/\e\[1;9m200\e\[0m OK/, Padrino.logger.log.string)
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
-
describe
|
|
127
|
+
describe 'static asset logging' do
|
|
128
128
|
it 'should not log static assets by default' do
|
|
129
129
|
mock_app do
|
|
130
130
|
enable :logging
|
|
131
|
-
get(
|
|
131
|
+
get('/images/something.png') { env['sinatra.static_file'] = '/public/images/something.png'; 'Foo' }
|
|
132
132
|
end
|
|
133
|
-
get
|
|
134
|
-
assert_equal
|
|
135
|
-
assert_match
|
|
133
|
+
get '/images/something.png'
|
|
134
|
+
assert_equal 'Foo', body
|
|
135
|
+
assert_match '', Padrino.logger.log.string
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
it 'should allow turning on static assets logging' do
|
|
139
|
-
Padrino.logger.instance_eval{ @log_static = true }
|
|
139
|
+
Padrino.logger.instance_eval { @log_static = true }
|
|
140
140
|
mock_app do
|
|
141
141
|
enable :logging
|
|
142
|
-
get(
|
|
142
|
+
get('/images/something.png') { env['sinatra.static_file'] = '/public/images/something.png'; 'Foo' }
|
|
143
143
|
end
|
|
144
|
-
get
|
|
145
|
-
assert_equal
|
|
144
|
+
get '/images/something.png'
|
|
145
|
+
assert_equal 'Foo', body
|
|
146
146
|
assert_match(/GET/, Padrino.logger.log.string)
|
|
147
|
-
Padrino.logger.instance_eval{ @log_static = false }
|
|
147
|
+
Padrino.logger.instance_eval { @log_static = false }
|
|
148
148
|
end
|
|
149
149
|
end
|
|
150
150
|
|
|
151
|
-
describe
|
|
151
|
+
describe 'health-check requests logging' do
|
|
152
152
|
def access_to_mock_app
|
|
153
153
|
mock_app do
|
|
154
154
|
enable :logging
|
|
155
|
-
get(
|
|
155
|
+
get('/') { 'Foo' }
|
|
156
156
|
end
|
|
157
|
-
get
|
|
157
|
+
get '/'
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
it 'should output under debug level' do
|
|
161
|
-
Padrino.logger.instance_eval{ @level = Padrino::Logger::Levels[:debug] }
|
|
161
|
+
Padrino.logger.instance_eval { @level = Padrino::Logger::Levels[:debug] }
|
|
162
162
|
access_to_mock_app
|
|
163
163
|
assert_match(/\e\[0;36m DEBUG\e\[0m/, Padrino.logger.log.string)
|
|
164
164
|
|
|
165
|
-
Padrino.logger.instance_eval{ @level = Padrino::Logger::Levels[:devel] }
|
|
165
|
+
Padrino.logger.instance_eval { @level = Padrino::Logger::Levels[:devel] }
|
|
166
166
|
access_to_mock_app
|
|
167
167
|
assert_match(/\e\[0;36m DEBUG\e\[0m/, Padrino.logger.log.string)
|
|
168
168
|
end
|
|
169
169
|
|
|
170
170
|
it 'should not output over debug level' do
|
|
171
|
-
Padrino.logger.instance_eval{ @level = Padrino::Logger::Levels[:info] }
|
|
171
|
+
Padrino.logger.instance_eval { @level = Padrino::Logger::Levels[:info] }
|
|
172
172
|
access_to_mock_app
|
|
173
173
|
assert_equal '', Padrino.logger.log.string
|
|
174
174
|
|
|
175
|
-
Padrino.logger.instance_eval{ @level = Padrino::Logger::Levels[:error] }
|
|
175
|
+
Padrino.logger.instance_eval { @level = Padrino::Logger::Levels[:error] }
|
|
176
176
|
access_to_mock_app
|
|
177
177
|
assert_equal '', Padrino.logger.log.string
|
|
178
178
|
end
|
|
@@ -180,13 +180,15 @@ describe "PadrinoLogger" do
|
|
|
180
180
|
end
|
|
181
181
|
end
|
|
182
182
|
|
|
183
|
-
describe
|
|
183
|
+
describe 'alternate logger' do
|
|
184
184
|
class FancyLogger
|
|
185
185
|
attr_accessor :level, :log
|
|
186
|
+
|
|
186
187
|
def initialize(buf)
|
|
187
188
|
self.log = buf
|
|
188
189
|
self.level = 0
|
|
189
190
|
end
|
|
191
|
+
|
|
190
192
|
def add(level, text)
|
|
191
193
|
self.log << text
|
|
192
194
|
end
|
|
@@ -205,7 +207,7 @@ describe "alternate logger" do
|
|
|
205
207
|
end
|
|
206
208
|
|
|
207
209
|
it 'should annotate the logger to support additional Padrino fancyness' do
|
|
208
|
-
Padrino.logger.debug(
|
|
210
|
+
Padrino.logger.debug('Debug message')
|
|
209
211
|
assert_match(/Debug message/, @log.string)
|
|
210
212
|
Padrino.logger.exception(Exception.new('scary message'))
|
|
211
213
|
assert_match(/Exception - scary message/, @log.string)
|
|
@@ -216,22 +218,20 @@ describe "alternate logger" do
|
|
|
216
218
|
|
|
217
219
|
mock_app do
|
|
218
220
|
enable :logging
|
|
219
|
-
get(
|
|
221
|
+
get('/') { 'Foo' }
|
|
220
222
|
end
|
|
221
|
-
get
|
|
223
|
+
get '/'
|
|
222
224
|
|
|
223
225
|
assert_match(/\e\[1;9m200\e\[0m OK/, @log.string)
|
|
224
226
|
end
|
|
225
227
|
end
|
|
226
228
|
|
|
227
|
-
describe
|
|
229
|
+
describe 'binary logger' do
|
|
228
230
|
before do
|
|
229
231
|
@save_logger = Padrino.logger
|
|
230
232
|
@log = StringIO.new
|
|
231
233
|
new_logger = Logger.new(@log)
|
|
232
|
-
new_logger.formatter = proc
|
|
233
|
-
"#{message.size}"
|
|
234
|
-
end
|
|
234
|
+
new_logger.formatter = proc { |_, _, _, message| message.size.to_s }
|
|
235
235
|
capture_io { Padrino.logger = new_logger }
|
|
236
236
|
end
|
|
237
237
|
|
|
@@ -240,12 +240,12 @@ describe "binary logger" do
|
|
|
240
240
|
end
|
|
241
241
|
|
|
242
242
|
it 'should not convert parameters to strings before formatting' do
|
|
243
|
-
logger.info({:
|
|
244
|
-
assert_equal
|
|
243
|
+
logger.info({ a: 2 })
|
|
244
|
+
assert_equal '1', @log.string
|
|
245
245
|
end
|
|
246
246
|
end
|
|
247
247
|
|
|
248
|
-
describe
|
|
248
|
+
describe 'alternate logger: stdlib logger' do
|
|
249
249
|
before do
|
|
250
250
|
@log = StringIO.new
|
|
251
251
|
@save_logger = Padrino.logger
|
|
@@ -259,7 +259,7 @@ describe "alternate logger: stdlib logger" do
|
|
|
259
259
|
end
|
|
260
260
|
|
|
261
261
|
it 'should annotate the logger to support additional Padrino fancyness' do
|
|
262
|
-
Padrino.logger.debug(
|
|
262
|
+
Padrino.logger.debug('Debug message')
|
|
263
263
|
assert_match(/Debug message/, @log.string)
|
|
264
264
|
end
|
|
265
265
|
|
|
@@ -268,21 +268,21 @@ describe "alternate logger: stdlib logger" do
|
|
|
268
268
|
|
|
269
269
|
mock_app do
|
|
270
270
|
enable :logging
|
|
271
|
-
get(
|
|
271
|
+
get('/') { 'Foo' }
|
|
272
272
|
end
|
|
273
|
-
get
|
|
273
|
+
get '/'
|
|
274
274
|
|
|
275
275
|
assert_match(/\e\[1;9m200\e\[0m OK/, @log.string)
|
|
276
276
|
end
|
|
277
277
|
end
|
|
278
278
|
|
|
279
|
-
describe
|
|
279
|
+
describe 'options :colorize_logging' do
|
|
280
280
|
def access_to_mock_app
|
|
281
281
|
mock_app do
|
|
282
282
|
enable :logging
|
|
283
|
-
get(
|
|
283
|
+
get('/') { 'Foo' }
|
|
284
284
|
end
|
|
285
|
-
get
|
|
285
|
+
get '/'
|
|
286
286
|
end
|
|
287
287
|
|
|
288
288
|
before do
|
|
@@ -321,46 +321,46 @@ describe "options :colorize_logging" do
|
|
|
321
321
|
end
|
|
322
322
|
end
|
|
323
323
|
|
|
324
|
-
describe
|
|
324
|
+
describe 'options :source_location' do
|
|
325
325
|
before do
|
|
326
326
|
Padrino::Logger::Config[:test][:source_location] = true
|
|
327
327
|
Padrino::Logger.setup!
|
|
328
328
|
end
|
|
329
329
|
|
|
330
|
-
def stub_root(base_path = File.expand_path(
|
|
331
|
-
callable = proc{ |*args| File.join(base_path, *args) }
|
|
330
|
+
def stub_root(base_path = File.expand_path('.'), &block)
|
|
331
|
+
callable = proc { |*args| File.join(base_path, *args) }
|
|
332
332
|
Padrino.stub(:root, callable, &block)
|
|
333
333
|
end
|
|
334
334
|
|
|
335
335
|
it 'should output source_location if :source_location is set to true' do
|
|
336
|
-
stub_root { Padrino.logger.debug(
|
|
336
|
+
stub_root { Padrino.logger.debug('hello world') }
|
|
337
337
|
assert_match(/hello world/, Padrino.logger.log.string)
|
|
338
338
|
end
|
|
339
339
|
|
|
340
340
|
it 'should output source_location if file path is relative' do
|
|
341
341
|
stub_message = "test/test_logger.rb:269:in `test'"
|
|
342
|
-
Padrino::Logger.logger.stub(:caller, [stub_message]){ stub_root { Padrino.logger.debug(
|
|
343
|
-
assert_match(
|
|
342
|
+
Padrino::Logger.logger.stub(:caller, [stub_message]) { stub_root { Padrino.logger.debug('hello relative path') } }
|
|
343
|
+
assert_match(%r{\[test/test_logger\.rb:269\] hello relative path}, Padrino.logger.log.string)
|
|
344
344
|
end
|
|
345
345
|
|
|
346
346
|
it 'should not output source_location if :source_location is set to false' do
|
|
347
347
|
Padrino::Logger::Config[:test][:source_location] = false
|
|
348
348
|
Padrino::Logger.setup!
|
|
349
|
-
stub_root { Padrino.logger.debug(
|
|
349
|
+
stub_root { Padrino.logger.debug('hello world') }
|
|
350
350
|
assert_match(/hello world/, Padrino.logger.log.string)
|
|
351
351
|
refute_match(/\[.+?\] hello world/, Padrino.logger.log.string)
|
|
352
352
|
end
|
|
353
353
|
|
|
354
354
|
it 'should not output source_location unless file path is not started with Padrino.root' do
|
|
355
|
-
stub_root(
|
|
355
|
+
stub_root('/unknown/path/') { Padrino.logger.debug('hello boy') }
|
|
356
356
|
assert_match(/hello boy/, Padrino.logger.log.string)
|
|
357
357
|
refute_match(/\[.+?\] hello boy/, Padrino.logger.log.string)
|
|
358
358
|
end
|
|
359
359
|
|
|
360
360
|
it 'should not output source_location if source file path is started with Padrino.root + vendor' do
|
|
361
|
-
base_path = File.expand_path(
|
|
362
|
-
stub_message = File.expand_path(
|
|
363
|
-
Padrino::Logger.logger.stub(:caller, [stub_message]) { stub_root(base_path) { Padrino.logger.debug(
|
|
361
|
+
base_path = File.expand_path("#{__dir__}/fixtures/")
|
|
362
|
+
stub_message = "#{File.expand_path("#{__dir__}/fixtures/vendor/logger.rb")}:291:in `test'"
|
|
363
|
+
Padrino::Logger.logger.stub(:caller, [stub_message]) { stub_root(base_path) { Padrino.logger.debug('hello vendor') } }
|
|
364
364
|
assert_match(/hello vendor/, Padrino.logger.log.string)
|
|
365
365
|
refute_match(/\[.+?\] hello vendor/, Padrino.logger.log.string)
|
|
366
366
|
end
|