gin 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +16 -0
- data/Manifest.txt +12 -2
- data/README.rdoc +33 -0
- data/Rakefile +5 -0
- data/TODO.rdoc +7 -0
- data/bin/gin +158 -0
- data/lib/gin.rb +19 -2
- data/lib/gin/app.rb +420 -173
- data/lib/gin/cache.rb +65 -0
- data/lib/gin/config.rb +174 -18
- data/lib/gin/constants.rb +4 -0
- data/lib/gin/controller.rb +219 -11
- data/lib/gin/core_ext/gin_class.rb +16 -0
- data/lib/gin/errorable.rb +16 -2
- data/lib/gin/filterable.rb +29 -19
- data/lib/gin/reloadable.rb +1 -1
- data/lib/gin/request.rb +11 -0
- data/lib/gin/router.rb +185 -61
- data/lib/gin/rw_lock.rb +109 -0
- data/lib/gin/test.rb +702 -0
- data/public/gin.css +15 -3
- data/test/app/layouts/bar.erb +9 -0
- data/test/app/layouts/foo.erb +9 -0
- data/test/app/views/bar.erb +1 -0
- data/test/mock_app.rb +94 -0
- data/test/mock_config/invalid.yml +2 -0
- data/test/test_app.rb +160 -45
- data/test/test_cache.rb +57 -0
- data/test/test_config.rb +108 -13
- data/test/test_controller.rb +201 -11
- data/test/test_errorable.rb +1 -1
- data/test/test_gin.rb +9 -0
- data/test/test_helper.rb +3 -1
- data/test/test_router.rb +33 -0
- data/test/test_rw_lock.rb +65 -0
- data/test/test_test.rb +627 -0
- metadata +86 -6
- data/.autotest +0 -23
- data/.gitignore +0 -7
data/public/gin.css
CHANGED
@@ -1,15 +1,27 @@
|
|
1
1
|
|
2
2
|
body {
|
3
|
-
font-family: Helvetica Neue, Helvetica, Sans-Serif;
|
4
3
|
background-color: #eee;
|
5
4
|
margin: 50px;
|
6
5
|
}
|
7
6
|
|
7
|
+
body, h1 {
|
8
|
+
font-family: 'HelveticaNeue-Light', 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
9
|
+
font-weight: 100;
|
10
|
+
}
|
11
|
+
|
12
|
+
h1, strong {
|
13
|
+
color: #444;
|
14
|
+
}
|
15
|
+
|
16
|
+
a {
|
17
|
+
color: #9fbb4a;
|
18
|
+
}
|
19
|
+
|
8
20
|
.canvas {
|
9
21
|
border: 1px solid #ccc;
|
10
22
|
padding: 12px;
|
11
23
|
padding-top: 10px;
|
12
|
-
border-radius:
|
24
|
+
border-radius: 10px;
|
13
25
|
box-shadow: 3px 3px 10px #aaa;
|
14
26
|
background-color: #fff;
|
15
27
|
margin: 0 auto;
|
@@ -29,7 +41,7 @@ body {
|
|
29
41
|
border: 1px solid #ccc;
|
30
42
|
overflow: scroll;
|
31
43
|
background-color: #efefef;
|
32
|
-
border-radius:
|
44
|
+
border-radius: 7px;
|
33
45
|
box-shadow: 3px 3px -10px #aaa;
|
34
46
|
}
|
35
47
|
|
@@ -0,0 +1 @@
|
|
1
|
+
Value is <%= test_val %>
|
data/test/mock_app.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
class MockApp < Gin::App
|
2
|
+
|
3
|
+
class FooController < Gin::Controller
|
4
|
+
controller_name "foo"
|
5
|
+
layout "foo"
|
6
|
+
|
7
|
+
def index
|
8
|
+
view :bar, locals: {test_val: "LOCAL"}
|
9
|
+
end
|
10
|
+
|
11
|
+
def login
|
12
|
+
set_cookie "foo_session", "12345",
|
13
|
+
expires: Time.parse("Fri, 01 Jan 2100 00:00:00 -0000")
|
14
|
+
"OK"
|
15
|
+
end
|
16
|
+
|
17
|
+
def supercookie
|
18
|
+
set_cookie "supercookie", "SUPER!",
|
19
|
+
expires: Time.parse("Fri, 01 Jan 2100 00:00:00 -0000"),
|
20
|
+
domain: "mockapp.com",
|
21
|
+
path: "/",
|
22
|
+
secure: true,
|
23
|
+
httponly: true
|
24
|
+
"OK"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
class BarController < Gin::Controller
|
30
|
+
controller_name "bar"
|
31
|
+
|
32
|
+
def show id
|
33
|
+
"SHOW #{id}!"
|
34
|
+
end
|
35
|
+
|
36
|
+
def index
|
37
|
+
raise "OH NOES"
|
38
|
+
end
|
39
|
+
|
40
|
+
def see_other
|
41
|
+
redirect "http://example.com", 301
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
class ApiController < Gin::Controller
|
47
|
+
controller_name "api"
|
48
|
+
|
49
|
+
def pdf
|
50
|
+
content_type 'application/pdf'
|
51
|
+
'fake pdf'
|
52
|
+
end
|
53
|
+
|
54
|
+
def json
|
55
|
+
content_type :json
|
56
|
+
'{"foo":1234}'
|
57
|
+
end
|
58
|
+
|
59
|
+
def bson
|
60
|
+
content_type 'application/bson'
|
61
|
+
BSON.serialize({'foo' => 1234}).to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
def xml
|
65
|
+
content_type :xml
|
66
|
+
'<foo>1234</foo>'
|
67
|
+
end
|
68
|
+
|
69
|
+
def plist
|
70
|
+
content_type 'application/plist'
|
71
|
+
<<-STR
|
72
|
+
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
73
|
+
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">
|
74
|
+
<dict>\n\t<key>foo</key>\n\t<integer>1234</integer>\n</dict>\n</plist>
|
75
|
+
STR
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
logger StringIO.new
|
81
|
+
root_dir "test/app"
|
82
|
+
|
83
|
+
autoreload false
|
84
|
+
|
85
|
+
mount BarController do
|
86
|
+
get :show, "/:id"
|
87
|
+
get :index, "/"
|
88
|
+
defaults
|
89
|
+
end
|
90
|
+
|
91
|
+
mount FooController
|
92
|
+
|
93
|
+
mount ApiController
|
94
|
+
end
|
data/test/test_app.rb
CHANGED
@@ -73,22 +73,17 @@ end
|
|
73
73
|
class AppTest < Test::Unit::TestCase
|
74
74
|
class NamespacedApp < Gin::App; end
|
75
75
|
|
76
|
+
FOO_ROUTER = FooApp.router
|
77
|
+
|
76
78
|
def setup
|
77
|
-
FooApp.
|
78
|
-
FooApp.
|
79
|
-
FooApp.instance_variable_set("@middleware", nil)
|
80
|
-
FooApp.instance_variable_set("@instance", nil)
|
81
|
-
FooApp.instance_variable_set("@config", nil)
|
82
|
-
FooApp.instance_variable_set("@config_dir", nil)
|
83
|
-
FooApp.instance_variable_set("@error_delegate", nil)
|
84
|
-
FooApp.instance_variable_set("@public_dir", nil)
|
85
|
-
FooApp.instance_variable_set("@session", nil)
|
86
|
-
FooApp.instance_variable_set("@protection", nil)
|
87
|
-
FooApp.instance_variable_set("@autoreload", nil)
|
79
|
+
FooApp.setup
|
80
|
+
FooApp.options[:router] = FOO_ROUTER
|
88
81
|
|
89
82
|
@error_io = StringIO.new
|
90
|
-
|
91
|
-
|
83
|
+
FooApp.logger(@error_io)
|
84
|
+
|
85
|
+
@app = FooApp.new
|
86
|
+
@rapp = FooApp.new lambda{|env| [200,{'Content-Type'=>'text/html'},["HI"]]}
|
92
87
|
end
|
93
88
|
|
94
89
|
|
@@ -99,9 +94,9 @@ class AppTest < Test::Unit::TestCase
|
|
99
94
|
|
100
95
|
def test_class_proxies
|
101
96
|
proxies = [:protection, :sessions, :session_secret, :middleware,
|
102
|
-
:error_delegate, :router, :root_dir, :public_dir, :
|
103
|
-
:
|
104
|
-
:
|
97
|
+
:error_delegate, :router, :root_dir, :public_dir, :environment,
|
98
|
+
:mime_type, :asset_host, :options, :config, :autoreload, :md5s,
|
99
|
+
:templates]
|
105
100
|
|
106
101
|
proxies.each do |name|
|
107
102
|
assert FooApp.respond_to?(name), "Gin::App should respond to #{name}"
|
@@ -145,15 +140,19 @@ class AppTest < Test::Unit::TestCase
|
|
145
140
|
|
146
141
|
|
147
142
|
def test_autoreload
|
143
|
+
FooApp.setup
|
148
144
|
FooApp.environment "production"
|
145
|
+
@app = FooApp.new
|
149
146
|
assert_equal false, FooApp.autoreload
|
150
147
|
assert_equal false, @app.autoreload
|
151
148
|
|
152
149
|
FooApp.autoreload true
|
150
|
+
@app = FooApp.new
|
153
151
|
assert_equal true, FooApp.autoreload
|
154
152
|
assert_equal true, @app.autoreload
|
155
153
|
|
156
154
|
FooApp.autoreload false
|
155
|
+
@app = FooApp.new
|
157
156
|
assert_equal false, FooApp.autoreload
|
158
157
|
assert_equal false, @app.autoreload
|
159
158
|
end
|
@@ -161,10 +160,12 @@ class AppTest < Test::Unit::TestCase
|
|
161
160
|
|
162
161
|
def test_autoreload_dev
|
163
162
|
FooApp.environment "development"
|
163
|
+
@app = FooApp.new
|
164
164
|
assert_equal true, FooApp.autoreload
|
165
165
|
assert_equal true, @app.autoreload
|
166
166
|
|
167
167
|
FooApp.autoreload false
|
168
|
+
@app = FooApp.new
|
168
169
|
assert_equal false, FooApp.autoreload
|
169
170
|
assert_equal false, @app.autoreload
|
170
171
|
end
|
@@ -202,31 +203,139 @@ class AppTest < Test::Unit::TestCase
|
|
202
203
|
|
203
204
|
def test_config_dir
|
204
205
|
assert_equal File.join(FooApp.root_dir, "config"), FooApp.config_dir
|
206
|
+
assert_equal File.join(FooApp.root_dir, "config"), FooApp.config.dir
|
207
|
+
assert_equal File.join(FooApp.root_dir, "config"), @app.config.dir
|
205
208
|
|
206
209
|
FooApp.config_dir "/foo/blah"
|
207
210
|
assert_equal "/foo/blah", FooApp.config_dir
|
211
|
+
assert_equal "/foo/blah", FooApp.config.dir
|
212
|
+
assert_equal "/foo/blah", @app.config.dir
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
def test_config_env
|
217
|
+
assert_equal 'development', FooApp.environment
|
218
|
+
assert_equal 'development', FooApp.config.environment
|
219
|
+
assert_equal 'development', @app.config.environment
|
220
|
+
|
221
|
+
FooApp.environment "production"
|
222
|
+
assert_equal "production", FooApp.config.environment
|
223
|
+
assert_equal "production", @app.config.environment
|
224
|
+
end
|
225
|
+
|
226
|
+
|
227
|
+
def test_config_reload
|
228
|
+
assert_equal false, FooApp.config_reload
|
229
|
+
assert_equal false, FooApp.config.ttl
|
230
|
+
assert_equal false, @app.config.ttl
|
231
|
+
|
232
|
+
FooApp.config_reload 300
|
233
|
+
assert_equal 300, FooApp.config.ttl
|
234
|
+
assert_equal 300, @app.config.ttl
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
def test_config_logger
|
239
|
+
assert_equal @error_io, FooApp.logger
|
240
|
+
assert_equal @error_io, FooApp.config.logger
|
241
|
+
assert_equal @error_io, @app.config.logger
|
242
|
+
|
243
|
+
FooApp.logger "mock_logger"
|
244
|
+
assert_equal "mock_logger", FooApp.config.logger
|
245
|
+
assert_equal "mock_logger", @app.config.logger
|
208
246
|
end
|
209
247
|
|
210
248
|
|
211
249
|
def test_config
|
212
|
-
|
213
|
-
assert
|
250
|
+
@app = FooApp.new
|
251
|
+
assert Gin::Config === @app.config
|
252
|
+
assert @app.config == FooApp.config
|
253
|
+
assert @app.config.instance_variable_get("@data").empty?
|
214
254
|
end
|
215
255
|
|
216
256
|
|
217
257
|
def test_config_with_dir
|
258
|
+
FooApp.setup
|
218
259
|
FooApp.config_dir "./test/mock_config"
|
219
|
-
|
260
|
+
@app = FooApp.new
|
261
|
+
assert_equal 1, FooApp.config['backend.connections']
|
262
|
+
assert_equal 1, @app.config['backend.connections']
|
220
263
|
end
|
221
264
|
|
222
265
|
|
223
|
-
def
|
224
|
-
FooApp.
|
225
|
-
|
226
|
-
|
266
|
+
def test_layout
|
267
|
+
assert_equal :layout, FooApp.layout
|
268
|
+
assert_equal :layout, @app.layout
|
269
|
+
|
270
|
+
FooApp.layout "foo"
|
271
|
+
assert_equal "foo", FooApp.layout
|
272
|
+
assert_equal :layout, @app.layout
|
273
|
+
|
274
|
+
@app = FooApp.new
|
275
|
+
assert_equal "foo", @app.layout
|
276
|
+
end
|
277
|
+
|
278
|
+
|
279
|
+
def test_layouts_dir
|
280
|
+
assert_equal File.join(FooApp.root_dir, "layouts"), FooApp.layouts_dir
|
281
|
+
FooApp.root_dir "test/foo"
|
282
|
+
assert_equal File.join(FooApp.root_dir, "layouts"), FooApp.layouts_dir
|
283
|
+
assert_equal File.join(@app.root_dir, "layouts"), @app.layouts_dir
|
284
|
+
end
|
285
|
+
|
286
|
+
|
287
|
+
def test_views_dir
|
288
|
+
assert_equal File.join(FooApp.root_dir, "views"), FooApp.views_dir
|
289
|
+
FooApp.root_dir "test/foo"
|
290
|
+
assert_equal File.join(FooApp.root_dir, "views"), FooApp.views_dir
|
291
|
+
assert_equal File.join(@app.root_dir, "views"), @app.views_dir
|
292
|
+
end
|
293
|
+
|
294
|
+
|
295
|
+
def test_template_engines
|
296
|
+
FooApp.setup
|
297
|
+
default = Tilt.mappings.merge(nil => [Tilt::ERBTemplate])
|
298
|
+
assert_equal default, FooApp.options[:template_engines]
|
299
|
+
assert_equal default, @app.template_engines
|
300
|
+
|
301
|
+
FooApp.default_template Tilt::ERBTemplate, "custom", "thing"
|
302
|
+
|
303
|
+
assert_equal default, @app.template_engines
|
304
|
+
@app = FooApp.new
|
305
|
+
assert_equal [Tilt::ERBTemplate], @app.template_engines['custom']
|
306
|
+
assert_equal [Tilt::ERBTemplate], @app.template_engines['thing']
|
307
|
+
|
308
|
+
FooApp.default_template Tilt::HamlTemplate
|
309
|
+
assert_equal [Tilt::HamlTemplate, Tilt::ERBTemplate],
|
310
|
+
FooApp.options[:template_engines][nil]
|
311
|
+
end
|
312
|
+
|
313
|
+
|
314
|
+
def test_template_for
|
315
|
+
FooApp.default_template Tilt::ERBTemplate, "erb"
|
316
|
+
@app = FooApp.new root_dir: "./test/app"
|
317
|
+
template = @app.template_for "./test/app/layouts/foo"
|
318
|
+
|
319
|
+
assert Tilt::ERBTemplate === template
|
320
|
+
assert_equal "./test/app/layouts/foo.erb", template.file
|
321
|
+
end
|
322
|
+
|
323
|
+
|
324
|
+
def test_template_for_invalid
|
325
|
+
@app = FooApp.new root_dir: "./test/app"
|
326
|
+
template = @app.template_for "./test/app/layouts/ugh"
|
327
|
+
assert_nil template
|
328
|
+
end
|
329
|
+
|
227
330
|
|
228
|
-
|
229
|
-
|
331
|
+
def test_template_files
|
332
|
+
@app = FooApp.new root_dir: "./test/app"
|
333
|
+
|
334
|
+
files = @app.template_files "./test/app/layouts/foo"
|
335
|
+
assert_equal ["./test/app/layouts/foo.erb"], files
|
336
|
+
|
337
|
+
files = @app.template_files "./test/app/layouts/ugh"
|
338
|
+
assert_equal [], files
|
230
339
|
end
|
231
340
|
|
232
341
|
|
@@ -242,7 +351,7 @@ class AppTest < Test::Unit::TestCase
|
|
242
351
|
assert_equal [FooMiddleware, :foo, :bar], FooApp.middleware[0]
|
243
352
|
assert !FooMiddleware.called?
|
244
353
|
|
245
|
-
myapp = FooApp.new @error_io
|
354
|
+
myapp = FooApp.new logger: @error_io
|
246
355
|
myapp.call({'rack.input' => "", 'PATH_INFO' => '/foo', 'REQUEST_METHOD' => 'GET'})
|
247
356
|
assert FooMiddleware.called?
|
248
357
|
|
@@ -276,8 +385,8 @@ class AppTest < Test::Unit::TestCase
|
|
276
385
|
def test_call_rack_app
|
277
386
|
env = {'rack.input' => "", 'PATH_INFO' => '/bad', 'REQUEST_METHOD' => 'GET'}
|
278
387
|
expected = [200, {'Content-Length'=>"5"}, "AHOY!"]
|
279
|
-
myapp = lambda{|
|
280
|
-
@app = FooApp.new myapp
|
388
|
+
myapp = lambda{|_| expected }
|
389
|
+
@app = FooApp.new myapp
|
281
390
|
|
282
391
|
resp = @app.call env
|
283
392
|
assert_equal expected, resp
|
@@ -310,6 +419,7 @@ class AppTest < Test::Unit::TestCase
|
|
310
419
|
|
311
420
|
def test_dispatch_not_found
|
312
421
|
FooApp.environment 'test'
|
422
|
+
@app = FooApp.new
|
313
423
|
env = {'rack.input' => "", 'PATH_INFO' => '/foo', 'REQUEST_METHOD' => 'GET'}
|
314
424
|
|
315
425
|
resp = @app.dispatch env, FooController, :bad
|
@@ -322,6 +432,7 @@ class AppTest < Test::Unit::TestCase
|
|
322
432
|
|
323
433
|
def test_dispatch_no_handler
|
324
434
|
FooApp.environment 'test'
|
435
|
+
@app = FooApp.new
|
325
436
|
env = {'rack.input' => "", 'PATH_INFO' => '/foo', 'REQUEST_METHOD' => 'GET'}
|
326
437
|
|
327
438
|
resp = @app.dispatch env, FooController, nil
|
@@ -338,6 +449,7 @@ class AppTest < Test::Unit::TestCase
|
|
338
449
|
|
339
450
|
def test_dispatch_error
|
340
451
|
FooApp.environment 'test'
|
452
|
+
@app = FooApp.new
|
341
453
|
env = {'rack.input' => "", 'PATH_INFO' => '/bad', 'REQUEST_METHOD' => 'GET'}
|
342
454
|
resp = @app.dispatch env, FooController, :error
|
343
455
|
|
@@ -350,6 +462,7 @@ class AppTest < Test::Unit::TestCase
|
|
350
462
|
|
351
463
|
def test_handle_error
|
352
464
|
FooApp.error_delegate ErrDelegate
|
465
|
+
@app = FooApp.new
|
353
466
|
env = {'rack.input' => "", 'PATH_INFO' => '/bad', 'REQUEST_METHOD' => 'GET'}
|
354
467
|
err = ArgumentError.new("Unexpected Argument")
|
355
468
|
|
@@ -365,6 +478,7 @@ class AppTest < Test::Unit::TestCase
|
|
365
478
|
|
366
479
|
def test_handle_error_no_delegate
|
367
480
|
FooApp.environment "production"
|
481
|
+
@app = FooApp.new
|
368
482
|
env = {'rack.input' => "", 'PATH_INFO' => '/bad', 'REQUEST_METHOD' => 'GET'}
|
369
483
|
resp = @app.handle_error ArgumentError.new("Unexpected Argument"), env
|
370
484
|
|
@@ -377,6 +491,7 @@ class AppTest < Test::Unit::TestCase
|
|
377
491
|
def test_handle_error_bad_delegate
|
378
492
|
FooApp.environment "production"
|
379
493
|
FooApp.error_delegate BadErrDelegate
|
494
|
+
@app = FooApp.new
|
380
495
|
|
381
496
|
env = {'rack.input' => "", 'PATH_INFO' => '/bad', 'REQUEST_METHOD' => 'GET'}
|
382
497
|
err = ArgumentError.new("Unexpected Argument")
|
@@ -395,7 +510,7 @@ class AppTest < Test::Unit::TestCase
|
|
395
510
|
env = {'rack.input' => "", 'PATH_INFO' => '/bad', 'REQUEST_METHOD' => 'GET'}
|
396
511
|
err = ArgumentError.new("Unexpected Argument")
|
397
512
|
old_handler = Gin::Controller.error_handlers[Exception]
|
398
|
-
Gin::Controller.error_handlers[Exception] = lambda{|
|
513
|
+
Gin::Controller.error_handlers[Exception] = lambda{|_| raise Gin::Error, "FRAMEWORK IST KAPUT"}
|
399
514
|
|
400
515
|
assert_raises(Gin::Error){ @app.handle_error err, env }
|
401
516
|
ensure
|
@@ -423,11 +538,12 @@ class AppTest < Test::Unit::TestCase
|
|
423
538
|
def test_asset_version
|
424
539
|
old_dir = FooApp.public_dir
|
425
540
|
FooApp.public_dir File.dirname(__FILE__)
|
541
|
+
@app = FooApp.new
|
426
542
|
|
427
543
|
md5_cmd = RUBY_PLATFORM =~ /darwin/ ? 'md5 -q' : 'md5sum'
|
428
544
|
expected = `#{md5_cmd} #{__FILE__}`[0...8]
|
429
545
|
|
430
|
-
assert_equal expected,
|
546
|
+
assert_equal expected, @app.asset_version(File.basename(__FILE__))
|
431
547
|
|
432
548
|
ensure
|
433
549
|
FooApp.public_dir old_dir
|
@@ -438,24 +554,27 @@ class AppTest < Test::Unit::TestCase
|
|
438
554
|
FooApp.asset_host do |name|
|
439
555
|
"http://#{File.extname(name)[1..-1] << "." if name}foo.com"
|
440
556
|
end
|
441
|
-
|
557
|
+
@app = FooApp.new
|
442
558
|
assert_equal "http://js.foo.com", @app.asset_host_for("app.js")
|
443
559
|
end
|
444
560
|
|
445
561
|
|
446
562
|
def test_asset_host
|
447
563
|
FooApp.asset_host "http://example.com"
|
564
|
+
@app = FooApp.new
|
448
565
|
assert_equal "http://example.com", FooApp.asset_host
|
449
566
|
assert_equal "http://example.com", @app.asset_host
|
450
567
|
|
451
568
|
FooApp.asset_host{ "https://foo.com" }
|
452
|
-
|
569
|
+
@app = FooApp.new
|
570
|
+
assert_equal Proc, FooApp.asset_host.class
|
453
571
|
assert_equal "https://foo.com", @app.asset_host
|
454
572
|
end
|
455
573
|
|
456
574
|
|
457
575
|
def test_asset
|
458
576
|
FooApp.public_dir "./test/mock_config"
|
577
|
+
@app = FooApp.new
|
459
578
|
assert @app.asset("backend.yml") =~ %r{/gin/test/mock_config/backend\.yml$}
|
460
579
|
assert @app.asset("500.html") =~ %r{/gin/public/500\.html$}
|
461
580
|
|
@@ -466,6 +585,7 @@ class AppTest < Test::Unit::TestCase
|
|
466
585
|
|
467
586
|
def test_bad_asset
|
468
587
|
FooApp.public_dir "./test/mock_config"
|
588
|
+
@app = FooApp.new
|
469
589
|
assert_nil @app.asset("bad_file")
|
470
590
|
assert_nil @app.asset("../../History.rdoc")
|
471
591
|
|
@@ -511,6 +631,7 @@ class AppTest < Test::Unit::TestCase
|
|
511
631
|
env['PATH_INFO'] = '/backend.yml'
|
512
632
|
|
513
633
|
FooApp.public_dir "./test/mock_config"
|
634
|
+
@app = FooApp.new
|
514
635
|
assert @app.static!(env)
|
515
636
|
assert env['gin.static'] =~ %r{/gin/test/mock_config/backend\.yml$}
|
516
637
|
|
@@ -531,8 +652,8 @@ class AppTest < Test::Unit::TestCase
|
|
531
652
|
|
532
653
|
def test_init
|
533
654
|
@app = FooApp.new
|
534
|
-
assert_equal
|
535
|
-
assert_equal
|
655
|
+
assert_equal @error_io, @app.logger, "logger should default to class logger"
|
656
|
+
assert_equal @error_io, @rapp.logger, "logger should default to class logger"
|
536
657
|
assert_nil @app.rack_app, "Rack application should be nil by default"
|
537
658
|
assert Proc === @rapp.rack_app, "Rack application should be a Proc"
|
538
659
|
assert Gin::Router === @app.router, "Should have a Gin::Router"
|
@@ -556,10 +677,7 @@ class AppTest < Test::Unit::TestCase
|
|
556
677
|
|
557
678
|
|
558
679
|
def test_default_environment
|
559
|
-
|
560
|
-
assert !FooApp.test?
|
561
|
-
assert !FooApp.staging?
|
562
|
-
assert !FooApp.production?
|
680
|
+
assert_equal 'development', FooApp.environment
|
563
681
|
end
|
564
682
|
|
565
683
|
|
@@ -572,18 +690,15 @@ class AppTest < Test::Unit::TestCase
|
|
572
690
|
|
573
691
|
|
574
692
|
def test_environment
|
575
|
-
FooApp.instance_variable_set("@environment", nil)
|
576
693
|
ENV['RACK_ENV'] = 'production'
|
577
|
-
|
578
|
-
|
579
|
-
assert !FooApp.staging?
|
580
|
-
assert FooApp.production?
|
694
|
+
FooApp.setup
|
695
|
+
assert_equal 'production', FooApp.environment
|
581
696
|
end
|
582
697
|
|
583
698
|
|
584
699
|
def test_inst_environment
|
585
|
-
FooApp.instance_variable_set("@environment", nil)
|
586
700
|
ENV['RACK_ENV'] = 'production'
|
701
|
+
FooApp.setup
|
587
702
|
@app = FooApp.new
|
588
703
|
assert !@app.development?
|
589
704
|
assert !@app.test?
|
@@ -595,9 +710,9 @@ class AppTest < Test::Unit::TestCase
|
|
595
710
|
def test_set_environment
|
596
711
|
%w{development test staging production}.each do |name|
|
597
712
|
FooApp.environment name
|
713
|
+
@app = FooApp.new
|
598
714
|
mname = name + "?"
|
599
715
|
assert @app.send(mname), "Instance environment should be #{name}"
|
600
|
-
assert FooApp.send(mname), "Class environment should be #{name}"
|
601
716
|
end
|
602
717
|
end
|
603
718
|
|