padrino-core 0.11.4 → 0.12.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/padrino-core/application/authenticity_token.rb +25 -0
  3. data/lib/padrino-core/application/rendering/extensions/erubis.rb +11 -7
  4. data/lib/padrino-core/application/rendering/extensions/haml.rb +3 -2
  5. data/lib/padrino-core/application/rendering/extensions/slim.rb +10 -3
  6. data/lib/padrino-core/application/rendering.rb +13 -5
  7. data/lib/padrino-core/application/routing.rb +62 -19
  8. data/lib/padrino-core/application.rb +136 -50
  9. data/lib/padrino-core/cli/base.rb +32 -1
  10. data/lib/padrino-core/loader.rb +68 -68
  11. data/lib/padrino-core/logger.rb +6 -6
  12. data/lib/padrino-core/mounter.rb +9 -4
  13. data/lib/padrino-core/reloader/rack.rb +26 -0
  14. data/lib/padrino-core/reloader/storage.rb +55 -0
  15. data/lib/padrino-core/reloader.rb +192 -287
  16. data/lib/padrino-core/router.rb +11 -12
  17. data/lib/padrino-core/server.rb +5 -0
  18. data/lib/padrino-core/support_lite.rb +31 -32
  19. data/lib/padrino-core/version.rb +1 -1
  20. data/lib/padrino-core.rb +22 -30
  21. data/padrino-core.gemspec +2 -1
  22. data/test/fixtures/apps/helpers/system_helpers.rb +8 -0
  23. data/test/fixtures/apps/kiq.rb +3 -0
  24. data/test/fixtures/apps/lib/myklass/mysubklass.rb +4 -0
  25. data/test/fixtures/apps/lib/myklass.rb +2 -0
  26. data/test/fixtures/apps/models/child.rb +2 -0
  27. data/test/fixtures/apps/models/parent.rb +5 -0
  28. data/test/fixtures/apps/render.rb +13 -0
  29. data/test/fixtures/apps/system.rb +13 -0
  30. data/test/fixtures/apps/views/blog/post.erb +1 -0
  31. data/test/helper.rb +1 -1
  32. data/test/mini_shoulda.rb +4 -4
  33. data/test/test_application.rb +5 -13
  34. data/test/test_core.rb +2 -6
  35. data/test/test_csrf_protection.rb +67 -1
  36. data/test/test_dependencies.rb +14 -1
  37. data/test/test_mounter.rb +50 -6
  38. data/test/test_reloader_complex.rb +2 -2
  39. data/test/test_reloader_simple.rb +1 -1
  40. data/test/test_reloader_system.rb +52 -0
  41. data/test/test_rendering.rb +54 -0
  42. data/test/test_router.rb +121 -2
  43. data/test/test_routing.rb +84 -15
  44. metadata +29 -11
data/test/test_router.rb CHANGED
@@ -17,8 +17,8 @@ describe "Router" do
17
17
  }
18
18
  map = Padrino::Router.new(
19
19
  { :path => '/bar', :to => app },
20
- { :path => '/foo', :to => app },
21
- { :path => '/foo/bar', :to => app }
20
+ { :path => '/foo/bar', :to => app },
21
+ { :path => '/foo', :to => app }
22
22
  )
23
23
 
24
24
  res = Rack::MockRequest.new(map).get("/")
@@ -69,6 +69,125 @@ describe "Router" do
69
69
  assert_equal "/", res["X-PathInfo"]
70
70
  end
71
71
 
72
+ should "dispatch requests to cascade mounted apps" do
73
+ app = lambda { |env|
74
+ scary = !!env['PATH_INFO'].match(/scary/)
75
+ [scary ? 404 : 200, {
76
+ 'X-ScriptName' => env['SCRIPT_NAME'],
77
+ 'X-PathInfo' => env['PATH_INFO'],
78
+ 'Content-Type' => 'text/plain'
79
+ }, [""]]
80
+ }
81
+ api = lambda { |env|
82
+ spooky = !!env['QUERY_STRING'].match(/spooky/)
83
+ [spooky ? 200 : 404, {
84
+ 'X-API' => spooky,
85
+ 'X-ScriptName' => env['SCRIPT_NAME'],
86
+ 'X-PathInfo' => env['PATH_INFO'],
87
+ 'Content-Type' => 'application/json'
88
+ }, [""]]
89
+ }
90
+ map = Padrino::Router.new(
91
+ { :path => '/bar', :to => api },
92
+ { :path => '/bar', :to => app }
93
+ )
94
+
95
+ res = Rack::MockRequest.new(map).get("/werewolf")
96
+ assert_equal 404, res.status
97
+ assert_equal nil, res["X-API"]
98
+ assert_equal nil, res["X-ScriptName"]
99
+ assert_equal nil, res["X-PathInfo"]
100
+
101
+ res = Rack::MockRequest.new(map).get("/bar/mitzvah")
102
+ assert res.ok?
103
+ assert_equal nil, 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"]
107
+
108
+ res = Rack::MockRequest.new(map).get("/bar?spooky")
109
+ 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"]
114
+
115
+ res = Rack::MockRequest.new(map).get("/bar/scary")
116
+ assert_equal 404, res.status
117
+ assert_equal nil, 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"]
121
+ end
122
+
123
+ should "dispatch requests to cascade mounted apps and not cascade ok statuses" do
124
+
125
+ api = mock_app do
126
+ get 'scary' do
127
+ "1"
128
+ end
129
+ set :cascade, true
130
+ end
131
+
132
+ app = mock_app do
133
+ get 'scary' do
134
+ "2"
135
+ end
136
+ set :cascade, false
137
+ end
138
+
139
+ app2 = mock_app do
140
+ get 'terrifying' do
141
+ ""
142
+ end
143
+ end
144
+
145
+ map = Padrino::Router.new(
146
+ { :path => '/bar', :to => api },
147
+ { :path => '/bar', :to => app },
148
+ { :path => '/bar', :to => app2 }
149
+ )
150
+
151
+ res = Rack::MockRequest.new(map).get("/bar/scary")
152
+ 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?
158
+
159
+ end
160
+
161
+ should "dispatch requests to cascade mounted apps until it sees a cascade == false or []g" do
162
+ app = mock_app do
163
+ get 'scary' do
164
+ ""
165
+ end
166
+ set :cascade, []
167
+ end
168
+
169
+ app2 = mock_app do
170
+ get 'terrifying' do
171
+ ""
172
+ end
173
+ end
174
+
175
+ map = Padrino::Router.new(
176
+ { :path => '/bar', :to => app },
177
+ { :path => '/bar', :to => app2 }
178
+ )
179
+
180
+ request_case = lambda {
181
+ Rack::MockRequest.new(map).get("/bar/terrifying")
182
+ }
183
+
184
+ app.cascade = false
185
+ assert !request_case.call.ok?
186
+
187
+ app.cascade = true
188
+ assert request_case.call.ok?
189
+ end
190
+
72
191
  should "dispatches hosts correctly" do
73
192
  map = Padrino::Router.new(
74
193
  { :host => "foo.org", :to => lambda { |env|
data/test/test_routing.rb CHANGED
@@ -1,4 +1,4 @@
1
- #encoding: utf-8
1
+ #encoding: utf-8
2
2
  require File.expand_path(File.dirname(__FILE__) + '/helper')
3
3
 
4
4
  class FooError < RuntimeError; end
@@ -56,6 +56,32 @@ describe "Routing" do
56
56
  }
57
57
  end
58
58
 
59
+ should 'fail with unrecognized route exception when namespace is invalid' do
60
+ mock_app do
61
+ controller :foo_bar do
62
+ get(:index){ "okey" }
63
+ get(:test_baz){ "okey" }
64
+ end
65
+ end
66
+ assert_equal "/foo_bar", @app.url_for(:foo_bar, :index)
67
+ assert_raises(Padrino::Routing::UnrecognizedException) {
68
+ get @app.url_for(:foo, :bar, :index)
69
+ }
70
+ assert_raises(Padrino::Routing::UnrecognizedException) {
71
+ get @app.url_for(:foo, :bar_index)
72
+ }
73
+ assert_equal "/foo_bar/test_baz", @app.url_for(:foo_bar, :test_baz)
74
+ assert_raises(Padrino::Routing::UnrecognizedException) {
75
+ get @app.url_for(:foo_bar, :test, :baz)
76
+ }
77
+ assert_raises(Padrino::Routing::UnrecognizedException) {
78
+ get @app.url_for(:foo, :bar_test, :baz)
79
+ }
80
+ assert_raises(Padrino::Routing::UnrecognizedException) {
81
+ get @app.url_for(:foo, :bar_test_baz)
82
+ }
83
+ end
84
+
59
85
  should 'accept regexp routes' do
60
86
  mock_app do
61
87
  get(%r./fob|/baz.) { "regexp" }
@@ -102,11 +128,11 @@ describe "Routing" do
102
128
  end
103
129
 
104
130
  should 'parse routes that are encoded' do
105
- mock_app do
131
+ mock_app do
106
132
  get('/щч') { 'success!' }
107
133
  end
108
134
  get(URI.escape('/щч'))
109
- assert_equal 'success!', body
135
+ assert_equal 'success!', body
110
136
  end
111
137
 
112
138
  should 'parse routes that include encoded slash' do
@@ -120,9 +146,7 @@ describe "Routing" do
120
146
  end
121
147
 
122
148
  should 'encode params using UTF-8' do
123
- skip unless ''.respond_to?(:encoding) # for 1.8.7
124
-
125
- mock_app do
149
+ mock_app do
126
150
  get('/:foo') { params[:foo].encoding.name }
127
151
  end
128
152
  get '/bar'
@@ -272,6 +296,24 @@ describe "Routing" do
272
296
  assert_equal 'http://example.org/test/foo?id=1', body
273
297
  end
274
298
 
299
+ should 'rebase simple string urls to app uri_root' do
300
+ mock_app do
301
+ set :uri_root, '/app'
302
+ get(:a){ url('/foo') }
303
+ get(:b){ url('bar') }
304
+ get(:c){ absolute_url('/foo') }
305
+ get(:d, :map => '/d/e/f'){ absolute_url('bar') }
306
+ end
307
+ get "/a"
308
+ assert_equal "/app/foo", body
309
+ get "/b"
310
+ assert_equal "bar", body
311
+ get "/c"
312
+ assert_equal "http://example.org/app/foo", body
313
+ get "/d/e/f"
314
+ assert_equal "http://example.org/app/d/e/bar", body
315
+ end
316
+
275
317
  should 'allow regex url with format' do
276
318
  mock_app do
277
319
  get(/.*/, :provides => :any) { "regexp" }
@@ -354,7 +396,7 @@ describe "Routing" do
354
396
  get("/foo"){ content_type(:json); content_type.to_s }
355
397
  end
356
398
  get "/foo"
357
- assert_equal 'application/json;charset=utf-8', content_type
399
+ assert_equal 'application/json', content_type
358
400
  assert_equal 'json', body
359
401
  end
360
402
 
@@ -367,7 +409,7 @@ describe "Routing" do
367
409
  end
368
410
 
369
411
  should "allow .'s in param values" do
370
- skip
412
+ skip # TODO fix this?
371
413
  mock_app do
372
414
  get('/id/:email', :provides => [:json]) { |email, format| [email, format] * '/' }
373
415
  end
@@ -474,7 +516,7 @@ describe "Routing" do
474
516
  end
475
517
  end
476
518
  get "/posts"
477
- assert_equal "posts_index", body
519
+ assert_equal "posts index", body
478
520
  end
479
521
 
480
522
  should "preserve the format if you set it manually" do
@@ -640,7 +682,7 @@ describe "Routing" do
640
682
  assert_equal 'application/javascript;charset=utf-8', response["Content-Type"]
641
683
  get "/a.json"
642
684
  assert_equal "json", body
643
- assert_equal 'application/json;charset=utf-8', response["Content-Type"]
685
+ assert_equal 'application/json', response["Content-Type"]
644
686
  get "/a.foo"
645
687
  assert_equal "foo", body
646
688
  assert_equal 'application/foo;charset=utf-8', response["Content-Type"]
@@ -676,8 +718,8 @@ describe "Routing" do
676
718
  assert_equal "1", body
677
719
  get "/admin/show/1"
678
720
  assert_equal "show 1", body
679
- assert_equal "/admin/1", @app.url(:admin_index, :id => 1)
680
- assert_equal "/admin/show/1", @app.url(:admin_show, :id => 1)
721
+ assert_equal "/admin/1", @app.url(:admin, :index, :id => 1)
722
+ assert_equal "/admin/show/1", @app.url(:admin, :show, :id => 1)
681
723
  get "/foo/bar"
682
724
  assert_equal "foo_bar_index", body
683
725
  end
@@ -1790,6 +1832,33 @@ describe "Routing" do
1790
1832
  assert ok?
1791
1833
  end
1792
1834
 
1835
+ should 'return params as a HashWithIndifferentAccess object via GET' do
1836
+ mock_app do
1837
+ get('/foo/:bar') { "#{params["bar"]} #{params[:bar]}" }
1838
+ get(:foo, :map => '/prefix/:var') { "#{params["var"]} #{params[:var]}" }
1839
+ end
1840
+
1841
+ get('/foo/some_text')
1842
+ assert_equal "some_text some_text", body
1843
+
1844
+ get('/prefix/var')
1845
+ assert_equal "var var", body
1846
+ end
1847
+
1848
+ should 'return params as a HashWithIndifferentAccess object via POST' do
1849
+ mock_app do
1850
+ post('/user') do
1851
+ "#{params["user"]["full_name"]} #{params[:user][:full_name]}"
1852
+ end
1853
+ end
1854
+
1855
+ post '/user', {:user => {:full_name => 'example user'}}
1856
+ assert_equal "example user example user", body
1857
+
1858
+ post '/user', {"user" => {"full_name" => 'example user'}}
1859
+ assert_equal "example user example user", body
1860
+ end
1861
+
1793
1862
  should 'have MethodOverride middleware with more options' do
1794
1863
  mock_app do
1795
1864
  put('/hi', :provides => [:json]) { 'hi' }
@@ -1840,7 +1909,7 @@ describe "Routing" do
1840
1909
  end
1841
1910
 
1842
1911
  should 'render a custom error page using error method' do
1843
- skip
1912
+ skip # TODO sinatra bug?
1844
1913
  mock_app do
1845
1914
  error(404) { "custom 404 error" }
1846
1915
  end
@@ -1867,8 +1936,8 @@ describe "Routing" do
1867
1936
  get(:simple, :map => "/simple/:id") { }
1868
1937
  get(:with_format, :with => :id, :provides => :js) { }
1869
1938
  end
1870
- assert_equal [:foo_bar, { :id => "fantastic" }], @app.recognize_path(@app.url(:foo, :bar, :id => :fantastic))
1871
- assert_equal [:foo_bar, { :id => "18" }], @app.recognize_path(@app.url(:foo, :bar, :id => 18))
1939
+ assert_equal [:"foo bar", { :id => "fantastic" }], @app.recognize_path(@app.url(:foo, :bar, :id => :fantastic))
1940
+ assert_equal [:"foo bar", { :id => "18" }], @app.recognize_path(@app.url(:foo, :bar, :id => 18))
1872
1941
  assert_equal [:simple, { :id => "bar" }], @app.recognize_path(@app.url(:simple, :id => "bar"))
1873
1942
  assert_equal [:simple, { :id => "true" }], @app.recognize_path(@app.url(:simple, :id => true))
1874
1943
  assert_equal [:simple, { :id => "9" }], @app.recognize_path(@app.url(:simple, :id => 9))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.4
4
+ version: 0.12.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-09-24 00:00:00.000000000 Z
14
+ date: 2013-12-31 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: tilt
@@ -76,9 +76,6 @@ dependencies:
76
76
  - - '>='
77
77
  - !ruby/object:Gem::Version
78
78
  version: '3.1'
79
- - - <
80
- - !ruby/object:Gem::Version
81
- version: '4.0'
82
79
  type: :runtime
83
80
  prerelease: false
84
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -86,9 +83,6 @@ dependencies:
86
83
  - - '>='
87
84
  - !ruby/object:Gem::Version
88
85
  version: '3.1'
89
- - - <
90
- - !ruby/object:Gem::Version
91
- version: '4.0'
92
86
  - !ruby/object:Gem::Dependency
93
87
  name: rack-protection
94
88
  requirement: !ruby/object:Gem::Requirement
@@ -120,6 +114,7 @@ files:
120
114
  - bin/padrino
121
115
  - lib/padrino-core.rb
122
116
  - lib/padrino-core/application.rb
117
+ - lib/padrino-core/application/authenticity_token.rb
123
118
  - lib/padrino-core/application/flash.rb
124
119
  - lib/padrino-core/application/rendering.rb
125
120
  - lib/padrino-core/application/rendering/extensions/erubis.rb
@@ -162,6 +157,8 @@ files:
162
157
  - lib/padrino-core/module.rb
163
158
  - lib/padrino-core/mounter.rb
164
159
  - lib/padrino-core/reloader.rb
160
+ - lib/padrino-core/reloader/rack.rb
161
+ - lib/padrino-core/reloader/storage.rb
165
162
  - lib/padrino-core/router.rb
166
163
  - lib/padrino-core/server.rb
167
164
  - lib/padrino-core/support_lite.rb
@@ -176,7 +173,16 @@ files:
176
173
  - test/fixtures/apps/.components
177
174
  - test/fixtures/apps/.gitignore
178
175
  - test/fixtures/apps/complex.rb
176
+ - test/fixtures/apps/helpers/system_helpers.rb
177
+ - test/fixtures/apps/kiq.rb
178
+ - test/fixtures/apps/lib/myklass.rb
179
+ - test/fixtures/apps/lib/myklass/mysubklass.rb
180
+ - test/fixtures/apps/models/child.rb
181
+ - test/fixtures/apps/models/parent.rb
182
+ - test/fixtures/apps/render.rb
179
183
  - test/fixtures/apps/simple.rb
184
+ - test/fixtures/apps/system.rb
185
+ - test/fixtures/apps/views/blog/post.erb
180
186
  - test/fixtures/dependencies/a.rb
181
187
  - test/fixtures/dependencies/b.rb
182
188
  - test/fixtures/dependencies/c.rb
@@ -197,6 +203,7 @@ files:
197
203
  - test/test_mounter.rb
198
204
  - test/test_reloader_complex.rb
199
205
  - test/test_reloader_simple.rb
206
+ - test/test_reloader_system.rb
200
207
  - test/test_rendering.rb
201
208
  - test/test_rendering_extensions.rb
202
209
  - test/test_restful_routing.rb
@@ -204,7 +211,8 @@ files:
204
211
  - test/test_routing.rb
205
212
  - test/test_support_lite.rb
206
213
  homepage: http://www.padrinorb.com
207
- licenses: []
214
+ licenses:
215
+ - MIT
208
216
  metadata: {}
209
217
  post_install_message:
210
218
  rdoc_options:
@@ -218,9 +226,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
226
  version: '0'
219
227
  required_rubygems_version: !ruby/object:Gem::Requirement
220
228
  requirements:
221
- - - '>='
229
+ - - '>'
222
230
  - !ruby/object:Gem::Version
223
- version: 1.3.6
231
+ version: 1.3.1
224
232
  requirements: []
225
233
  rubyforge_project: padrino-core
226
234
  rubygems_version: 2.0.6
@@ -236,7 +244,16 @@ test_files:
236
244
  - test/fixtures/apps/.components
237
245
  - test/fixtures/apps/.gitignore
238
246
  - test/fixtures/apps/complex.rb
247
+ - test/fixtures/apps/helpers/system_helpers.rb
248
+ - test/fixtures/apps/kiq.rb
249
+ - test/fixtures/apps/lib/myklass.rb
250
+ - test/fixtures/apps/lib/myklass/mysubklass.rb
251
+ - test/fixtures/apps/models/child.rb
252
+ - test/fixtures/apps/models/parent.rb
253
+ - test/fixtures/apps/render.rb
239
254
  - test/fixtures/apps/simple.rb
255
+ - test/fixtures/apps/system.rb
256
+ - test/fixtures/apps/views/blog/post.erb
240
257
  - test/fixtures/dependencies/a.rb
241
258
  - test/fixtures/dependencies/b.rb
242
259
  - test/fixtures/dependencies/c.rb
@@ -257,6 +274,7 @@ test_files:
257
274
  - test/test_mounter.rb
258
275
  - test/test_reloader_complex.rb
259
276
  - test/test_reloader_simple.rb
277
+ - test/test_reloader_system.rb
260
278
  - test/test_rendering.rb
261
279
  - test/test_rendering_extensions.rb
262
280
  - test/test_restful_routing.rb