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
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
|
+
require_relative 'fixtures/apps/kiq'
|
|
3
|
+
require_relative 'fixtures/apps/system'
|
|
4
|
+
require_relative 'fixtures/apps/static'
|
|
5
|
+
require_relative 'fixtures/apps/custom_dependencies/custom_dependencies'
|
|
6
6
|
|
|
7
|
-
describe
|
|
7
|
+
describe 'SystemReloader' do
|
|
8
8
|
describe 'for wierd and difficult reload events' do
|
|
9
9
|
before do
|
|
10
10
|
@app = SystemDemo
|
|
@@ -18,9 +18,9 @@ describe "SystemReloader" do
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it 'should reload children on parent change' do
|
|
21
|
-
Padrino.mount(SystemDemo).to(
|
|
21
|
+
Padrino.mount(SystemDemo).to('/')
|
|
22
22
|
assert_equal Child.new.family, 'Danes'
|
|
23
|
-
parent_file = File.expand_path(
|
|
23
|
+
parent_file = File.expand_path("#{__dir__}/fixtures/apps/models/parent.rb")
|
|
24
24
|
new_class = <<-DOC
|
|
25
25
|
class Parent
|
|
26
26
|
def family
|
|
@@ -36,24 +36,24 @@ describe "SystemReloader" do
|
|
|
36
36
|
Padrino::Reloader.reload!
|
|
37
37
|
assert_equal 'Danes', Parent.new.family
|
|
38
38
|
assert_equal 'Danes', Child.new.family
|
|
39
|
-
File.open(parent_file,
|
|
39
|
+
File.open(parent_file, 'w') { |f| f.write(new_class) }
|
|
40
40
|
Padrino::Reloader.reload!
|
|
41
41
|
assert_equal 'Dancy', Parent.new.family
|
|
42
42
|
assert_equal 'Shmancy', Parent.new.shmamily
|
|
43
43
|
assert_equal 'Dancy', Child.new.family
|
|
44
44
|
assert_equal 'Shmancy', Child.new.shmamily
|
|
45
45
|
ensure
|
|
46
|
-
File.open(parent_file,
|
|
46
|
+
File.open(parent_file, 'w') { |f| f.write(backup) }
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it 'should not fail horribly on reload event with non-padrino apps' do
|
|
51
|
-
Padrino.mount(
|
|
51
|
+
Padrino.mount('kiq').to('/')
|
|
52
52
|
Padrino.reload!
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
it 'should not reload apps with disabled reload' do
|
|
56
|
-
Padrino.mount(StaticDemo).to(
|
|
56
|
+
Padrino.mount(StaticDemo).to('/')
|
|
57
57
|
Padrino.reload!
|
|
58
58
|
end
|
|
59
59
|
end
|
|
@@ -68,15 +68,15 @@ describe "SystemReloader" do
|
|
|
68
68
|
DOC
|
|
69
69
|
tmp_file = '/tmp/padrino_class_demo.rb'
|
|
70
70
|
begin
|
|
71
|
-
File.open(tmp_file,
|
|
71
|
+
File.open(tmp_file, 'w') { |f| f.write(new_class) }
|
|
72
72
|
Padrino.clear!
|
|
73
|
-
require File.expand_path(
|
|
73
|
+
require File.expand_path("#{__dir__}/fixtures/apps/system_class_methods_demo.rb")
|
|
74
74
|
@app = SystemClassMethodsDemo
|
|
75
|
-
Padrino.mount(SystemClassMethodsDemo).to(
|
|
75
|
+
Padrino.mount(SystemClassMethodsDemo).to('/')
|
|
76
76
|
get '/'
|
|
77
77
|
assert defined?(SingletonClassTest), 'SingletonClassTest undefined'
|
|
78
78
|
assert_includes SingletonClassTest.singleton_methods, :external_test
|
|
79
|
-
FileUtils.touch File.expand_path(
|
|
79
|
+
FileUtils.touch File.expand_path("#{__dir__}/fixtures/apps/helpers/class_methods_helpers.rb")
|
|
80
80
|
Padrino.reload!
|
|
81
81
|
assert defined?(SingletonClassTest), 'SingletonClassTest undefined'
|
|
82
82
|
assert_includes SingletonClassTest.singleton_methods, :external_test
|
|
@@ -94,15 +94,15 @@ describe "SystemReloader" do
|
|
|
94
94
|
DOC
|
|
95
95
|
tmp_file = '/tmp/padrino_instance_demo.rb'
|
|
96
96
|
begin
|
|
97
|
-
File.open(tmp_file,
|
|
97
|
+
File.open(tmp_file, 'w') { |f| f.write(new_class) }
|
|
98
98
|
Padrino.clear!
|
|
99
|
-
require File.expand_path(
|
|
99
|
+
require File.expand_path("#{__dir__}/fixtures/apps/system_instance_methods_demo.rb")
|
|
100
100
|
@app = SystemInstanceMethodsDemo
|
|
101
|
-
Padrino.mount(SystemInstanceMethodsDemo).to(
|
|
101
|
+
Padrino.mount(SystemInstanceMethodsDemo).to('/')
|
|
102
102
|
get '/'
|
|
103
103
|
assert defined?(InstanceTest), 'InstanceTest undefined'
|
|
104
104
|
assert_includes InstanceTest.new.methods, :instance_test
|
|
105
|
-
FileUtils.touch File.expand_path(
|
|
105
|
+
FileUtils.touch File.expand_path("#{__dir__}/fixtures/apps/helpers/instance_methods_helpers.rb")
|
|
106
106
|
Padrino.reload!
|
|
107
107
|
assert defined?(InstanceTest), 'InstanceTest undefined'
|
|
108
108
|
assert_includes InstanceTest.new.methods, :instance_test
|
|
@@ -113,24 +113,24 @@ describe "SystemReloader" do
|
|
|
113
113
|
|
|
114
114
|
it 'should not fail with superclass mismatch when reloading descendant classes with no instances' do
|
|
115
115
|
Padrino.clear!
|
|
116
|
-
require File.expand_path(
|
|
116
|
+
require File.expand_path("#{__dir__}/fixtures/apps/stealthy/app.rb")
|
|
117
117
|
@app = SystemStealthyClassDemo
|
|
118
|
-
Padrino.mount(SystemStealthyClassDemo).to(
|
|
118
|
+
Padrino.mount(SystemStealthyClassDemo).to('/')
|
|
119
119
|
get '/'
|
|
120
|
-
FileUtils.touch File.expand_path(
|
|
120
|
+
FileUtils.touch File.expand_path("#{__dir__}/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb")
|
|
121
121
|
Padrino.reload!
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
describe 'reloading custom dependencies' do
|
|
126
|
-
let(:custom_dependency_path) {
|
|
126
|
+
let(:custom_dependency_path) { "#{__dir__}/fixtures/apps/custom_dependencies/my_dependencies" }
|
|
127
127
|
let(:custom_dependency) { File.join(custom_dependency_path, 'my_dependency.rb') }
|
|
128
128
|
|
|
129
129
|
before do
|
|
130
130
|
@app = CustomDependencies
|
|
131
131
|
Padrino.clear!
|
|
132
|
-
Padrino.mount(CustomDependencies).to(
|
|
133
|
-
Padrino.dependency_paths << custom_dependency_path
|
|
132
|
+
Padrino.mount(CustomDependencies).to('/')
|
|
133
|
+
Padrino.dependency_paths << "#{custom_dependency_path}/*.rb"
|
|
134
134
|
Padrino.load!
|
|
135
135
|
get '/'
|
|
136
136
|
end
|
|
@@ -145,13 +145,13 @@ describe "SystemReloader" do
|
|
|
145
145
|
it 'should remove constants of misdesigned modules' do
|
|
146
146
|
skip
|
|
147
147
|
Padrino.clear!
|
|
148
|
-
require File.expand_path(
|
|
148
|
+
require File.expand_path("#{__dir__}/fixtures/apps/concerned/app.rb")
|
|
149
149
|
@app = SystemConcernedClassDemo
|
|
150
|
-
Padrino.mount(SystemConcernedClassDemo).to(
|
|
150
|
+
Padrino.mount(SystemConcernedClassDemo).to('/')
|
|
151
151
|
get '/'
|
|
152
152
|
|
|
153
153
|
original_value = BadModule.instance_variable_get(:@happy_global_variable)
|
|
154
|
-
FileUtils.touch
|
|
154
|
+
FileUtils.touch "#{__dir__}/fixtures/apps/concerned/models/mixins/badmodule.rb"
|
|
155
155
|
Padrino.reload!
|
|
156
156
|
assert_equal original_value, BadModule.instance_variable_get(:@happy_global_variable)
|
|
157
157
|
end
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe 'Routing' do
|
|
4
4
|
it 'should perform restul routing' do
|
|
5
5
|
mock_app do
|
|
6
|
-
controller :
|
|
7
|
-
get :index, :
|
|
8
|
-
"#{url_for(:index, params[:parent_id], :
|
|
6
|
+
controller parent: :parents do
|
|
7
|
+
get :index, with: :asset_id do
|
|
8
|
+
"#{url_for(:index, params[:parent_id], asset_id: params[:asset_id])} get"
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
put :index, :
|
|
12
|
-
"#{url_for(:index, params[:parent_id], :
|
|
11
|
+
put :index, with: :asset_id do
|
|
12
|
+
"#{url_for(:index, params[:parent_id], asset_id: params[:asset_id])} put"
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
post :index, :
|
|
16
|
-
"#{url_for(:index, :
|
|
15
|
+
post :index, with: :asset_id do
|
|
16
|
+
"#{url_for(:index, parent_id: params[:parent_id], asset_id: params[:asset_id])} post"
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
delete :index, :
|
|
20
|
-
"#{url_for(:index, params[:parent_id], :
|
|
19
|
+
delete :index, with: :asset_id do
|
|
20
|
+
"#{url_for(:index, params[:parent_id], asset_id: params[:asset_id])} delete"
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
|
-
get
|
|
25
|
-
assert_equal
|
|
26
|
-
put
|
|
27
|
-
assert_equal
|
|
28
|
-
post
|
|
29
|
-
assert_equal
|
|
30
|
-
delete
|
|
31
|
-
assert_equal
|
|
24
|
+
get '/parents/1/hi'
|
|
25
|
+
assert_equal '/parents/1/hi get', body
|
|
26
|
+
put '/parents/1/hi'
|
|
27
|
+
assert_equal '/parents/1/hi put', body
|
|
28
|
+
post '/parents/1/hi'
|
|
29
|
+
assert_equal '/parents/1/hi post', body
|
|
30
|
+
delete '/parents/1/hi'
|
|
31
|
+
assert_equal '/parents/1/hi delete', body
|
|
32
32
|
end
|
|
33
33
|
end
|
data/test/test_router.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
describe "Router" do
|
|
1
|
+
require_relative 'helper'
|
|
2
|
+
require_relative 'fixtures/apps/simple'
|
|
5
3
|
|
|
4
|
+
describe 'Router' do
|
|
6
5
|
def setup
|
|
7
6
|
Padrino.clear!
|
|
8
7
|
end
|
|
@@ -13,269 +12,251 @@ describe "Router" do
|
|
|
13
12
|
'X-ScriptName' => env['SCRIPT_NAME'],
|
|
14
13
|
'X-PathInfo' => env['PATH_INFO'],
|
|
15
14
|
'Content-Type' => 'text/plain'
|
|
16
|
-
}, [
|
|
15
|
+
}, ['']]
|
|
17
16
|
}
|
|
18
17
|
map = Padrino::Router.new(
|
|
19
|
-
{ :
|
|
20
|
-
{ :
|
|
21
|
-
{ :
|
|
18
|
+
{ path: '/bar', to: app },
|
|
19
|
+
{ path: '/foo/bar', to: app },
|
|
20
|
+
{ path: '/foo', to: app }
|
|
22
21
|
)
|
|
23
22
|
|
|
24
|
-
res = Rack::MockRequest.new(map).get(
|
|
23
|
+
res = Rack::MockRequest.new(map).get('/')
|
|
25
24
|
assert res.not_found?
|
|
26
25
|
|
|
27
|
-
res = Rack::MockRequest.new(map).get(
|
|
26
|
+
res = Rack::MockRequest.new(map).get('/qux')
|
|
28
27
|
assert res.not_found?
|
|
29
28
|
|
|
30
|
-
res = Rack::MockRequest.new(map).get(
|
|
29
|
+
res = Rack::MockRequest.new(map).get('/foo')
|
|
31
30
|
assert res.ok?
|
|
32
|
-
assert_equal
|
|
33
|
-
assert_equal
|
|
31
|
+
assert_equal '/foo', res['X-ScriptName']
|
|
32
|
+
assert_equal '/', res['X-PathInfo']
|
|
34
33
|
|
|
35
|
-
res = Rack::MockRequest.new(map).get(
|
|
34
|
+
res = Rack::MockRequest.new(map).get('/foo/')
|
|
36
35
|
assert res.ok?
|
|
37
|
-
assert_equal
|
|
38
|
-
assert_equal
|
|
36
|
+
assert_equal '/foo', res['X-ScriptName']
|
|
37
|
+
assert_equal '/', res['X-PathInfo']
|
|
39
38
|
|
|
40
|
-
res = Rack::MockRequest.new(map).get(
|
|
39
|
+
res = Rack::MockRequest.new(map).get('/foo/bar')
|
|
41
40
|
assert res.ok?
|
|
42
|
-
assert_equal
|
|
43
|
-
assert_equal
|
|
41
|
+
assert_equal '/foo/bar', res['X-ScriptName']
|
|
42
|
+
assert_equal '/', res['X-PathInfo']
|
|
44
43
|
|
|
45
|
-
res = Rack::MockRequest.new(map).get(
|
|
44
|
+
res = Rack::MockRequest.new(map).get('/foo/bar/')
|
|
46
45
|
assert res.ok?
|
|
47
|
-
assert_equal
|
|
48
|
-
assert_equal
|
|
46
|
+
assert_equal '/foo/bar', res['X-ScriptName']
|
|
47
|
+
assert_equal '/', res['X-PathInfo']
|
|
49
48
|
|
|
50
|
-
res = Rack::MockRequest.new(map).get(
|
|
49
|
+
res = Rack::MockRequest.new(map).get('/foo///bar//quux')
|
|
51
50
|
assert_equal 200, res.status
|
|
52
51
|
assert res.ok?
|
|
53
|
-
assert_equal
|
|
54
|
-
assert_equal
|
|
52
|
+
assert_equal '/foo/bar', res['X-ScriptName']
|
|
53
|
+
assert_equal '//quux', res['X-PathInfo']
|
|
55
54
|
|
|
56
|
-
res = Rack::MockRequest.new(map).get(
|
|
55
|
+
res = Rack::MockRequest.new(map).get('/foo/quux', 'SCRIPT_NAME' => '/bleh')
|
|
57
56
|
assert res.ok?
|
|
58
|
-
assert_equal
|
|
59
|
-
assert_equal
|
|
57
|
+
assert_equal '/bleh/foo', res['X-ScriptName']
|
|
58
|
+
assert_equal '/quux', res['X-PathInfo']
|
|
60
59
|
|
|
61
|
-
res = Rack::MockRequest.new(map).get(
|
|
60
|
+
res = Rack::MockRequest.new(map).get('/bar', 'HTTP_HOST' => 'foo.org')
|
|
62
61
|
assert res.ok?
|
|
63
|
-
assert_equal
|
|
64
|
-
assert_equal
|
|
62
|
+
assert_equal '/bar', res['X-ScriptName']
|
|
63
|
+
assert_equal '/', res['X-PathInfo']
|
|
65
64
|
|
|
66
|
-
res = Rack::MockRequest.new(map).get(
|
|
65
|
+
res = Rack::MockRequest.new(map).get('/bar/', 'HTTP_HOST' => 'foo.org')
|
|
67
66
|
assert res.ok?
|
|
68
|
-
assert_equal
|
|
69
|
-
assert_equal
|
|
67
|
+
assert_equal '/bar', res['X-ScriptName']
|
|
68
|
+
assert_equal '/', res['X-PathInfo']
|
|
70
69
|
end
|
|
71
70
|
|
|
72
71
|
it 'should dispatch requests to cascade mounted apps' do
|
|
73
72
|
app = lambda { |env|
|
|
74
|
-
scary =
|
|
73
|
+
scary = env['PATH_INFO'].match?(/scary/)
|
|
75
74
|
[scary ? 404 : 200, {
|
|
76
75
|
'X-ScriptName' => env['SCRIPT_NAME'],
|
|
77
76
|
'X-PathInfo' => env['PATH_INFO'],
|
|
78
77
|
'Content-Type' => 'text/plain'
|
|
79
|
-
}, [
|
|
78
|
+
}, ['']]
|
|
80
79
|
}
|
|
81
80
|
api = lambda { |env|
|
|
82
|
-
spooky =
|
|
81
|
+
spooky = env['QUERY_STRING'].match?(/spooky/)
|
|
83
82
|
[spooky ? 200 : 404, {
|
|
84
83
|
'X-API' => spooky,
|
|
85
84
|
'X-ScriptName' => env['SCRIPT_NAME'],
|
|
86
85
|
'X-PathInfo' => env['PATH_INFO'],
|
|
87
86
|
'Content-Type' => 'application/json'
|
|
88
|
-
}, [
|
|
87
|
+
}, ['']]
|
|
89
88
|
}
|
|
90
89
|
map = Padrino::Router.new(
|
|
91
|
-
{ :
|
|
92
|
-
{ :
|
|
90
|
+
{ path: '/bar', to: api },
|
|
91
|
+
{ path: '/bar', to: app }
|
|
93
92
|
)
|
|
94
93
|
|
|
95
|
-
res = Rack::MockRequest.new(map).get(
|
|
94
|
+
res = Rack::MockRequest.new(map).get('/werewolf')
|
|
96
95
|
assert_equal 404, res.status
|
|
97
|
-
refute_includes res,
|
|
98
|
-
refute_includes res,
|
|
99
|
-
refute_includes res,
|
|
96
|
+
refute_includes res, 'X-API'
|
|
97
|
+
refute_includes res, 'X-ScriptName'
|
|
98
|
+
refute_includes res, 'X-PathInfo'
|
|
100
99
|
|
|
101
|
-
res = Rack::MockRequest.new(map).get(
|
|
100
|
+
res = Rack::MockRequest.new(map).get('/bar/mitzvah')
|
|
102
101
|
assert res.ok?
|
|
103
|
-
refute_includes res,
|
|
104
|
-
assert_equal 'text/plain', res[
|
|
105
|
-
assert_equal
|
|
106
|
-
assert_equal
|
|
102
|
+
refute_includes res, 'X-API'
|
|
103
|
+
assert_equal 'text/plain', res['Content-Type']
|
|
104
|
+
assert_equal '/bar', res['X-ScriptName']
|
|
105
|
+
assert_equal '/mitzvah', res['X-PathInfo']
|
|
107
106
|
|
|
108
|
-
res = Rack::MockRequest.new(map).get(
|
|
107
|
+
res = Rack::MockRequest.new(map).get('/bar?spooky')
|
|
109
108
|
assert res.ok?
|
|
110
|
-
|
|
111
|
-
assert_equal 'application/json', res[
|
|
112
|
-
assert_equal
|
|
113
|
-
assert_equal
|
|
109
|
+
assert res['X-API']
|
|
110
|
+
assert_equal 'application/json', res['Content-Type']
|
|
111
|
+
assert_equal '/bar', res['X-ScriptName']
|
|
112
|
+
assert_equal '/', res['X-PathInfo']
|
|
114
113
|
|
|
115
|
-
res = Rack::MockRequest.new(map).get(
|
|
114
|
+
res = Rack::MockRequest.new(map).get('/bar/scary')
|
|
116
115
|
assert_equal 404, res.status
|
|
117
|
-
refute_includes res,
|
|
118
|
-
assert_equal 'text/plain', res[
|
|
119
|
-
assert_equal
|
|
120
|
-
assert_equal
|
|
116
|
+
refute_includes res, 'X-API'
|
|
117
|
+
assert_equal 'text/plain', res['Content-Type']
|
|
118
|
+
assert_equal '/bar', res['X-ScriptName']
|
|
119
|
+
assert_equal '/scary', res['X-PathInfo']
|
|
121
120
|
end
|
|
122
121
|
|
|
123
122
|
it 'should dispatch requests to cascade mounted apps and not cascade ok statuses' do
|
|
124
|
-
|
|
125
123
|
api = mock_app do
|
|
126
|
-
get
|
|
127
|
-
"1"
|
|
128
|
-
end
|
|
124
|
+
get('scary') { '1' }
|
|
129
125
|
set :cascade, true
|
|
130
126
|
end
|
|
131
127
|
|
|
132
128
|
app = mock_app do
|
|
133
|
-
get
|
|
134
|
-
"2"
|
|
135
|
-
end
|
|
129
|
+
get('scary') { '2' }
|
|
136
130
|
set :cascade, false
|
|
137
131
|
end
|
|
138
132
|
|
|
139
133
|
app2 = mock_app do
|
|
140
|
-
get
|
|
141
|
-
""
|
|
142
|
-
end
|
|
134
|
+
get('terrifying') { '' }
|
|
143
135
|
end
|
|
144
136
|
|
|
145
137
|
map = Padrino::Router.new(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
138
|
+
{ path: '/bar', to: api },
|
|
139
|
+
{ path: '/bar', to: app },
|
|
140
|
+
{ path: '/bar', to: app2 }
|
|
149
141
|
)
|
|
150
142
|
|
|
151
|
-
res = Rack::MockRequest.new(map).get(
|
|
143
|
+
res = Rack::MockRequest.new(map).get('/bar/scary')
|
|
152
144
|
assert res.ok?
|
|
153
|
-
#asserting that on ok we're good to go
|
|
154
|
-
assert_equal
|
|
155
|
-
|
|
156
|
-
res = Rack::MockRequest.new(map).get("/bar/terrifying")
|
|
157
|
-
assert !res.ok?
|
|
145
|
+
# asserting that on ok we're good to go
|
|
146
|
+
assert_equal '1', res.body
|
|
158
147
|
|
|
148
|
+
res = Rack::MockRequest.new(map).get('/bar/terrifying')
|
|
149
|
+
refute res.ok?
|
|
159
150
|
end
|
|
160
151
|
|
|
161
152
|
it 'should dispatch requests to cascade mounted apps until it sees a cascade == false or []g' do
|
|
162
153
|
app = mock_app do
|
|
163
|
-
get
|
|
164
|
-
""
|
|
165
|
-
end
|
|
154
|
+
get('scary') { '' }
|
|
166
155
|
set :cascade, []
|
|
167
156
|
end
|
|
168
157
|
|
|
169
158
|
app2 = mock_app do
|
|
170
|
-
get
|
|
171
|
-
""
|
|
172
|
-
end
|
|
159
|
+
get('terrifying') { '' }
|
|
173
160
|
end
|
|
174
161
|
|
|
175
162
|
map = Padrino::Router.new(
|
|
176
|
-
|
|
177
|
-
|
|
163
|
+
{ path: '/bar', to: app },
|
|
164
|
+
{ path: '/bar', to: app2 }
|
|
178
165
|
)
|
|
179
166
|
|
|
180
|
-
request_case =
|
|
181
|
-
Rack::MockRequest.new(map).get("/bar/terrifying")
|
|
182
|
-
}
|
|
167
|
+
request_case = -> { Rack::MockRequest.new(map).get('/bar/terrifying') }
|
|
183
168
|
|
|
184
169
|
app.cascade = false
|
|
185
|
-
|
|
170
|
+
refute request_case.call.ok?
|
|
186
171
|
|
|
187
172
|
app.cascade = true
|
|
188
173
|
assert request_case.call.ok?
|
|
189
174
|
end
|
|
190
175
|
|
|
191
176
|
it 'should dispatches hosts correctly' do
|
|
177
|
+
app = lambda do |position, env|
|
|
178
|
+
headers = {
|
|
179
|
+
'Content-Type' => 'text/plain',
|
|
180
|
+
'X-Host' => env['HTTP_HOST'] || env['SERVER_NAME'],
|
|
181
|
+
'X-Position' => position
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
[200, headers, ['']]
|
|
185
|
+
end.curry
|
|
186
|
+
|
|
192
187
|
map = Padrino::Router.new(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "bar.org")
|
|
214
|
-
assert res.not_found?
|
|
215
|
-
|
|
216
|
-
res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "at.bar.org")
|
|
217
|
-
assert res.ok?
|
|
218
|
-
assert_equal "bar.org", res["X-Position"]
|
|
219
|
-
|
|
220
|
-
res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "foo.org")
|
|
221
|
-
assert res.ok?
|
|
222
|
-
assert_equal "foo.org", res["X-Position"]
|
|
223
|
-
|
|
224
|
-
res = Rack::MockRequest.new(map).get("/", "HTTP_HOST" => "subdomain.foo.org", "SERVER_NAME" => "foo.org")
|
|
225
|
-
assert res.ok?
|
|
226
|
-
assert_equal "subdomain.foo.org", res["X-Position"]
|
|
188
|
+
{ host: 'foo.org', to: app['foo.org'] },
|
|
189
|
+
{ host: 'subdomain.foo.org', to: app['subdomain.foo.org'] },
|
|
190
|
+
{ host: /.*\.bar.org/, to: app['bar.org'] }
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
res = Rack::MockRequest.new(map).get('/', 'HTTP_HOST' => 'bar.org')
|
|
194
|
+
assert res.not_found?
|
|
195
|
+
|
|
196
|
+
res = Rack::MockRequest.new(map).get('/', 'HTTP_HOST' => 'at.bar.org')
|
|
197
|
+
assert res.ok?
|
|
198
|
+
assert_equal 'bar.org', res['X-Position']
|
|
199
|
+
|
|
200
|
+
res = Rack::MockRequest.new(map).get('/', 'HTTP_HOST' => 'foo.org')
|
|
201
|
+
assert res.ok?
|
|
202
|
+
assert_equal 'foo.org', res['X-Position']
|
|
203
|
+
|
|
204
|
+
res = Rack::MockRequest.new(map).get('/', 'HTTP_HOST' => 'subdomain.foo.org', 'SERVER_NAME' => 'foo.org')
|
|
205
|
+
assert res.ok?
|
|
206
|
+
assert_equal 'subdomain.foo.org', res['X-Position']
|
|
227
207
|
end
|
|
228
208
|
|
|
229
209
|
it 'should works with padrino core applications' do
|
|
230
|
-
Padrino.mount(
|
|
231
|
-
assert_equal [
|
|
232
|
-
assert_equal [
|
|
210
|
+
Padrino.mount('simple_demo').host('padrino.org')
|
|
211
|
+
assert_equal ['simple_demo'], Padrino.mounted_apps.map(&:name)
|
|
212
|
+
assert_equal ['padrino.org'], Padrino.mounted_apps.map(&:app_host)
|
|
233
213
|
|
|
234
|
-
res = Rack::MockRequest.new(Padrino.application).get(
|
|
214
|
+
res = Rack::MockRequest.new(Padrino.application).get('/')
|
|
235
215
|
assert res.not_found?
|
|
236
216
|
|
|
237
|
-
res = Rack::MockRequest.new(Padrino.application).get(
|
|
217
|
+
res = Rack::MockRequest.new(Padrino.application).get('/', 'HTTP_HOST' => 'bar.org')
|
|
238
218
|
assert res.not_found?
|
|
239
219
|
|
|
240
|
-
res = Rack::MockRequest.new(Padrino.application).get(
|
|
220
|
+
res = Rack::MockRequest.new(Padrino.application).get('/', 'HTTP_HOST' => 'padrino.org')
|
|
241
221
|
assert res.ok?
|
|
242
222
|
end
|
|
243
223
|
|
|
244
224
|
it 'should works with padrino applications' do
|
|
245
|
-
Padrino.mount(
|
|
225
|
+
Padrino.mount('simple_demo').to('/foo').host(/.*\.padrino.org/)
|
|
246
226
|
|
|
247
|
-
res = Rack::MockRequest.new(Padrino.application).get(
|
|
227
|
+
res = Rack::MockRequest.new(Padrino.application).get('/')
|
|
248
228
|
assert res.not_found?
|
|
249
229
|
|
|
250
|
-
res = Rack::MockRequest.new(Padrino.application).get(
|
|
230
|
+
res = Rack::MockRequest.new(Padrino.application).get('/', 'HTTP_HOST' => 'bar.org')
|
|
251
231
|
assert res.not_found?
|
|
252
232
|
|
|
253
|
-
res = Rack::MockRequest.new(Padrino.application).get(
|
|
233
|
+
res = Rack::MockRequest.new(Padrino.application).get('/', 'HTTP_HOST' => 'padrino.org')
|
|
254
234
|
assert res.not_found?
|
|
255
235
|
|
|
256
|
-
res = Rack::MockRequest.new(Padrino.application).get(
|
|
236
|
+
res = Rack::MockRequest.new(Padrino.application).get('/none', 'HTTP_HOST' => 'foo.padrino.org')
|
|
257
237
|
assert res.not_found?
|
|
258
238
|
|
|
259
|
-
res = Rack::MockRequest.new(Padrino.application).get(
|
|
239
|
+
res = Rack::MockRequest.new(Padrino.application).get('/foo', 'HTTP_HOST' => 'bar.padrino.org')
|
|
260
240
|
assert res.ok?
|
|
261
241
|
|
|
262
|
-
res = Rack::MockRequest.new(Padrino.application).get(
|
|
242
|
+
res = Rack::MockRequest.new(Padrino.application).get('/foo/', 'HTTP_HOST' => 'bar.padrino.org')
|
|
263
243
|
assert res.ok?
|
|
264
244
|
end
|
|
265
245
|
|
|
266
246
|
it 'should keep the same environment object' do
|
|
267
|
-
app = lambda
|
|
247
|
+
app = lambda do |env|
|
|
268
248
|
env['path'] = env['PATH_INFO']
|
|
269
|
-
[200, {'Content-Type' => 'text/plain'}, [
|
|
270
|
-
|
|
249
|
+
[200, { 'Content-Type' => 'text/plain' }, ['']]
|
|
250
|
+
end
|
|
251
|
+
|
|
271
252
|
map = Padrino::Router.new(
|
|
272
|
-
{ :
|
|
273
|
-
{ :
|
|
274
|
-
{ :
|
|
253
|
+
{ path: '/bar', to: app },
|
|
254
|
+
{ path: '/foo/bar', to: app },
|
|
255
|
+
{ path: '/foo', to: app }
|
|
275
256
|
)
|
|
276
257
|
|
|
277
|
-
env = Rack::MockRequest.env_for(
|
|
258
|
+
env = Rack::MockRequest.env_for('/bar/foo')
|
|
278
259
|
map.call(env)
|
|
279
|
-
assert_equal
|
|
260
|
+
assert_equal '/foo', env['path']
|
|
280
261
|
end
|
|
281
262
|
end
|