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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +8 -8
  3. data/Rakefile +1 -1
  4. data/bin/padrino +1 -1
  5. data/lib/padrino-core/application/application_setup.rb +28 -26
  6. data/lib/padrino-core/application/authenticity_token.rb +3 -2
  7. data/lib/padrino-core/application/flash.rb +4 -5
  8. data/lib/padrino-core/application/params_protection.rb +34 -37
  9. data/lib/padrino-core/application/routing.rb +165 -164
  10. data/lib/padrino-core/application/show_exceptions.rb +5 -7
  11. data/lib/padrino-core/application.rb +4 -4
  12. data/lib/padrino-core/caller.rb +6 -7
  13. data/lib/padrino-core/cli/adapter.rb +4 -4
  14. data/lib/padrino-core/cli/base.rb +31 -32
  15. data/lib/padrino-core/cli/binstub.rb +9 -8
  16. data/lib/padrino-core/cli/console.rb +1 -1
  17. data/lib/padrino-core/cli/launcher.rb +45 -42
  18. data/lib/padrino-core/cli/rake.rb +16 -14
  19. data/lib/padrino-core/cli/rake_tasks.rb +18 -20
  20. data/lib/padrino-core/command.rb +1 -1
  21. data/lib/padrino-core/ext/sinatra.rb +3 -2
  22. data/lib/padrino-core/filter.rb +3 -3
  23. data/lib/padrino-core/loader.rb +10 -12
  24. data/lib/padrino-core/logger.rb +85 -77
  25. data/lib/padrino-core/mounter/application_extension.rb +2 -2
  26. data/lib/padrino-core/mounter.rb +33 -34
  27. data/lib/padrino-core/path_router/compiler.rb +8 -8
  28. data/lib/padrino-core/path_router/matcher.rb +11 -11
  29. data/lib/padrino-core/path_router/route.rb +15 -15
  30. data/lib/padrino-core/path_router.rb +4 -3
  31. data/lib/padrino-core/reloader/rack.rb +1 -1
  32. data/lib/padrino-core/reloader/storage.rb +12 -11
  33. data/lib/padrino-core/reloader.rb +18 -19
  34. data/lib/padrino-core/router.rb +14 -14
  35. data/lib/padrino-core/server.rb +20 -24
  36. data/lib/padrino-core/tasks.rb +0 -1
  37. data/lib/padrino-core/version.rb +1 -1
  38. data/lib/padrino-core.rb +9 -10
  39. data/padrino-core.gemspec +18 -18
  40. data/test/fixtures/app_gem/app_gem.gemspec +8 -7
  41. data/test/fixtures/app_gem/lib/app_gem/version.rb +1 -1
  42. data/test/fixtures/apps/complex.rb +6 -6
  43. data/test/fixtures/apps/concerned/app.rb +1 -1
  44. data/test/fixtures/apps/custom_dependencies/custom_dependencies.rb +3 -3
  45. data/test/fixtures/apps/demo_app.rb +1 -1
  46. data/test/fixtures/apps/demo_demo.rb +1 -1
  47. data/test/fixtures/apps/demo_project/api/app.rb +1 -1
  48. data/test/fixtures/apps/demo_project/app.rb +1 -1
  49. data/test/fixtures/apps/helpers/class_methods_helpers.rb +1 -0
  50. data/test/fixtures/apps/helpers/instance_methods_helpers.rb +1 -0
  51. data/test/fixtures/apps/helpers/system_helpers.rb +0 -1
  52. data/test/fixtures/apps/lib/myklass/mysubklass.rb +2 -2
  53. data/test/fixtures/apps/mountable_apps/rack_apps.rb +7 -7
  54. data/test/fixtures/apps/precompiled_app.rb +6 -5
  55. data/test/fixtures/apps/simple.rb +5 -5
  56. data/test/fixtures/apps/static.rb +2 -2
  57. data/test/fixtures/apps/stealthy/app.rb +1 -1
  58. data/test/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb +1 -1
  59. data/test/fixtures/apps/system.rb +1 -1
  60. data/test/fixtures/apps/system_class_methods_demo.rb +1 -1
  61. data/test/fixtures/apps/system_instance_methods_demo.rb +1 -1
  62. data/test/fixtures/dependencies/a.rb +1 -1
  63. data/test/fixtures/dependencies/b.rb +1 -1
  64. data/test/fixtures/dependencies/c.rb +1 -1
  65. data/test/fixtures/dependencies/circular/e.rb +2 -1
  66. data/test/fixtures/dependencies/d.rb +1 -1
  67. data/test/fixtures/dependencies/linear/i.rb +1 -1
  68. data/test/fixtures/dependencies/nested/l.rb +2 -2
  69. data/test/fixtures/dependencies/nested/m.rb +1 -1
  70. data/test/fixtures/dependencies/nested/qqq.rb +2 -2
  71. data/test/fixtures/dependencies/nested/rrr.rb +1 -1
  72. data/test/fixtures/dependencies/nested/sss.rb +1 -1
  73. data/test/fixtures/reloadable_apps/external/app/app.rb +0 -1
  74. data/test/fixtures/reloadable_apps/external/app/controllers/base.rb +1 -2
  75. data/test/fixtures/reloadable_apps/main/app.rb +2 -2
  76. data/test/helper.rb +2 -2
  77. data/test/test_application.rb +59 -60
  78. data/test/test_configuration.rb +2 -2
  79. data/test/test_core.rb +13 -13
  80. data/test/test_csrf_protection.rb +67 -63
  81. data/test/test_dependencies.rb +33 -34
  82. data/test/test_filters.rb +46 -47
  83. data/test/test_flash.rb +14 -14
  84. data/test/test_locale.rb +2 -2
  85. data/test/test_logger.rb +64 -64
  86. data/test/test_mounter.rb +133 -123
  87. data/test/test_params_protection.rb +40 -40
  88. data/test/test_reloader_complex.rb +23 -23
  89. data/test/test_reloader_external.rb +10 -10
  90. data/test/test_reloader_simple.rb +26 -23
  91. data/test/test_reloader_storage.rb +9 -12
  92. data/test/test_reloader_system.rb +29 -29
  93. data/test/test_restful_routing.rb +19 -19
  94. data/test/test_router.rb +126 -145
  95. data/test/test_routing.rb +882 -894
  96. metadata +6 -6
@@ -1,10 +1,10 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/kiq')
3
- require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/system')
4
- require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/static')
5
- require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/custom_dependencies/custom_dependencies')
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 "SystemReloader" do
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(File.dirname(__FILE__) + '/fixtures/apps/models/parent.rb')
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, "w") { |f| f.write(new_class) }
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, "w") { |f| f.write(backup) }
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("kiq").to("/")
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, "w") { |f| f.write(new_class) }
71
+ File.open(tmp_file, 'w') { |f| f.write(new_class) }
72
72
  Padrino.clear!
73
- require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/system_class_methods_demo.rb')
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(File.dirname(__FILE__) + '/fixtures/apps/helpers/class_methods_helpers.rb')
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, "w") { |f| f.write(new_class) }
97
+ File.open(tmp_file, 'w') { |f| f.write(new_class) }
98
98
  Padrino.clear!
99
- require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/system_instance_methods_demo.rb')
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(File.dirname(__FILE__) + '/fixtures/apps/helpers/instance_methods_helpers.rb')
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(File.dirname(__FILE__) + '/fixtures/apps/stealthy/app.rb')
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(File.dirname(__FILE__) + '/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb')
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) { File.dirname(__FILE__) + '/fixtures/apps/custom_dependencies/my_dependencies' }
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 + '/*.rb'
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(File.dirname(__FILE__) + '/fixtures/apps/concerned/app.rb')
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 File.dirname(__FILE__) + '/fixtures/apps/concerned/models/mixins/badmodule.rb'
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
- require File.expand_path(File.dirname(__FILE__) + '/helper')
1
+ require_relative 'helper'
2
2
 
3
- describe "Routing" do
3
+ describe 'Routing' do
4
4
  it 'should perform restul routing' do
5
5
  mock_app do
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"
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, :with => :asset_id do
12
- "#{url_for(:index, params[:parent_id], :asset_id => params[:asset_id])} put"
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, :with => :asset_id do
16
- "#{url_for(:index, :parent_id => params[:parent_id], :asset_id => params[:asset_id])} post"
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, :with => :asset_id do
20
- "#{url_for(:index, params[:parent_id], :asset_id => params[:asset_id])} delete"
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 "/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
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
- require File.expand_path(File.dirname(__FILE__) + '/helper')
2
- require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/simple')
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
- { :path => '/bar', :to => app },
20
- { :path => '/foo/bar', :to => app },
21
- { :path => '/foo', :to => app }
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("/qux")
26
+ res = Rack::MockRequest.new(map).get('/qux')
28
27
  assert res.not_found?
29
28
 
30
- res = Rack::MockRequest.new(map).get("/foo")
29
+ res = Rack::MockRequest.new(map).get('/foo')
31
30
  assert res.ok?
32
- assert_equal "/foo", res["X-ScriptName"]
33
- assert_equal "/", res["X-PathInfo"]
31
+ assert_equal '/foo', res['X-ScriptName']
32
+ assert_equal '/', res['X-PathInfo']
34
33
 
35
- res = Rack::MockRequest.new(map).get("/foo/")
34
+ res = Rack::MockRequest.new(map).get('/foo/')
36
35
  assert res.ok?
37
- assert_equal "/foo", res["X-ScriptName"]
38
- assert_equal "/", res["X-PathInfo"]
36
+ assert_equal '/foo', res['X-ScriptName']
37
+ assert_equal '/', res['X-PathInfo']
39
38
 
40
- res = Rack::MockRequest.new(map).get("/foo/bar")
39
+ res = Rack::MockRequest.new(map).get('/foo/bar')
41
40
  assert res.ok?
42
- assert_equal "/foo/bar", res["X-ScriptName"]
43
- assert_equal "/", res["X-PathInfo"]
41
+ assert_equal '/foo/bar', res['X-ScriptName']
42
+ assert_equal '/', res['X-PathInfo']
44
43
 
45
- res = Rack::MockRequest.new(map).get("/foo/bar/")
44
+ res = Rack::MockRequest.new(map).get('/foo/bar/')
46
45
  assert res.ok?
47
- assert_equal "/foo/bar", res["X-ScriptName"]
48
- assert_equal "/", res["X-PathInfo"]
46
+ assert_equal '/foo/bar', res['X-ScriptName']
47
+ assert_equal '/', res['X-PathInfo']
49
48
 
50
- res = Rack::MockRequest.new(map).get("/foo///bar//quux")
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 "/foo/bar", res["X-ScriptName"]
54
- assert_equal "//quux", res["X-PathInfo"]
52
+ assert_equal '/foo/bar', res['X-ScriptName']
53
+ assert_equal '//quux', res['X-PathInfo']
55
54
 
56
- res = Rack::MockRequest.new(map).get("/foo/quux", "SCRIPT_NAME" => "/bleh")
55
+ res = Rack::MockRequest.new(map).get('/foo/quux', 'SCRIPT_NAME' => '/bleh')
57
56
  assert res.ok?
58
- assert_equal "/bleh/foo", res["X-ScriptName"]
59
- assert_equal "/quux", res["X-PathInfo"]
57
+ assert_equal '/bleh/foo', res['X-ScriptName']
58
+ assert_equal '/quux', res['X-PathInfo']
60
59
 
61
- res = Rack::MockRequest.new(map).get("/bar", 'HTTP_HOST' => 'foo.org')
60
+ res = Rack::MockRequest.new(map).get('/bar', 'HTTP_HOST' => 'foo.org')
62
61
  assert res.ok?
63
- assert_equal "/bar", res["X-ScriptName"]
64
- assert_equal "/", res["X-PathInfo"]
62
+ assert_equal '/bar', res['X-ScriptName']
63
+ assert_equal '/', res['X-PathInfo']
65
64
 
66
- res = Rack::MockRequest.new(map).get("/bar/", 'HTTP_HOST' => 'foo.org')
65
+ res = Rack::MockRequest.new(map).get('/bar/', 'HTTP_HOST' => 'foo.org')
67
66
  assert res.ok?
68
- assert_equal "/bar", res["X-ScriptName"]
69
- assert_equal "/", res["X-PathInfo"]
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 = !!env['PATH_INFO'].match(/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 = !!env['QUERY_STRING'].match(/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
- { :path => '/bar', :to => api },
92
- { :path => '/bar', :to => app }
90
+ { path: '/bar', to: api },
91
+ { path: '/bar', to: app }
93
92
  )
94
93
 
95
- res = Rack::MockRequest.new(map).get("/werewolf")
94
+ res = Rack::MockRequest.new(map).get('/werewolf')
96
95
  assert_equal 404, res.status
97
- refute_includes res, "X-API"
98
- refute_includes res, "X-ScriptName"
99
- refute_includes res, "X-PathInfo"
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("/bar/mitzvah")
100
+ res = Rack::MockRequest.new(map).get('/bar/mitzvah')
102
101
  assert res.ok?
103
- refute_includes res, "X-API"
104
- assert_equal 'text/plain', res["Content-Type"]
105
- assert_equal "/bar", res["X-ScriptName"]
106
- assert_equal "/mitzvah", res["X-PathInfo"]
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("/bar?spooky")
107
+ res = Rack::MockRequest.new(map).get('/bar?spooky')
109
108
  assert res.ok?
110
- assert_equal true, res["X-API"]
111
- assert_equal 'application/json', res["Content-Type"]
112
- assert_equal "/bar", res["X-ScriptName"]
113
- assert_equal "/", res["X-PathInfo"]
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("/bar/scary")
114
+ res = Rack::MockRequest.new(map).get('/bar/scary')
116
115
  assert_equal 404, res.status
117
- refute_includes res, "X-API"
118
- assert_equal 'text/plain', res["Content-Type"]
119
- assert_equal "/bar", res["X-ScriptName"]
120
- assert_equal "/scary", res["X-PathInfo"]
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 'scary' do
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 'scary' do
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 'terrifying' do
141
- ""
142
- end
134
+ get('terrifying') { '' }
143
135
  end
144
136
 
145
137
  map = Padrino::Router.new(
146
- { :path => '/bar', :to => api },
147
- { :path => '/bar', :to => app },
148
- { :path => '/bar', :to => app2 }
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("/bar/scary")
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 "1", res.body
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 'scary' do
164
- ""
165
- end
154
+ get('scary') { '' }
166
155
  set :cascade, []
167
156
  end
168
157
 
169
158
  app2 = mock_app do
170
- get 'terrifying' do
171
- ""
172
- end
159
+ get('terrifying') { '' }
173
160
  end
174
161
 
175
162
  map = Padrino::Router.new(
176
- { :path => '/bar', :to => app },
177
- { :path => '/bar', :to => app2 }
163
+ { path: '/bar', to: app },
164
+ { path: '/bar', to: app2 }
178
165
  )
179
166
 
180
- request_case = lambda {
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
- assert !request_case.call.ok?
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
- { :host => "foo.org", :to => lambda { |env|
194
- [200,
195
- { "Content-Type" => "text/plain",
196
- "X-Position" => "foo.org",
197
- "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"],
198
- }, [""]]}},
199
- { :host => "subdomain.foo.org", :to => lambda { |env|
200
- [200,
201
- { "Content-Type" => "text/plain",
202
- "X-Position" => "subdomain.foo.org",
203
- "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"],
204
- }, [""]]}},
205
- { :host => /.*\.bar.org/, :to => lambda { |env|
206
- [200,
207
- { "Content-Type" => "text/plain",
208
- "X-Position" => "bar.org",
209
- "X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"],
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("simple_demo").host("padrino.org")
231
- assert_equal ["simple_demo"], Padrino.mounted_apps.map(&:name)
232
- assert_equal ["padrino.org"], Padrino.mounted_apps.map(&:app_host)
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("/", "HTTP_HOST" => "bar.org")
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("/", "HTTP_HOST" => "padrino.org")
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("simple_demo").to("/foo").host(/.*\.padrino.org/)
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("/", "HTTP_HOST" => "bar.org")
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("/", "HTTP_HOST" => "padrino.org")
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("/none", "HTTP_HOST" => "foo.padrino.org")
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("/foo", "HTTP_HOST" => "bar.padrino.org")
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("/foo/", "HTTP_HOST" => "bar.padrino.org")
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 { |env|
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
- { :path => '/bar', :to => app },
273
- { :path => '/foo/bar', :to => app },
274
- { :path => '/foo', :to => app }
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("/bar/foo")
258
+ env = Rack::MockRequest.env_for('/bar/foo')
278
259
  map.call(env)
279
- assert_equal "/foo", env["path"]
260
+ assert_equal '/foo', env['path']
280
261
  end
281
262
  end