padrino-core 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/lib/padrino-core.rb +4 -4
  3. data/lib/padrino-core/application.rb +6 -195
  4. data/lib/padrino-core/application/application_setup.rb +199 -0
  5. data/lib/padrino-core/application/routing.rb +66 -25
  6. data/lib/padrino-core/cli/base.rb +8 -5
  7. data/lib/padrino-core/cli/rake.rb +12 -9
  8. data/lib/padrino-core/loader.rb +1 -1
  9. data/lib/padrino-core/logger.rb +25 -0
  10. data/lib/padrino-core/mounter.rb +8 -3
  11. data/lib/padrino-core/reloader.rb +2 -2
  12. data/lib/padrino-core/server.rb +50 -17
  13. data/lib/padrino-core/version.rb +1 -1
  14. data/padrino-core.gemspec +2 -10
  15. data/test/fixtures/apps/demo_app.rb +7 -0
  16. data/test/fixtures/apps/demo_demo.rb +7 -0
  17. data/test/helper.rb +6 -37
  18. data/test/test_application.rb +12 -13
  19. data/test/test_core.rb +12 -13
  20. data/test/test_csrf_protection.rb +49 -23
  21. data/test/test_dependencies.rb +7 -7
  22. data/test/test_filters.rb +41 -17
  23. data/test/test_flash.rb +24 -24
  24. data/test/test_locale.rb +1 -1
  25. data/test/test_logger.rb +39 -27
  26. data/test/test_mounter.rb +34 -20
  27. data/test/test_reloader_complex.rb +5 -6
  28. data/test/test_reloader_simple.rb +23 -20
  29. data/test/test_reloader_system.rb +10 -7
  30. data/test/test_restful_routing.rb +1 -1
  31. data/test/test_router.rb +7 -7
  32. data/test/test_routing.rb +177 -141
  33. metadata +14 -53
  34. data/lib/padrino-core/application/rendering.rb +0 -325
  35. data/lib/padrino-core/application/rendering/extensions/erubis.rb +0 -68
  36. data/lib/padrino-core/application/rendering/extensions/haml.rb +0 -29
  37. data/lib/padrino-core/application/rendering/extensions/slim.rb +0 -21
  38. data/lib/padrino-core/locale/cs.yml +0 -33
  39. data/lib/padrino-core/locale/da.yml +0 -33
  40. data/lib/padrino-core/locale/de.yml +0 -33
  41. data/lib/padrino-core/locale/en.yml +0 -33
  42. data/lib/padrino-core/locale/es.yml +0 -33
  43. data/lib/padrino-core/locale/fr.yml +0 -33
  44. data/lib/padrino-core/locale/hu.yml +0 -33
  45. data/lib/padrino-core/locale/it.yml +0 -39
  46. data/lib/padrino-core/locale/ja.yml +0 -33
  47. data/lib/padrino-core/locale/lv.yml +0 -33
  48. data/lib/padrino-core/locale/nl.yml +0 -33
  49. data/lib/padrino-core/locale/no.yml +0 -33
  50. data/lib/padrino-core/locale/pl.yml +0 -33
  51. data/lib/padrino-core/locale/pt_br.yml +0 -39
  52. data/lib/padrino-core/locale/ro.yml +0 -33
  53. data/lib/padrino-core/locale/ru.yml +0 -34
  54. data/lib/padrino-core/locale/sv.yml +0 -33
  55. data/lib/padrino-core/locale/tr.yml +0 -33
  56. data/lib/padrino-core/locale/uk.yml +0 -33
  57. data/lib/padrino-core/locale/zh_cn.yml +0 -33
  58. data/lib/padrino-core/locale/zh_tw.yml +0 -33
  59. data/lib/padrino-core/support_lite.rb +0 -259
  60. data/test/fixtures/apps/.components +0 -6
  61. data/test/fixtures/apps/.gitignore +0 -7
  62. data/test/fixtures/apps/render.rb +0 -13
  63. data/test/fixtures/apps/views/blog/post.erb +0 -1
  64. data/test/fixtures/layouts/layout.erb +0 -1
  65. data/test/mini_shoulda.rb +0 -45
  66. data/test/test_rendering.rb +0 -606
  67. data/test/test_rendering_extensions.rb +0 -14
  68. data/test/test_support_lite.rb +0 -56
@@ -0,0 +1,7 @@
1
+ PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
2
+
3
+ module Demo
4
+ class App < Padrino::Application
5
+ set :reload, true
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
2
+
3
+ module Demo
4
+ class Demo < Padrino::Application
5
+ set :reload, true
6
+ end
7
+ end
data/test/helper.rb CHANGED
@@ -2,21 +2,21 @@ ENV['RACK_ENV'] = 'test'
2
2
  PADRINO_ROOT = File.dirname(__FILE__) unless defined?(PADRINO_ROOT)
3
3
 
4
4
  require File.expand_path('../../../load_paths', __FILE__)
5
- require File.expand_path('../mini_shoulda', __FILE__)
5
+ require 'minitest/autorun'
6
+ require 'minitest/pride'
7
+ require 'i18n'
8
+ require 'padrino-support'
6
9
  require 'padrino-core'
7
10
  require 'json'
11
+ require 'builder'
8
12
  require 'rack/test'
9
13
  require 'rack'
14
+ require 'yaml'
10
15
 
11
16
  # Rubies < 1.9 don't handle hashes in the properly order so to prevent
12
17
  # this issue for now we remove extra values from mimetypes.
13
18
  Rack::Mime::MIME_TYPES.delete(".xsl") # In this way application/xml respond only to .xml
14
19
 
15
- class Sinatra::Base
16
- # Allow assertions in request context
17
- include MiniTest::Assertions
18
- end
19
-
20
20
  class MiniTest::Spec
21
21
  include Rack::Test::Methods
22
22
 
@@ -49,35 +49,4 @@ class MiniTest::Spec
49
49
  end
50
50
 
51
51
  alias :response :last_response
52
-
53
- def create_template(name, content, options={})
54
- FileUtils.mkdir_p(File.dirname(__FILE__) + "/views")
55
- FileUtils.mkdir_p(File.dirname(__FILE__) + "/views/layouts")
56
- path = "/views/#{name}"
57
- path += ".#{options.delete(:locale)}" if options[:locale].present?
58
- path += ".#{options[:format]}" if options[:format].present?
59
- path += ".erb" unless options[:format].to_s =~ /erb|slim|haml|rss|atom/
60
- path += ".builder" if options[:format].to_s =~ /rss|atom/
61
- file = File.dirname(__FILE__) + path
62
- File.open(file, 'w') { |io| io.write content }
63
- file
64
- end
65
- alias :create_view :create_template
66
- alias :create_layout :create_template
67
-
68
- def remove_views
69
- FileUtils.rm_rf(File.dirname(__FILE__) + "/views")
70
- end
71
-
72
- def with_template(name, content, options={})
73
- # Build a temp layout
74
- template = create_template(name, content, options)
75
- yield
76
- ensure
77
- # Remove temp layout
78
- File.unlink(template) rescue nil
79
- remove_views
80
- end
81
- alias :with_view :with_template
82
- alias :with_layout :with_template
83
52
  end
@@ -7,11 +7,10 @@ class PadrinoTestApp2 < Padrino::Application; end
7
7
 
8
8
  describe "Application" do
9
9
  before { Padrino.clear! }
10
- after { remove_views }
11
10
 
12
- context 'for application functionality' do
11
+ describe 'for application functionality' do
13
12
 
14
- should 'check default options' do
13
+ it 'should check default options' do
15
14
  assert File.identical?(__FILE__, PadrinoPristine.app_file)
16
15
  assert_equal :padrino_pristine, PadrinoPristine.app_name
17
16
  assert_equal :test, PadrinoPristine.environment
@@ -25,7 +24,7 @@ describe "Application" do
25
24
  assert !Padrino.configure_apps
26
25
  end
27
26
 
28
- should 'check padrino specific options' do
27
+ it 'should check padrino specific options' do
29
28
  assert !PadrinoPristine.instance_variable_get(:@_configured)
30
29
  PadrinoPristine.send(:setup_application!)
31
30
  assert_equal :padrino_pristine, PadrinoPristine.app_name
@@ -34,7 +33,7 @@ describe "Application" do
34
33
  assert !PadrinoPristine.reload?
35
34
  end
36
35
 
37
- should 'set global project settings' do
36
+ it 'should set global project settings' do
38
37
  Padrino.configure_apps { enable :sessions; set :foo, "bar" }
39
38
  PadrinoTestApp.send(:default_configuration!)
40
39
  PadrinoTestApp2.send(:default_configuration!)
@@ -43,7 +42,7 @@ describe "Application" do
43
42
  assert_equal PadrinoTestApp.session_secret, PadrinoTestApp2.session_secret
44
43
  end
45
44
 
46
- should 'be able to configure_apps multiple times' do
45
+ it 'should be able to configure_apps multiple times' do
47
46
  Padrino.configure_apps { set :foo1, "bar" }
48
47
  Padrino.configure_apps { set :foo1, "bam" }
49
48
  Padrino.configure_apps { set :foo2, "baz" }
@@ -52,7 +51,7 @@ describe "Application" do
52
51
  assert_equal "baz", PadrinoTestApp.settings.foo2, "should have foo2 assigned to baz"
53
52
  end
54
53
 
55
- should "have shared sessions accessible in project" do
54
+ it 'should have shared sessions accessible in project' do
56
55
  Padrino.configure_apps { enable :sessions; set :session_secret, 'secret' }
57
56
  Padrino.mount("PadrinoTestApp").to("/write")
58
57
  Padrino.mount("PadrinoTestApp2").to("/read")
@@ -67,7 +66,7 @@ describe "Application" do
67
66
  end
68
67
 
69
68
  # compare to: test_routing: allow global provides
70
- should "set content_type to nil if none can be determined" do
69
+ it 'should set content_type to nil if none can be determined' do
71
70
  mock_app do
72
71
  provides :xml
73
72
 
@@ -84,25 +83,25 @@ describe "Application" do
84
83
  assert_equal "Foo in nil", body
85
84
  end
86
85
 
87
- should "resolve views and layouts paths" do
86
+ it 'should resolve views and layouts paths' do
88
87
  assert_equal Padrino.root('views')+'/users/index', PadrinoPristine.view_path('users/index')
89
88
  assert_equal Padrino.root('views')+'/layouts/app', PadrinoPristine.layout_path(:app)
90
89
  end
91
90
 
92
- context "errors" do
93
- should "haven't mapped errors on development" do
91
+ describe "errors" do
92
+ it 'should have not mapped errors on development' do
94
93
  mock_app { get('/'){ 'HI' } }
95
94
  get "/"
96
95
  assert @app.errors.empty?
97
96
  end
98
97
 
99
- should "have mapped errors on production" do
98
+ it 'should have mapped errors on production' do
100
99
  mock_app { set :environment, :production; get('/'){ 'HI' } }
101
100
  get "/"
102
101
  assert_equal 1, @app.errors.size
103
102
  end
104
103
 
105
- should "overide errors" do
104
+ it 'should overide errors' do
106
105
  mock_app do
107
106
  set :environment, :production
108
107
  get('/'){ raise }
data/test/test_core.rb CHANGED
@@ -5,9 +5,8 @@ describe "Core" do
5
5
  Padrino.clear!
6
6
  end
7
7
 
8
- context 'for core functionality' do
9
-
10
- should 'check some global methods' do
8
+ describe 'for core functionality' do
9
+ it 'should check some global methods' do
11
10
  assert_respond_to Padrino, :root
12
11
  assert_respond_to Padrino, :env
13
12
  assert_respond_to Padrino, :application
@@ -18,28 +17,28 @@ describe "Core" do
18
17
  assert_respond_to Padrino, :configure_apps
19
18
  end
20
19
 
21
-
22
- should 'validate global helpers' do
20
+ it 'should validate global helpers' do
23
21
  assert_equal :test, Padrino.env
24
22
  assert_match /\/test/, Padrino.root
25
- assert_not_nil Padrino.version
23
+ refute_nil Padrino.version
26
24
  end
27
25
 
28
- should 'set correct utf-8 encoding' do
26
+ it 'should set correct utf-8 encoding' do
29
27
  Padrino.set_encoding
30
28
  assert_equal Encoding.default_external, Encoding::UTF_8
31
29
  assert_equal Encoding.default_internal, Encoding::UTF_8
32
30
  end
33
31
 
34
- should 'have load paths' do
32
+ it 'should have load paths' do
35
33
  assert_equal [Padrino.root('lib'), Padrino.root('models'), Padrino.root('shared')], Padrino.load_paths
36
34
  end
37
35
 
38
- should 'raise application error if I instantiate a new padrino application without mounted apps' do
39
- assert_raises(Padrino::ApplicationLoadError) { Padrino.application.new }
36
+ it 'should raise application error if I instantiate a new padrino application without mounted apps' do
37
+ text = capture_io { Padrino.application }
38
+ assert_match /No apps are mounted/, text.to_s
40
39
  end
41
40
 
42
- should "check before/after padrino load hooks" do
41
+ it 'should check before/after padrino load hooks' do
43
42
  Padrino.before_load { @_foo = 1 }
44
43
  Padrino.after_load { @_foo += 1 }
45
44
  Padrino.load!
@@ -48,7 +47,7 @@ describe "Core" do
48
47
  assert_equal 2, @_foo
49
48
  end
50
49
 
51
- should "add middlewares in front if specified" do
50
+ it 'should add middlewares in front if specified' do
52
51
  test = Class.new {
53
52
  def initialize(app)
54
53
  @app = app
@@ -70,7 +69,7 @@ describe "Core" do
70
69
  assert_equal "yes", res["Middleware-Called"]
71
70
  end
72
71
 
73
- should "properly set default options" do
72
+ it 'should properly set default options' do
74
73
  mock_app do
75
74
  default :foo, :bar
76
75
  default :zoo, :baz
@@ -2,10 +2,9 @@ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
3
  describe "Application" do
4
4
  before { Padrino.clear! }
5
- after { remove_views }
6
5
 
7
- context 'CSRF protection' do
8
- context "with CSRF protection on" do
6
+ describe 'CSRF protection' do
7
+ describe "with CSRF protection on" do
9
8
  before do
10
9
  mock_app do
11
10
  enable :sessions
@@ -14,23 +13,23 @@ describe "Application" do
14
13
  end
15
14
  end
16
15
 
17
- should "not allow requests without tokens" do
16
+ it 'should not allow requests without tokens' do
18
17
  post "/"
19
18
  assert_equal 403, status
20
19
  end
21
20
 
22
- should "allow requests with correct tokens" do
21
+ it 'should allow requests with correct tokens' do
23
22
  post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "a"}
24
23
  assert_equal 200, status
25
24
  end
26
25
 
27
- should "not allow requests with incorrect tokens" do
26
+ it 'should not allow requests with incorrect tokens' do
28
27
  post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "b"}
29
28
  assert_equal 403, status
30
29
  end
31
30
  end
32
31
 
33
- context "without CSRF protection on" do
32
+ describe "without CSRF protection on" do
34
33
  before do
35
34
  mock_app do
36
35
  enable :sessions
@@ -39,45 +38,46 @@ describe "Application" do
39
38
  end
40
39
  end
41
40
 
42
- should "allows requests without tokens" do
41
+ it 'should allows requests without tokens' do
43
42
  post "/"
44
43
  assert_equal 200, status
45
44
  end
46
45
 
47
- should "allow requests with correct tokens" do
46
+ it 'should allow requests with correct tokens' do
48
47
  post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "a"}
49
48
  assert_equal 200, status
50
49
  end
51
50
 
52
- should "allow requests with incorrect tokens" do
51
+ it 'should allow requests with incorrect tokens' do
53
52
  post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "b"}
54
53
  assert_equal 200, status
55
54
  end
56
55
  end
57
56
 
58
- context "with optional CSRF protection" do
57
+ describe "with optional CSRF protection" do
59
58
  before do
60
59
  mock_app do
61
60
  enable :sessions
62
61
  enable :protect_from_csrf
63
- set :allow_disabled_csrf, true
62
+ enable :allow_disabled_csrf
64
63
  post('/on') { 'HI' }
65
64
  post('/off', :csrf_protection => false) { 'HI' }
66
65
  end
67
66
  end
68
67
 
69
- should "allow access to routes with csrf_protection off" do
68
+ it 'should allow access to routes with csrf_protection off' do
70
69
  post "/off"
71
70
  assert_equal 200, status
72
71
  end
73
72
 
74
- should "not allow access to routes with csrf_protection on" do
73
+ it 'should not allow access to routes with csrf_protection on' do
75
74
  post "/on"
76
75
  assert_equal 403, status
76
+ assert_equal 'Forbidden', body
77
77
  end
78
78
  end
79
79
 
80
- context "with :except option that is using Proc" do
80
+ describe "with :except option that is using Proc" do
81
81
  before do
82
82
  mock_app do
83
83
  enable :sessions
@@ -88,7 +88,7 @@ describe "Application" do
88
88
  end
89
89
  end
90
90
 
91
- should "allow ignoring CSRF protection on specific routes" do
91
+ it 'should allow ignoring CSRF protection on specific routes' do
92
92
  post "/"
93
93
  assert_equal 200, status
94
94
  post "/foo"
@@ -98,7 +98,7 @@ describe "Application" do
98
98
  end
99
99
  end
100
100
 
101
- context "with :except option that is using String and Regexp" do
101
+ describe "with :except option that is using String and Regexp" do
102
102
  before do
103
103
  mock_app do
104
104
  enable :sessions
@@ -109,7 +109,7 @@ describe "Application" do
109
109
  end
110
110
  end
111
111
 
112
- should "allow ignoring CSRF protection on specific routes" do
112
+ it 'should allow ignoring CSRF protection on specific routes' do
113
113
  post "/a"
114
114
  assert_equal 200, status
115
115
  post "/abc"
@@ -119,22 +119,28 @@ describe "Application" do
119
119
  end
120
120
  end
121
121
 
122
- context "with custom protection options" do
122
+ describe "with custom protection options" do
123
123
  before do
124
124
  mock_app do
125
125
  enable :sessions
126
- set :protect_from_csrf, :authenticity_param => 'foobar'
126
+ set :protect_from_csrf, :authenticity_param => 'foobar', :message => 'sucker!'
127
127
  post("/a") { "a" }
128
128
  end
129
129
  end
130
130
 
131
- should "allow configuring protection options" do
131
+ it 'should allow configuring protection options' do
132
132
  post "/a", {"foobar" => "a"}, 'rack.session' => {:csrf => "a"}
133
133
  assert_equal 200, status
134
134
  end
135
+
136
+ it 'should allow configuring message' do
137
+ post "/a"
138
+ assert_equal 403, status
139
+ assert_equal 'sucker!', body
140
+ end
135
141
  end
136
142
 
137
- context "with middleware" do
143
+ describe "with middleware" do
138
144
  before do
139
145
  class Middleware < Sinatra::Base
140
146
  post("/middleware") { "Hello, middleware" }
@@ -148,7 +154,7 @@ describe "Application" do
148
154
  end
149
155
  end
150
156
 
151
- should "allow ignoring CSRF protection on specific routes of middleware" do
157
+ it 'should allow ignoring CSRF protection on specific routes of middleware' do
152
158
  post "/"
153
159
  assert_equal 200, status
154
160
  post "/middleware"
@@ -157,5 +163,25 @@ describe "Application" do
157
163
  assert_equal 403, status
158
164
  end
159
165
  end
166
+
167
+ describe "with standard report layout" do
168
+ before do
169
+ mock_app do
170
+ enable :sessions
171
+ set :protect_from_csrf, :message => 'sucker!'
172
+ enable :report_csrf_failure
173
+ post("/a") { "a" }
174
+ error 403 do
175
+ halt 406, 'please, do not hack'
176
+ end
177
+ end
178
+ end
179
+
180
+ it 'should allow configuring protection options' do
181
+ post "/a"
182
+ assert_equal 406, status
183
+ assert_equal 'please, do not hack', body
184
+ end
185
+ end
160
186
  end
161
187
  end
@@ -1,20 +1,20 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
3
  describe "Dependencies" do
4
- context 'when we require a dependency that have another dependency' do
5
- setup do
4
+ describe 'when we require a dependency that have another dependency' do
5
+ before do
6
6
  @log_level = Padrino::Logger::Config[:test]
7
7
  @io = StringIO.new
8
8
  Padrino::Logger::Config[:test] = { :log_level => :error, :stream => @io }
9
9
  Padrino::Logger.setup!
10
10
  end
11
11
 
12
- teardown do
12
+ after do
13
13
  Padrino::Logger::Config[:test] = @log_level
14
14
  Padrino::Logger.setup!
15
15
  end
16
16
 
17
- should 'raise an error without reloading it twice' do
17
+ it 'should raise an error without reloading it twice' do
18
18
  capture_io do
19
19
  assert_raises(RuntimeError) do
20
20
  Padrino.require_dependencies(
@@ -26,10 +26,10 @@ describe "Dependencies" do
26
26
  end
27
27
  end
28
28
  assert_equal 1, D
29
- assert_match /RuntimeError: SomeThing/, @io.string
29
+ assert_match /RuntimeError - SomeThing/, @io.string
30
30
  end
31
31
 
32
- should 'resolve dependency problems' do
32
+ it 'should resolve dependency problems' do
33
33
  capture_io do
34
34
  Padrino.require_dependencies(
35
35
  Padrino.root("fixtures/dependencies/a.rb"),
@@ -42,7 +42,7 @@ describe "Dependencies" do
42
42
  assert_equal "", @io.string
43
43
  end
44
44
 
45
- should 'remove partially loaded constants' do
45
+ it 'should remove partially loaded constants' do
46
46
  capture_io do
47
47
  Padrino.require_dependencies(
48
48
  Padrino.root("fixtures/dependencies/circular/e.rb"),