padrino-core 0.16.0.pre3 → 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 +28 -30
- 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 +87 -78
- 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 -17
- 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 +52 -53
- data/test/test_flash.rb +18 -18
- data/test/test_locale.rb +2 -2
- data/test/test_logger.rb +65 -65
- data/test/test_mounter.rb +133 -123
- data/test/test_params_protection.rb +40 -40
- data/test/test_reloader_complex.rb +24 -24
- 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 +897 -909
- metadata +7 -7
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(
|
|
337
|
-
assert_match(
|
|
336
|
+
stub_root { Padrino.logger.debug('hello world') }
|
|
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
|