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,4 +1,4 @@
1
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
1
+ PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
2
2
 
3
3
  module LibDemo
4
4
  def self.give_me_a_random
@@ -8,22 +8,22 @@ end
8
8
 
9
9
  class Complex1Demo < Padrino::Application
10
10
  set :reload, true
11
- get("/old"){ "Old Sinatra Way" }
11
+ get('/old') { 'Old Sinatra Way' }
12
12
  end
13
13
 
14
14
  class Complex2Demo < Padrino::Application
15
15
  set :reload, true
16
- get("/old"){ "Old Sinatra Way" }
16
+ get('/old') { 'Old Sinatra Way' }
17
17
 
18
18
  controllers :var do
19
- get(:destroy){ params.to_json }
19
+ get(:destroy) { params.to_json }
20
20
  end
21
21
 
22
- get("/"){ "The magick number is: 12!" } # Change only the number!!!
22
+ get('/') { 'The magick number is: 12!' } # Change only the number!!!
23
23
  end
24
24
 
25
25
  Complex1Demo.controllers do
26
- get("/"){ "Given random #{LibDemo.give_me_a_random}" }
26
+ get('/') { "Given random #{LibDemo.give_me_a_random}" }
27
27
  end
28
28
 
29
29
  Complex2Demo.controllers do
@@ -1,4 +1,4 @@
1
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
1
+ PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
2
2
 
3
3
  class SystemConcernedClassDemo < Padrino::Application
4
4
  set :reload, true
@@ -1,11 +1,11 @@
1
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
1
+ PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
2
2
 
3
3
  class CustomDependencies < Padrino::Application
4
4
  set :reload, true
5
5
  end
6
6
 
7
7
  CustomDependencies.controllers do
8
- get "/" do
9
- "foo"
8
+ get '/' do
9
+ 'foo'
10
10
  end
11
11
  end
@@ -1,4 +1,4 @@
1
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
1
+ PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
2
2
 
3
3
  module Demo
4
4
  class App < Padrino::Application
@@ -1,4 +1,4 @@
1
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
1
+ PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
2
2
 
3
3
  module Demo
4
4
  class Demo < Padrino::Application
@@ -1,7 +1,7 @@
1
1
  module DemoProject
2
2
  class API
3
3
  def self.call(_)
4
- [200, {}, ["api app"]]
4
+ [200, {}, ['api app']]
5
5
  end
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module DemoProject
2
2
  class App < Padrino::Application
3
3
  get :index do
4
- "padrino app"
4
+ 'padrino app'
5
5
  end
6
6
  end
7
7
  end
@@ -1,4 +1,5 @@
1
1
  begin
2
2
  require '/tmp/padrino_class_demo'
3
3
  rescue LoadError
4
+ # do nothing
4
5
  end
@@ -1,4 +1,5 @@
1
1
  begin
2
2
  require '/tmp/padrino_instance_demo'
3
3
  rescue LoadError
4
+ # do nothing
4
5
  end
@@ -5,4 +5,3 @@ SystemDemo.helpers do
5
5
  Resolv.name
6
6
  end
7
7
  end
8
-
@@ -1,4 +1,4 @@
1
1
  class MyKlass
2
- class MySubKlass
3
- end
2
+ class MySubKlass
3
+ end
4
4
  end
@@ -1,10 +1,9 @@
1
-
2
1
  class RackApp
3
2
  def self.call(env)
4
3
  if env['PATH_INFO'] == '/404'
5
- [404, {}, ["not found ;("]]
4
+ [404, {}, ['not found ;(']]
6
5
  else
7
- [200, {}, ["hello rack app"]]
6
+ [200, {}, ['hello rack app']]
8
7
  end
9
8
  end
10
9
 
@@ -13,11 +12,12 @@ class RackApp
13
12
  end
14
13
  end
15
14
 
16
- RackApp2 = ->(_){ [200, {}, ["hello rack app2"]] }
15
+ RackApp2 = ->(_) { [200, {}, ['hello rack app2']] }
17
16
 
18
17
  class SinatraApp < Sinatra::Base
19
- set :public_folder, File.dirname(__FILE__)
20
- get "/" do
21
- "hello sinatra app"
18
+ set :public_folder, __dir__
19
+
20
+ get '/' do
21
+ 'hello sinatra app'
22
22
  end
23
23
  end
@@ -1,4 +1,4 @@
1
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
1
+ PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
2
2
 
3
3
  Padrino.configure_apps do
4
4
  set :precompile_routes, true
@@ -6,14 +6,15 @@ end
6
6
 
7
7
  module PrecompiledApp
8
8
  class App < Padrino::Application
9
- 10.times{|n| get("/#{n}"){} }
9
+ 10.times { |n| get("/#{n}") {} }
10
10
  end
11
+
11
12
  class SubApp < Padrino::Application
12
- 10.times{|n| get("/#{n}"){} }
13
+ 10.times { |n| get("/#{n}") {} }
13
14
  end
14
15
  end
15
16
 
16
- Padrino.mount("PrecompiledApp::SubApp").to("/subapp")
17
- Padrino.mount("PrecompiledApp::App").to("/")
17
+ Padrino.mount('PrecompiledApp::SubApp').to('/subapp')
18
+ Padrino.mount('PrecompiledApp::App').to('/')
18
19
 
19
20
  Padrino.load!
@@ -1,4 +1,4 @@
1
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
1
+ PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
2
2
  # Remove this comment if you want do some like this: ruby RACK_ENV=test app.rb
3
3
  #
4
4
  # require 'padrino-core'
@@ -8,16 +8,16 @@ class SimpleDemo < Padrino::Application
8
8
  set :reload, true
9
9
  before { true }
10
10
  after { true }
11
- error(404) { "404" }
11
+ error(404) { '404' }
12
12
  end
13
13
 
14
14
  SimpleDemo.controllers do
15
- get "/" do
15
+ get '/' do
16
16
  'The magick number is: 2767356926488785838763860464013972991031534522105386787489885890443740254365!' # Change only the number!!!
17
17
  end
18
18
 
19
- get "/rand" do
20
- rand(2 ** 256).to_s
19
+ get '/rand' do
20
+ rand(2**256).to_s
21
21
  end
22
22
  end
23
23
 
@@ -1,9 +1,9 @@
1
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
1
+ PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
2
2
 
3
3
  class StaticDemo < Padrino::Application
4
4
  disable :reload
5
5
  def self.reload!
6
- fail 'reload! called'
6
+ raise 'reload! called'
7
7
  end
8
8
  end
9
9
 
@@ -1,4 +1,4 @@
1
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
1
+ PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
2
2
 
3
3
  class SystemStealthyClassDemo < Padrino::Application
4
4
  set :reload, true
@@ -1,6 +1,6 @@
1
1
  class Boo
2
2
  def self.class_method
3
- "BooClass"
3
+ 'BooClass'
4
4
  end
5
5
  end
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
3
+ PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
4
4
 
5
5
  class SystemDemo < Padrino::Application
6
6
  set :reload, true
@@ -1,4 +1,4 @@
1
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
1
+ PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
2
2
 
3
3
  class SystemClassMethodsDemo < Padrino::Application
4
4
  set :reload, true
@@ -1,4 +1,4 @@
1
- PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
1
+ PADRINO_ROOT = __dir__ unless defined? PADRINO_ROOT
2
2
 
3
3
  class SystemInstanceMethodsDemo < Padrino::Application
4
4
  set :reload, true
@@ -6,4 +6,4 @@
6
6
  # But here we need some of b.rb
7
7
  A_result = [B, C]
8
8
 
9
- A = "A"
9
+ A = 'A'
@@ -1,4 +1,4 @@
1
1
  # But here we need some of c.rb and a.rb
2
2
  B_result = C
3
3
 
4
- B = "B"
4
+ B = 'B'
@@ -1 +1 @@
1
- C = "C"
1
+ C = 'C'
@@ -4,8 +4,9 @@ class E
4
4
  end
5
5
 
6
6
  def self.inherited(subclass)
7
+ super
7
8
  subclass.fields.replace fields.dup
8
9
  end
9
10
 
10
- fields << "name"
11
+ fields << 'name'
11
12
  end
@@ -1,4 +1,4 @@
1
1
  D = 0 unless defined?(D)
2
2
  D += 1
3
3
 
4
- raise "SomeThing"
4
+ raise 'SomeThing'
@@ -1 +1 @@
1
- fail
1
+ raise
@@ -1,4 +1,4 @@
1
1
  Padrino.require_dependencies(
2
- Padrino.root("fixtures/dependencies/nested/m.rb"),
3
- Padrino.root("fixtures/dependencies/nested/n.rb")
2
+ Padrino.root('fixtures/dependencies/nested/m.rb'),
3
+ Padrino.root('fixtures/dependencies/nested/n.rb')
4
4
  )
@@ -1,5 +1,5 @@
1
1
  class M
2
2
  def self.hello
3
- "hello"
3
+ 'hello'
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
1
  Padrino.require_dependencies(
2
- Padrino.root("fixtures/dependencies/nested/rrr.rb"),
3
- Padrino.root("fixtures/dependencies/nested/sss.rb")
2
+ Padrino.root('fixtures/dependencies/nested/rrr.rb'),
3
+ Padrino.root('fixtures/dependencies/nested/sss.rb')
4
4
  )
@@ -1,5 +1,5 @@
1
1
  class RRR
2
2
  def self.hello
3
- "hello"
3
+ 'hello'
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  class RollbackTarget
2
2
  def self.hello
3
- "hello"
3
+ 'hello'
4
4
  end
5
5
  end
6
6
 
@@ -1,4 +1,3 @@
1
-
2
1
  module ReloadableApp
3
2
  class External < Padrino::Application
4
3
  set :reload, true
@@ -1,6 +1,5 @@
1
-
2
1
  ReloadableApp::External.controller :base do
3
2
  get :index do
4
- "Hello External App"
3
+ 'Hello External App'
5
4
  end
6
5
  end
@@ -1,10 +1,10 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../external/app/app')
1
+ require_relative '../external/app/app'
2
2
 
3
3
  module ReloadableApp
4
4
  class Main < Padrino::Application
5
5
  set :reload, true
6
6
  get :index do
7
- "hey"
7
+ 'hey'
8
8
  end
9
9
  end
10
10
  end
data/test/helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  ENV['RACK_ENV'] = 'test'
2
- PADRINO_ROOT = File.dirname(__FILE__) unless defined?(PADRINO_ROOT)
2
+ PADRINO_ROOT = __dir__ unless defined?(PADRINO_ROOT)
3
3
 
4
4
  require 'minitest/autorun'
5
5
  require 'minitest/pride'
@@ -19,7 +19,7 @@ class Minitest::Spec
19
19
  # Sets up a Sinatra::Base subclass defined with the block
20
20
  # given. Used in setup or individual spec methods to establish
21
21
  # the application.
22
- def mock_app(base=Padrino::Application, &block)
22
+ def mock_app(base = Padrino::Application, &block)
23
23
  @app = Sinatra.new(base, &block)
24
24
  end
25
25
 
@@ -1,61 +1,60 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
1
+ require_relative 'helper'
2
2
 
3
3
  class PadrinoPristine < Padrino::Application; end
4
4
  class PadrinoTestApp < Padrino::Application; end
5
5
  class PadrinoTestApp2 < Padrino::Application; end
6
6
 
7
- describe "Application" do
7
+ describe 'Application' do
8
8
  before { Padrino.clear! }
9
9
 
10
10
  describe 'for application functionality' do
11
-
12
11
  it 'should check default options' do
13
12
  assert File.identical?(__FILE__, PadrinoPristine.app_file)
14
13
  assert_equal :padrino_pristine, PadrinoPristine.app_name
15
14
  assert_equal :test, PadrinoPristine.environment
16
15
  assert_equal Padrino.root('views'), PadrinoPristine.views
17
- assert PadrinoPristine.raise_errors
18
- assert !PadrinoPristine.logging
19
- assert !PadrinoPristine.sessions
20
- assert !PadrinoPristine.dump_errors
21
- assert !PadrinoPristine.show_exceptions
22
- assert PadrinoPristine.raise_errors
23
- assert !Padrino.configure_apps
16
+ assert PadrinoPristine.raise_errors
17
+ refute PadrinoPristine.logging
18
+ refute PadrinoPristine.sessions
19
+ refute PadrinoPristine.dump_errors
20
+ refute PadrinoPristine.show_exceptions
21
+ assert PadrinoPristine.raise_errors
22
+ refute Padrino.configure_apps
24
23
  end
25
24
 
26
25
  it 'should check padrino specific options' do
27
- assert !PadrinoPristine.instance_variable_get(:@_configured)
26
+ refute PadrinoPristine.instance_variable_get(:@_configured)
28
27
  PadrinoPristine.send(:setup_application!)
29
28
  assert_equal :padrino_pristine, PadrinoPristine.app_name
30
29
  assert_equal 'StandardFormBuilder', PadrinoPristine.default_builder
31
- assert PadrinoPristine.instance_variable_get(:@_configured)
32
- assert !PadrinoPristine.reload?
30
+ assert PadrinoPristine.instance_variable_get(:@_configured)
31
+ refute PadrinoPristine.reload?
33
32
  end
34
33
 
35
34
  it 'should set global project settings' do
36
- Padrino.configure_apps { enable :sessions; set :foo, "bar" }
35
+ Padrino.configure_apps { enable :sessions; set :foo, 'bar' }
37
36
  PadrinoTestApp.send(:default_configuration!)
38
37
  PadrinoTestApp2.send(:default_configuration!)
39
- assert PadrinoTestApp.sessions, "should have sessions enabled"
40
- assert_equal "bar", PadrinoTestApp.settings.foo, "should have foo assigned"
38
+ assert PadrinoTestApp.sessions, 'should have sessions enabled'
39
+ assert_equal 'bar', PadrinoTestApp.settings.foo, 'should have foo assigned'
41
40
  assert_equal PadrinoTestApp.session_secret, PadrinoTestApp2.session_secret
42
41
  end
43
42
 
44
43
  it 'should be able to configure_apps multiple times' do
45
- Padrino.configure_apps { set :foo1, "bar" }
46
- Padrino.configure_apps { set :foo1, "bam" }
47
- Padrino.configure_apps { set :foo2, "baz" }
44
+ Padrino.configure_apps { set :foo1, 'bar' }
45
+ Padrino.configure_apps { set :foo1, 'bam' }
46
+ Padrino.configure_apps { set :foo2, 'baz' }
48
47
  PadrinoTestApp.send(:default_configuration!)
49
- assert_equal "bam", PadrinoTestApp.settings.foo1, "should have foo1 assigned to bam"
50
- assert_equal "baz", PadrinoTestApp.settings.foo2, "should have foo2 assigned to baz"
48
+ assert_equal 'bam', PadrinoTestApp.settings.foo1, 'should have foo1 assigned to bam'
49
+ assert_equal 'baz', PadrinoTestApp.settings.foo2, 'should have foo2 assigned to baz'
51
50
  end
52
51
 
53
52
  it 'should have shared sessions accessible in project' do
54
53
  Padrino.configure_apps { enable :sessions; set :session_secret, PadrinoTestApp2.session_secret }
55
- Padrino.mount("PadrinoTestApp").to("/write")
56
- Padrino.mount("PadrinoTestApp2").to("/read")
54
+ Padrino.mount('PadrinoTestApp').to('/write')
55
+ Padrino.mount('PadrinoTestApp2').to('/read')
57
56
  PadrinoTestApp.send :default_configuration!
58
- PadrinoTestApp.get('/') { session[:foo] = "shared" }
57
+ PadrinoTestApp.get('/') { session[:foo] = 'shared' }
59
58
  PadrinoTestApp2.send(:default_configuration!)
60
59
  PadrinoTestApp2.get('/') { session[:foo] }
61
60
  @app = Padrino.application
@@ -73,10 +72,10 @@ describe "Application" do
73
72
 
74
73
  it 'should able to set custome session management' do
75
74
  class PadrinoTestApp3 < Padrino::Application
76
- set :sessions, :use => Rack::Session::Pool
75
+ set :sessions, use: Rack::Session::Pool
77
76
  end
78
- Padrino.mount("PadrinoTestApp3").to("/")
79
- PadrinoTestApp3.get('/write') { session[:foo] = "pool" }
77
+ Padrino.mount('PadrinoTestApp3').to('/')
78
+ PadrinoTestApp3.get('/write') { session[:foo] = 'pool' }
80
79
  PadrinoTestApp3.get('/read') { session[:foo] }
81
80
  @app = Padrino.application
82
81
  get '/write'
@@ -88,12 +87,14 @@ describe "Application" do
88
87
  class PadrinoTestApp4 < Padrino::Application
89
88
  enable :sessions
90
89
  end
90
+
91
91
  class PadrinoTestApp5 < Padrino::Application
92
- set :sessions, :use => Rack::Session::Pool
92
+ set :sessions, use: Rack::Session::Pool
93
93
  end
94
- Padrino.mount("PadrinoTestApp4").to("/write")
95
- Padrino.mount("PadrinoTestApp5").to("/read")
96
- PadrinoTestApp4.get('/') { session[:foo] = "cookie" }
94
+
95
+ Padrino.mount('PadrinoTestApp4').to('/write')
96
+ Padrino.mount('PadrinoTestApp5').to('/read')
97
+ PadrinoTestApp4.get('/') { session[:foo] = 'cookie' }
97
98
  PadrinoTestApp5.get('/') { session[:foo] }
98
99
  @app = Padrino.application
99
100
  get '/write'
@@ -106,8 +107,8 @@ describe "Application" do
106
107
  mock_app do
107
108
  provides :xml
108
109
 
109
- get("/foo"){ "Foo in #{content_type.inspect}" }
110
- get("/bar"){ "Foo in #{content_type.inspect}" }
110
+ get('/foo') { "Foo in #{content_type.inspect}" }
111
+ get('/bar') { "Foo in #{content_type.inspect}" }
111
112
  end
112
113
 
113
114
  get '/foo', {}, { 'HTTP_ACCEPT' => 'application/xml' }
@@ -116,61 +117,59 @@ describe "Application" do
116
117
  assert_equal 'Foo in :xml', body
117
118
 
118
119
  get '/bar', {}, { 'HTTP_ACCEPT' => 'application/xml' }
119
- assert_equal "Foo in nil", body
120
+ assert_equal 'Foo in nil', body
120
121
  end
121
122
 
122
123
  it 'should resolve views and layouts paths' do
123
- assert_equal Padrino.root('views')+'/users/index', PadrinoPristine.view_path('users/index')
124
- assert_equal Padrino.root('views')+'/layouts/app', PadrinoPristine.layout_path(:app)
124
+ assert_equal "#{Padrino.root('views')}/users/index", PadrinoPristine.view_path('users/index')
125
+ assert_equal "#{Padrino.root('views')}/layouts/app", PadrinoPristine.layout_path(:app)
125
126
  end
126
127
 
127
- describe "errors" do
128
+ describe 'errors' do
128
129
  it 'should have not mapped errors on development' do
129
- mock_app { get('/'){ 'HI' } }
130
- get "/"
130
+ mock_app { get('/') { 'HI' } }
131
+ get '/'
131
132
  assert_empty @app.errors
132
133
  end
133
134
 
134
135
  it 'should have mapped errors on production' do
135
- mock_app { set :environment, :production; get('/'){ 'HI' } }
136
- get "/"
136
+ mock_app { set :environment, :production; get('/') { 'HI' } }
137
+ get '/'
137
138
  assert_equal 1, @app.errors.size
138
139
  end
139
140
 
140
141
  it 'should overide errors' do
141
142
  mock_app do
142
143
  set :environment, :production
143
- get('/'){ raise }
144
- error(::Exception){ 'custom error' }
144
+ get('/') { raise }
145
+ error(::Exception) { 'custom error' }
145
146
  end
146
- get "/"
147
+ get '/'
147
148
  assert_equal 1, @app.errors.size
148
149
  assert_equal 'custom error', body
149
150
  end
150
151
 
152
+ # see naming collision in issue #1814
151
153
  it 'should pass Routing#parent to Module#parent' do
152
- # see naming collision in issue #1814
153
-
154
- ConstTest = Class.new(Padrino::Application)
155
- class Module
156
- def parent
157
- :dirty
158
- end
154
+ ConstTest = Class.new(Padrino::Application)
155
+ class Module
156
+ def parent
157
+ :dirty
159
158
  end
160
- assert_equal :dirty, ConstTest.parent
161
- ensure
162
- Module.instance_eval{ undef :parent }
163
-
159
+ end
160
+ assert_equal :dirty, ConstTest.parent
161
+ ensure
162
+ Module.instance_eval { undef :parent }
164
163
  end
165
164
  end
166
165
 
167
- describe "pre-compile routes" do
168
- it "should compile routes before first request if enabled the :precompile_routes option" do
169
- require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/precompiled_app')
166
+ describe 'pre-compile routes' do
167
+ it 'should compile routes before first request if enabled the :precompile_routes option' do
168
+ require File.expand_path("#{__dir__}/fixtures/apps/precompiled_app")
170
169
  assert_instance_of Padrino::PathRouter::Compiler, PrecompiledApp::App.compiled_router.engine
171
170
  assert_instance_of Padrino::PathRouter::Compiler, PrecompiledApp::SubApp.compiled_router.engine
172
- assert_equal true, PrecompiledApp::App.compiled_router.engine.compiled?
173
- assert_equal true, PrecompiledApp::SubApp.compiled_router.engine.compiled?
171
+ assert PrecompiledApp::App.compiled_router.engine.compiled?
172
+ assert PrecompiledApp::SubApp.compiled_router.engine.compiled?
174
173
  assert_equal 20, PrecompiledApp::App.compiled_router.engine.routes.length
175
174
  assert_equal 20, PrecompiledApp::SubApp.compiled_router.engine.routes.length
176
175
  end
@@ -1,6 +1,6 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
1
+ require_relative 'helper'
2
2
 
3
- describe "PadrinoConfiguration" do
3
+ describe 'PadrinoConfiguration' do
4
4
  it 'should be able to store values' do
5
5
  Padrino.config.val1 = 12_345
6
6
  assert_equal 12_345, Padrino.config.val1