padrino-core 0.9.26 → 0.9.27
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/padrino-core.rb +21 -0
- data/lib/padrino-core/application.rb +11 -28
- data/lib/padrino-core/application/rendering.rb +4 -1
- data/lib/padrino-core/application/routing.rb +30 -8
- data/lib/padrino-core/application/showexceptions.rb +3 -10
- data/lib/padrino-core/cli/rake.rb +2 -1
- data/lib/padrino-core/logger.rb +2 -1
- data/lib/padrino-core/reloader.rb +1 -1
- data/lib/padrino-core/support_lite.rb +10 -3
- data/lib/padrino-core/version.rb +1 -1
- data/padrino-core.gemspec +1 -1
- data/test/test_application.rb +32 -4
- data/test/test_core.rb +3 -1
- data/test/test_logger.rb +13 -4
- data/test/test_reloader_simple.rb +2 -2
- data/test/test_routing.rb +41 -1
- metadata +7 -7
data/lib/padrino-core.rb
CHANGED
@@ -51,6 +51,27 @@ module Padrino
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
##
|
55
|
+
# Configure Global Project Settings for mounted apps. These can be overloaded
|
56
|
+
# in each individual app's own personal configuration. This can be used like:
|
57
|
+
#
|
58
|
+
# Padrino.configure_apps do
|
59
|
+
# enable :sessions
|
60
|
+
# disable :raise_errors
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
def configure_apps(&block)
|
64
|
+
@_global_configuration = block if block_given?
|
65
|
+
end
|
66
|
+
|
67
|
+
###
|
68
|
+
# Returns project-wide configuration settings
|
69
|
+
# defined in 'configure_apps' block
|
70
|
+
#
|
71
|
+
def apps_configuration
|
72
|
+
@_global_configuration
|
73
|
+
end
|
74
|
+
|
54
75
|
##
|
55
76
|
# Default encoding to UTF8.
|
56
77
|
#
|
@@ -29,7 +29,11 @@ module Padrino
|
|
29
29
|
#
|
30
30
|
def new(*args, &bk)
|
31
31
|
setup_application!
|
32
|
+
logging, logging_was = false, logging
|
33
|
+
show_exceptions, show_exceptions_was = false, show_exceptions
|
32
34
|
super(*args, &bk)
|
35
|
+
ensure
|
36
|
+
logging, show_exceptions = logging_was, show_exceptions_was
|
33
37
|
end
|
34
38
|
|
35
39
|
##
|
@@ -127,25 +131,23 @@ module Padrino
|
|
127
131
|
# Overwriting Sinatra defaults
|
128
132
|
set :app_file, File.expand_path(caller_files.first || $0) # Assume app file is first caller
|
129
133
|
set :environment, Padrino.env
|
130
|
-
set :
|
131
|
-
set :
|
132
|
-
set :logging, false
|
133
|
-
set :padrino_logging, true
|
134
|
+
set :reload, Proc.new { development? }
|
135
|
+
set :logging, Proc.new { development? }
|
134
136
|
set :method_override, true
|
135
137
|
set :sessions, false
|
136
|
-
set :session_path, '/'
|
137
138
|
set :public, Proc.new { Padrino.root('public', uri_root) }
|
138
139
|
set :views, Proc.new { File.join(root, "views") }
|
139
140
|
set :images_path, Proc.new { File.join(public, "images") }
|
140
141
|
# Padrino specific
|
141
142
|
set :uri_root, "/"
|
142
|
-
set :reload, Proc.new { development? }
|
143
143
|
set :app_name, self.to_s.underscore.to_sym
|
144
144
|
set :default_builder, 'StandardFormBuilder'
|
145
145
|
set :flash, defined?(Rack::Flash)
|
146
146
|
set :authentication, false
|
147
147
|
# Padrino locale
|
148
148
|
set :locale_path, Proc.new { Dir[File.join(self.root, "/locale/**/*.{rb,yml}")] }
|
149
|
+
# Load the Global Configurations
|
150
|
+
class_eval(&Padrino.apps_configuration) if Padrino.apps_configuration
|
149
151
|
end
|
150
152
|
|
151
153
|
##
|
@@ -190,7 +192,8 @@ module Padrino
|
|
190
192
|
# Requires the Padrino middleware
|
191
193
|
#
|
192
194
|
def register_initializers
|
193
|
-
use Padrino::
|
195
|
+
use Padrino::ShowExceptions if show_exceptions?
|
196
|
+
use Padrino::Logger::Rack, uri_root if Padrino.logger && logging?
|
194
197
|
use Padrino::Reloader::Rack if reload?
|
195
198
|
use Rack::Flash if flash?
|
196
199
|
end
|
@@ -209,26 +212,6 @@ module Padrino
|
|
209
212
|
def require_load_paths
|
210
213
|
load_paths.each { |path| Padrino.require_dependencies(File.join(self.root, path)) }
|
211
214
|
end
|
212
|
-
|
213
|
-
private
|
214
|
-
|
215
|
-
def setup_sessions(builder)
|
216
|
-
return unless sessions?
|
217
|
-
options = {}
|
218
|
-
options[:secret] = session_secret if session_secret?
|
219
|
-
options[:path] = session_path if session_path?
|
220
|
-
options.merge!(sessions.to_hash) if sessions.respond_to?(:to_hash)
|
221
|
-
builder.use Rack::Session::Cookie, options
|
222
|
-
end
|
223
215
|
end # self
|
224
|
-
|
225
|
-
private
|
226
|
-
def clean_backtrace(trace)
|
227
|
-
return trace unless settings.clean_trace?
|
228
|
-
trace.reject { |line|
|
229
|
-
line =~ /lib\/sinatra.*\.rb|lib\/padrino.*\.rb/ ||
|
230
|
-
(defined?(Gem) && line.include?(Gem.dir))
|
231
|
-
}.map! { |line| line.gsub(/^\.\//, '') }
|
232
|
-
end
|
233
216
|
end # Application
|
234
|
-
end # Padrino
|
217
|
+
end # Padrino
|
@@ -110,7 +110,10 @@ module Padrino
|
|
110
110
|
# If engine is a hash then render data converted to json
|
111
111
|
return engine.to_json if engine.is_a?(Hash)
|
112
112
|
|
113
|
-
#
|
113
|
+
# If engine is nil, ignore engine parameter
|
114
|
+
engine, data = data, options if engine.nil? && data
|
115
|
+
|
116
|
+
# Data can actually be a hash of options in certain render cases
|
114
117
|
options.merge!(data) && data = nil if data.is_a?(Hash)
|
115
118
|
|
116
119
|
# If an engine is a string then this is a likely a path to be resolved
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'http_router' unless defined?(HttpRouter)
|
2
2
|
require 'padrino-core/support_lite' unless defined?(SupportLite)
|
3
3
|
|
4
|
-
class Sinatra::Request
|
4
|
+
class Sinatra::Request #:nodoc:
|
5
5
|
attr_accessor :route_obj
|
6
6
|
|
7
7
|
def controller
|
@@ -233,8 +233,19 @@ module Padrino
|
|
233
233
|
end
|
234
234
|
alias :urls :router
|
235
235
|
|
236
|
+
def recognition_router
|
237
|
+
@recognition_router ||= HttpRouter.new
|
238
|
+
end
|
239
|
+
|
236
240
|
def reset_router!
|
237
|
-
|
241
|
+
router.reset!
|
242
|
+
recognition_router.reset!
|
243
|
+
end
|
244
|
+
|
245
|
+
def recognize_path(path)
|
246
|
+
if response = @recognition_router.recognize(Rack::MockRequest.env_for(path))
|
247
|
+
[response.path.route.named, response.params]
|
248
|
+
end
|
238
249
|
end
|
239
250
|
|
240
251
|
##
|
@@ -277,11 +288,6 @@ module Padrino
|
|
277
288
|
route('HEAD', path, *args, &block)
|
278
289
|
end
|
279
290
|
|
280
|
-
def put(path, *args, &bk); route 'PUT', path, *args, &bk end
|
281
|
-
def post(path, *args, &bk); route 'POST', path, *args, &bk end
|
282
|
-
def delete(path, *args, &bk); route 'DELETE', path, *args, &bk end
|
283
|
-
def head(path, *args, &bk); route 'HEAD', path, *args, &bk end
|
284
|
-
|
285
291
|
private
|
286
292
|
# Parse params from the url method
|
287
293
|
def value_to_param(value)
|
@@ -382,6 +388,8 @@ module Padrino
|
|
382
388
|
end
|
383
389
|
end
|
384
390
|
|
391
|
+
recognition_router.add(path).name(name).to(name)
|
392
|
+
|
385
393
|
# Add Sinatra conditions
|
386
394
|
options.each { |option, args|
|
387
395
|
if route.respond_to?(option)
|
@@ -432,6 +440,7 @@ module Padrino
|
|
432
440
|
# Now we can eval route, but because we have "throw halt" we need to be
|
433
441
|
# (en)sure to reset old layout and run controller after filters.
|
434
442
|
begin
|
443
|
+
@route = route
|
435
444
|
@_response_buffer = catch(:halt) { route_eval(&block) }
|
436
445
|
processed = true
|
437
446
|
ensure
|
@@ -513,7 +522,7 @@ module Padrino
|
|
513
522
|
path = "#{@_map}/#{path}".squeeze('/') unless absolute_map or @_map.blank?
|
514
523
|
|
515
524
|
# Small reformats
|
516
|
-
path.gsub!(%r{/\?$}, '(/)')
|
525
|
+
path.gsub!(%r{/\?$}, '(/)') # Remove index path
|
517
526
|
path.gsub!(%r{/?index/?}, '/') # Remove index path
|
518
527
|
path.gsub!(%r{//$}, '/') # Remove index path
|
519
528
|
path[0,0] = "/" unless path =~ %r{^\(?/} # Paths must start with a /
|
@@ -650,6 +659,19 @@ module Padrino
|
|
650
659
|
end
|
651
660
|
alias :url_for :url
|
652
661
|
|
662
|
+
def recognize_path(path)
|
663
|
+
self.class.recognize_path(path)
|
664
|
+
end
|
665
|
+
|
666
|
+
def current_path(*path_params)
|
667
|
+
if path_params.last.is_a?(Hash)
|
668
|
+
path_params[-1] = params.merge(path_params[-1])
|
669
|
+
else
|
670
|
+
path_params << params
|
671
|
+
end
|
672
|
+
@route.url(*path_params)
|
673
|
+
end
|
674
|
+
|
653
675
|
##
|
654
676
|
# This is mostly just a helper so request.path_info isn't changed when
|
655
677
|
# serving files from the public directory
|
@@ -2,13 +2,8 @@ module Padrino
|
|
2
2
|
##
|
3
3
|
# This module extend Sinatra::ShowExceptions adding Padrino as "Framework"
|
4
4
|
#
|
5
|
-
|
6
|
-
|
7
|
-
def self.included(base)
|
8
|
-
base.alias_method_chain :frame_class, :padrino
|
9
|
-
end
|
10
|
-
|
11
|
-
def frame_class_with_padrino(frame)
|
5
|
+
class ShowExceptions < Sinatra::ShowExceptions
|
6
|
+
def frame_class(frame)
|
12
7
|
if frame.filename =~ /lib\/sinatra.*\.rb|lib\/padrino.*\.rb/
|
13
8
|
"framework"
|
14
9
|
elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) ||
|
@@ -20,6 +15,4 @@ module Padrino
|
|
20
15
|
end
|
21
16
|
end
|
22
17
|
end # ShowExceptions
|
23
|
-
end # Padrino
|
24
|
-
|
25
|
-
Sinatra::ShowExceptions.send(:include, Padrino::ShowExceptions)
|
18
|
+
end # Padrino
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../tasks')
|
2
2
|
require 'rake'
|
3
|
+
require 'securerandom' unless defined?(SecureRandom)
|
3
4
|
Rake.application.instance_variable_set(:@rakefile, __FILE__)
|
4
5
|
|
5
6
|
module PadrinoTasks
|
@@ -30,7 +31,7 @@ end
|
|
30
31
|
|
31
32
|
desc "Generate a secret key"
|
32
33
|
task :secret do
|
33
|
-
shell.say
|
34
|
+
shell.say SecureRandom.hex(32)
|
34
35
|
end
|
35
36
|
|
36
37
|
# lists all routes of a given app
|
data/lib/padrino-core/logger.rb
CHANGED
@@ -68,7 +68,7 @@ module Padrino
|
|
68
68
|
#
|
69
69
|
# ==== Examples
|
70
70
|
#
|
71
|
-
# Padrino::Logger::Config[:development] = { :log_level => :debug, :to_file }
|
71
|
+
# Padrino::Logger::Config[:development] = { :log_level => :debug, :stream => :to_file }
|
72
72
|
# # or you can edit our defaults
|
73
73
|
# Padrino::Logger::Config[:development][:log_level] = :error
|
74
74
|
# # or you can use your stream
|
@@ -284,6 +284,7 @@ module Padrino
|
|
284
284
|
end
|
285
285
|
|
286
286
|
def call(env)
|
287
|
+
env['rack.logger'] = Padrino.logger
|
287
288
|
began_at = Time.now
|
288
289
|
status, header, body = @app.call(env)
|
289
290
|
log(env, status, header, began_at)
|
@@ -214,7 +214,7 @@ module Padrino
|
|
214
214
|
files = paths.map { |path| Dir["#{path}/**/*.rb"] }.flatten.uniq
|
215
215
|
|
216
216
|
files.map { |file|
|
217
|
-
next if Padrino::Reloader.exclude.any? { |base| file =~ /^#{base}/ }
|
217
|
+
next if Padrino::Reloader.exclude.any? { |base| file =~ /^#{Regexp.escape(base)}/ }
|
218
218
|
|
219
219
|
found, stat = figure_path(file, paths)
|
220
220
|
next unless found && stat && mtime = stat.mtime
|
@@ -3,11 +3,12 @@
|
|
3
3
|
#
|
4
4
|
# Why use ActiveSupport and not our own library or extlib?
|
5
5
|
#
|
6
|
-
# 1) Rewriting custom method extensions
|
6
|
+
# 1) Rewriting custom method extensions required (i.e string inflectors) is not a good use of time.
|
7
7
|
# 2) Loading custom method extensions or separate gems would conflict with AS when AR or MM has been loaded.
|
8
8
|
# 3) Datamapper 1.0 supports ActiveSupport 3.0 and no longer requires extlib.
|
9
9
|
#
|
10
10
|
|
11
|
+
# ActiveSupport Required Extensions
|
11
12
|
require 'active_support/core_ext/string/conversions' unless String.method_defined?(:to_date)
|
12
13
|
require 'active_support/core_ext/kernel' unless Kernel.method_defined?(:silence_warnings)
|
13
14
|
require 'active_support/core_ext/module' unless Module.method_defined?(:alias_method_chain)
|
@@ -23,6 +24,7 @@ require 'active_support/inflector' unless String.method_define
|
|
23
24
|
require 'active_support/core_ext/float/rounding' unless Float.method_defined?(:round)
|
24
25
|
require 'active_support/option_merger' unless defined?(ActiveSupport::OptionMerger)
|
25
26
|
|
27
|
+
# Loads symbol to proc extensions
|
26
28
|
begin
|
27
29
|
require 'active_support/core_ext/symbol'
|
28
30
|
rescue LoadError
|
@@ -58,7 +60,7 @@ if defined?(ActiveSupport::CoreExtensions::Hash) && !Hash.method_defined?(:slice
|
|
58
60
|
end
|
59
61
|
|
60
62
|
##
|
61
|
-
# Used to know if this file
|
63
|
+
# Used to know if this file has already been required
|
62
64
|
#
|
63
65
|
module SupportLite; end unless defined?(SupportLite)
|
64
66
|
|
@@ -106,7 +108,12 @@ class FileSet
|
|
106
108
|
end
|
107
109
|
end unless defined?(FileSet)
|
108
110
|
|
111
|
+
# YAML Engine Parsing Fix
|
112
|
+
# https://github.com/padrino/padrino-framework/issues/424
|
113
|
+
require 'yaml' unless defined?(YAML)
|
114
|
+
YAML::ENGINE.yamler = "syck" if defined?(YAML::ENGINE)
|
115
|
+
|
109
116
|
##
|
110
|
-
# Loads our
|
117
|
+
# Loads our locale configuration files
|
111
118
|
#
|
112
119
|
I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"] if defined?(I18n)
|
data/lib/padrino-core/version.rb
CHANGED
data/padrino-core.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.rdoc_options = ["--charset=UTF-8"]
|
22
22
|
|
23
23
|
s.add_dependency("tilt", "~> 1.3.0")
|
24
|
-
s.add_dependency("sinatra", "~> 1.2.
|
24
|
+
s.add_dependency("sinatra", "~> 1.2.6")
|
25
25
|
s.add_dependency("http_router", "~> 0.7.5")
|
26
26
|
s.add_dependency("thor", ">=0.14.3")
|
27
27
|
s.add_dependency("activesupport", ">= 3.0.0")
|
data/test/test_application.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
2
|
|
3
3
|
class PadrinoTestApp < Padrino::Application; end
|
4
|
+
class PadrinoTestApp2 < Padrino::Application; end
|
4
5
|
|
5
6
|
class TestApplication < Test::Unit::TestCase
|
6
7
|
def setup
|
@@ -20,8 +21,11 @@ class TestApplication < Test::Unit::TestCase
|
|
20
21
|
assert_equal Padrino.root("views"), PadrinoTestApp.views
|
21
22
|
assert PadrinoTestApp.raise_errors
|
22
23
|
assert !PadrinoTestApp.logging
|
23
|
-
assert PadrinoTestApp.padrino_logging
|
24
24
|
assert !PadrinoTestApp.sessions
|
25
|
+
assert !PadrinoTestApp.dump_errors
|
26
|
+
assert !PadrinoTestApp.show_exceptions
|
27
|
+
assert PadrinoTestApp.raise_errors
|
28
|
+
assert !Padrino.configure_apps
|
25
29
|
end
|
26
30
|
|
27
31
|
should 'check padrino specific options' do
|
@@ -34,6 +38,29 @@ class TestApplication < Test::Unit::TestCase
|
|
34
38
|
assert !PadrinoTestApp.flash
|
35
39
|
end
|
36
40
|
|
41
|
+
should 'set global project settings' do
|
42
|
+
Padrino.configure_apps { enable :sessions; set :foo, "bar" }
|
43
|
+
PadrinoTestApp.send(:default_configuration!)
|
44
|
+
PadrinoTestApp2.send(:default_configuration!)
|
45
|
+
assert PadrinoTestApp.sessions, "should have sessions enabled"
|
46
|
+
assert_equal "bar", PadrinoTestApp.settings.foo, "should have foo assigned"
|
47
|
+
assert_equal PadrinoTestApp.session_secret, PadrinoTestApp2.session_secret
|
48
|
+
end
|
49
|
+
|
50
|
+
should "have shared sessions accessible in project" do
|
51
|
+
Padrino.configure_apps { enable :sessions; set :session_secret, 'secret' }
|
52
|
+
Padrino.mount("PadrinoTestApp").to("/write")
|
53
|
+
Padrino.mount("PadrinoTestApp2").to("/read")
|
54
|
+
PadrinoTestApp.tap { |app| app.send(:default_configuration!)
|
55
|
+
app.get("/") { session[:foo] = "shared" } }
|
56
|
+
PadrinoTestApp2.tap { |app| app.send(:default_configuration!)
|
57
|
+
app.get("/") { session[:foo] } }
|
58
|
+
browser = Rack::Test::Session.new(Rack::MockSession.new(Padrino.application))
|
59
|
+
browser.get '/write'
|
60
|
+
browser.get '/read'
|
61
|
+
assert_equal 'shared', browser.last_response.body
|
62
|
+
end
|
63
|
+
|
37
64
|
# compare to: test_routing: allow global provides
|
38
65
|
should "set content_type to :html if none can be determined" do
|
39
66
|
mock_app do
|
@@ -50,6 +77,7 @@ class TestApplication < Test::Unit::TestCase
|
|
50
77
|
|
51
78
|
get '/bar', {}, { 'HTTP_ACCEPT' => 'application/xml' }
|
52
79
|
assert_equal "Foo in html", body
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
80
|
+
end # content_type to :html
|
81
|
+
end # application functionality
|
82
|
+
|
83
|
+
end
|
data/test/test_core.rb
CHANGED
@@ -16,8 +16,10 @@ class TestCore < Test::Unit::TestCase
|
|
16
16
|
assert_respond_to Padrino, :reload!
|
17
17
|
assert_respond_to Padrino, :version
|
18
18
|
assert_respond_to Padrino, :bundle
|
19
|
+
assert_respond_to Padrino, :configure_apps
|
19
20
|
end
|
20
21
|
|
22
|
+
|
21
23
|
should 'validate global helpers' do
|
22
24
|
assert_equal :test, Padrino.env
|
23
25
|
assert_match /\/test/, Padrino.root
|
@@ -60,4 +62,4 @@ class TestCore < Test::Unit::TestCase
|
|
60
62
|
assert_equal "yes", res["Middleware-Called"]
|
61
63
|
end
|
62
64
|
end
|
63
|
-
end
|
65
|
+
end
|
data/test/test_logger.rb
CHANGED
@@ -55,7 +55,10 @@ class TestPadrinoLogger < Test::Unit::TestCase
|
|
55
55
|
end
|
56
56
|
|
57
57
|
should 'log an application' do
|
58
|
-
mock_app
|
58
|
+
mock_app do
|
59
|
+
enable :logging
|
60
|
+
get("/"){ "Foo" }
|
61
|
+
end
|
59
62
|
get "/"
|
60
63
|
assert_equal "Foo", body
|
61
64
|
assert_match /GET/, Padrino.logger.log.string
|
@@ -63,7 +66,10 @@ class TestPadrinoLogger < Test::Unit::TestCase
|
|
63
66
|
|
64
67
|
context "static asset logging" do
|
65
68
|
should 'not log static assets by default' do
|
66
|
-
mock_app
|
69
|
+
mock_app do
|
70
|
+
enable :logging
|
71
|
+
get("/images/something.png"){ env["sinatra.static_file"] = '/public/images/something.png'; "Foo" }
|
72
|
+
end
|
67
73
|
get "/images/something.png"
|
68
74
|
assert_equal "Foo", body
|
69
75
|
assert_match "", Padrino.logger.log.string
|
@@ -71,7 +77,10 @@ class TestPadrinoLogger < Test::Unit::TestCase
|
|
71
77
|
|
72
78
|
should 'allow turning on static assets logging' do
|
73
79
|
Padrino.logger.instance_eval{ @log_static = true }
|
74
|
-
mock_app
|
80
|
+
mock_app do
|
81
|
+
enable :logging
|
82
|
+
get("/images/something.png"){ env["sinatra.static_file"] = '/public/images/something.png'; "Foo" }
|
83
|
+
end
|
75
84
|
get "/images/something.png"
|
76
85
|
assert_equal "Foo", body
|
77
86
|
assert_match /GET/, Padrino.logger.log.string
|
@@ -79,4 +88,4 @@ class TestPadrinoLogger < Test::Unit::TestCase
|
|
79
88
|
end
|
80
89
|
end
|
81
90
|
end
|
82
|
-
end
|
91
|
+
end
|
@@ -78,7 +78,7 @@ class TestSimpleReloader < Test::Unit::TestCase
|
|
78
78
|
assert_equal 2, @app.filters[:before].size # one is ours the other is default_filter for content type
|
79
79
|
assert_equal 1, @app.errors.size
|
80
80
|
assert_equal 1, @app.filters[:after].size
|
81
|
-
assert_equal
|
81
|
+
assert_equal 1, @app.middleware.size # [Padrino::Reloader::Rack]
|
82
82
|
assert_equal 4, @app.routes.size # GET+HEAD of "/" + GET+HEAD of "/rand" = 4
|
83
83
|
assert_equal 2, @app.extensions.size # [Padrino::Routing, Padrino::Rendering]
|
84
84
|
assert_equal 0, @app.templates.size
|
@@ -88,7 +88,7 @@ class TestSimpleReloader < Test::Unit::TestCase
|
|
88
88
|
assert_equal 2, @app.filters[:before].size # one is ours the other is default_filter for content type
|
89
89
|
assert_equal 1, @app.errors.size
|
90
90
|
assert_equal 1, @app.filters[:after].size
|
91
|
-
assert_equal
|
91
|
+
assert_equal 1, @app.middleware.size
|
92
92
|
assert_equal 4, @app.routes.size # GET+HEAD of "/" = 2
|
93
93
|
assert_equal 2, @app.extensions.size # [Padrino::Routing, Padrino::Rendering]
|
94
94
|
assert_equal 0, @app.templates.size
|
data/test/test_routing.rb
CHANGED
@@ -1355,7 +1355,7 @@ class TestRouting < Test::Unit::TestCase
|
|
1355
1355
|
mock_app { set :environment, :development }
|
1356
1356
|
get "/"
|
1357
1357
|
assert_equal 404, status
|
1358
|
-
assert_match /Sinatra doesn
|
1358
|
+
assert_match /Sinatra doesn’t know this ditty./, body
|
1359
1359
|
end
|
1360
1360
|
|
1361
1361
|
should 'render a custom NotFound page' do
|
@@ -1375,4 +1375,44 @@ class TestRouting < Test::Unit::TestCase
|
|
1375
1375
|
assert_equal 404, status
|
1376
1376
|
assert_match /not found/, body
|
1377
1377
|
end
|
1378
|
+
|
1379
|
+
should 'recognize paths' do
|
1380
|
+
mock_app do
|
1381
|
+
controller :foo do
|
1382
|
+
get(:bar, :map => "/my/:id/custom-route") { }
|
1383
|
+
end
|
1384
|
+
get(:simple, :map => "/simple/:id") { }
|
1385
|
+
get(:with_format, :with => :id, :provides => :js) { }
|
1386
|
+
end
|
1387
|
+
assert_equal [:foo_bar, { :id => "fantastic" }], @app.recognize_path(@app.url(:foo, :bar, :id => :fantastic))
|
1388
|
+
assert_equal [:foo_bar, { :id => "18" }], @app.recognize_path(@app.url(:foo, :bar, :id => 18))
|
1389
|
+
assert_equal [:simple, { :id => "bar" }], @app.recognize_path(@app.url(:simple, :id => "bar"))
|
1390
|
+
assert_equal [:simple, { :id => "true" }], @app.recognize_path(@app.url(:simple, :id => true))
|
1391
|
+
assert_equal [:simple, { :id => "9" }], @app.recognize_path(@app.url(:simple, :id => 9))
|
1392
|
+
assert_equal [:with_format, { :id => "bar", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => "bar", :format => :js))
|
1393
|
+
assert_equal [:with_format, { :id => "true", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => true, :format => "js"))
|
1394
|
+
assert_equal [:with_format, { :id => "9", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => 9, :format => :js))
|
1395
|
+
end
|
1396
|
+
|
1397
|
+
should 'have current_path' do
|
1398
|
+
mock_app do
|
1399
|
+
controller :foo do
|
1400
|
+
get :bar, :map => "/paginate/:page" do
|
1401
|
+
current_path
|
1402
|
+
end
|
1403
|
+
end
|
1404
|
+
end
|
1405
|
+
get @app.url(:foo, :bar, :page => 10)
|
1406
|
+
assert_equal "/paginate/10", body
|
1407
|
+
end
|
1408
|
+
|
1409
|
+
should 'change params in current_path' do
|
1410
|
+
mock_app do
|
1411
|
+
get :index, :map => "/paginate/:page" do
|
1412
|
+
current_path(:page => 66)
|
1413
|
+
end
|
1414
|
+
end
|
1415
|
+
get @app.url(:index, :page => 10)
|
1416
|
+
assert_equal "/paginate/66", body
|
1417
|
+
end
|
1378
1418
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 27
|
10
|
+
version: 0.9.27
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Padrino Team
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2011-
|
21
|
+
date: 2011-05-06 00:00:00 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: tilt
|
@@ -44,12 +44,12 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
hash:
|
47
|
+
hash: 19
|
48
48
|
segments:
|
49
49
|
- 1
|
50
50
|
- 2
|
51
|
-
-
|
52
|
-
version: 1.2.
|
51
|
+
- 6
|
52
|
+
version: 1.2.6
|
53
53
|
type: :runtime
|
54
54
|
version_requirements: *id002
|
55
55
|
- !ruby/object:Gem::Dependency
|