padrino-core 0.12.3 → 0.12.4
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.
- checksums.yaml +4 -4
- data/lib/padrino-core/application.rb +1 -2
- data/lib/padrino-core/application/application_setup.rb +0 -11
- data/lib/padrino-core/application/params_protection.rb +3 -3
- data/lib/padrino-core/application/routing.rb +28 -21
- data/lib/padrino-core/ext/http_router.rb +20 -0
- data/lib/padrino-core/filter.rb +7 -2
- data/lib/padrino-core/loader.rb +2 -2
- data/lib/padrino-core/mounter.rb +72 -8
- data/lib/padrino-core/reloader.rb +5 -1
- data/lib/padrino-core/server.rb +1 -1
- data/lib/padrino-core/version.rb +1 -1
- data/test/fixtures/apps/demo_project/api/app.rb +7 -0
- data/test/fixtures/apps/demo_project/api/lib/api_lib.rb +3 -0
- data/test/fixtures/apps/demo_project/app.rb +7 -0
- data/test/fixtures/apps/rack_apps.rb +15 -0
- data/test/fixtures/apps/static.html +1 -0
- data/test/fixtures/reloadable_apps/external/app/app.rb +6 -0
- data/test/fixtures/reloadable_apps/external/app/controllers/base.rb +6 -0
- data/test/fixtures/reloadable_apps/main/app.rb +10 -0
- data/test/test_core.rb +0 -5
- data/test/test_mounter.rb +32 -0
- data/test/test_params_protection.rb +24 -0
- data/test/test_reloader_complex.rb +2 -2
- data/test/test_reloader_external.rb +21 -0
- data/test/test_reloader_simple.rb +3 -3
- data/test/test_reloader_system.rb +0 -10
- data/test/test_routing.rb +42 -2
- metadata +22 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f87c42ee6dafccf2f672e07adc52c3bb79102e09
|
4
|
+
data.tar.gz: b25c8da4bc6a104c7a688b7a62e69b17aeb5ad50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb6c04b20312a6fd49a9a75343a1fc75fb19a2a359e0321ba4dd67132c7e15d83e063a41f0125b34570476344fc327cd9bbb51b089761764487152404f369fc4
|
7
|
+
data.tar.gz: 57ca2a537531341e765ba190ed9be1b1a6510846d1964bef9f65a734cfc73fcbcee0ea1071bef87e0d680c1e5b422f8dd2bd8547a6f77b030d0395416a7ca240
|
@@ -65,7 +65,6 @@ module Padrino
|
|
65
65
|
reset_router!
|
66
66
|
Padrino.require_dependencies(settings.app_file, :force => true)
|
67
67
|
require_dependencies
|
68
|
-
default_filters
|
69
68
|
default_routes
|
70
69
|
default_errors
|
71
70
|
I18n.reload! if defined?(I18n)
|
@@ -149,7 +148,7 @@ module Padrino
|
|
149
148
|
'controllers.rb',
|
150
149
|
'helpers/**/*.rb',
|
151
150
|
'helpers.rb',
|
152
|
-
].
|
151
|
+
].flat_map{ |file| Dir.glob(File.join(settings.root, file)) }
|
153
152
|
end
|
154
153
|
|
155
154
|
##
|
@@ -42,7 +42,6 @@ module Padrino
|
|
42
42
|
def setup_application!
|
43
43
|
return if @_configured
|
44
44
|
require_dependencies
|
45
|
-
default_filters
|
46
45
|
default_routes
|
47
46
|
default_errors
|
48
47
|
setup_locale
|
@@ -109,16 +108,6 @@ module Padrino
|
|
109
108
|
setup_application!
|
110
109
|
end
|
111
110
|
|
112
|
-
##
|
113
|
-
# This filter it's used for know the format of the request, and
|
114
|
-
# automatically set the content type.
|
115
|
-
#
|
116
|
-
def default_filters
|
117
|
-
before do
|
118
|
-
response['Content-Type'] = 'text/html;charset=utf-8' unless @_content_type
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
111
|
##
|
123
112
|
# We need to add almost __sinatra__ images.
|
124
113
|
#
|
@@ -1,6 +1,6 @@
|
|
1
1
|
begin
|
2
2
|
require 'active_support/core_ext/object/deep_dup' # AS 4.1
|
3
|
-
rescue LoadError
|
3
|
+
rescue LoadError
|
4
4
|
require 'active_support/core_ext/hash/deep_dup' # AS >= 3.1
|
5
5
|
end
|
6
6
|
|
@@ -99,8 +99,8 @@ module Padrino
|
|
99
99
|
type = allowed_params[key]
|
100
100
|
next if value.kind_of?(Array) && type
|
101
101
|
case
|
102
|
-
when type.kind_of?(Hash)
|
103
|
-
if key == key.pluralize
|
102
|
+
when type.kind_of?(Hash) && value.kind_of?(Hash)
|
103
|
+
if key == key.pluralize && value.values.first.kind_of?(Hash)
|
104
104
|
value.each do |array_index,array_value|
|
105
105
|
value[array_index] = filter_params!(array_value, type)
|
106
106
|
end
|
@@ -367,6 +367,21 @@ module Padrino
|
|
367
367
|
end
|
368
368
|
end
|
369
369
|
|
370
|
+
##
|
371
|
+
# Processes the existing path and prepends the 'parent' parameters onto the route
|
372
|
+
# Used for calculating path in route method.
|
373
|
+
#
|
374
|
+
def process_path_for_parent_params(path, parent_params)
|
375
|
+
parent_prefix = parent_params.flatten.compact.uniq.map do |param|
|
376
|
+
map = (param.respond_to?(:map) && param.map ? param.map : param.to_s)
|
377
|
+
part = "#{map}/:#{param.to_s.singularize}_id/"
|
378
|
+
part = "(#{part})" if param.respond_to?(:optional) && param.optional?
|
379
|
+
part
|
380
|
+
end
|
381
|
+
|
382
|
+
[parent_prefix, path].flatten.join("")
|
383
|
+
end
|
384
|
+
|
370
385
|
private
|
371
386
|
|
372
387
|
CONTROLLER_OPTIONS = [ :parent, :provides, :use_format, :cache, :expires, :map, :conditions, :accepts, :params ].freeze
|
@@ -517,7 +532,10 @@ module Padrino
|
|
517
532
|
end
|
518
533
|
|
519
534
|
# Add Sinatra conditions.
|
520
|
-
options.each
|
535
|
+
options.each do |option, _args|
|
536
|
+
option = :provides_format if option == :provides
|
537
|
+
route.respond_to?(option) ? route.send(option, *_args) : send(option, *_args)
|
538
|
+
end
|
521
539
|
conditions, @conditions = @conditions, []
|
522
540
|
route.custom_conditions.concat(conditions)
|
523
541
|
|
@@ -576,8 +594,8 @@ module Padrino
|
|
576
594
|
|
577
595
|
options.delete(:accepts) if options[:accepts].nil?
|
578
596
|
|
579
|
-
if @_use_format
|
580
|
-
process_path_for_provides(path
|
597
|
+
if @_use_format || options[:provides]
|
598
|
+
process_path_for_provides(path)
|
581
599
|
# options[:add_match_with] ||= {}
|
582
600
|
# options[:add_match_with][:format] = /[^\.]+/
|
583
601
|
end
|
@@ -636,26 +654,11 @@ module Padrino
|
|
636
654
|
end.join("/"))
|
637
655
|
end
|
638
656
|
|
639
|
-
##
|
640
|
-
# Processes the existing path and prepends the 'parent' parameters onto the route
|
641
|
-
# Used for calculating path in route method.
|
642
|
-
#
|
643
|
-
def process_path_for_parent_params(path, parent_params)
|
644
|
-
parent_prefix = parent_params.flatten.compact.uniq.map do |param|
|
645
|
-
map = (param.respond_to?(:map) && param.map ? param.map : param.to_s)
|
646
|
-
part = "#{map}/:#{param.to_s.singularize}_id/"
|
647
|
-
part = "(#{part})" if param.respond_to?(:optional) && param.optional?
|
648
|
-
part
|
649
|
-
end
|
650
|
-
|
651
|
-
[parent_prefix, path].flatten.join("")
|
652
|
-
end
|
653
|
-
|
654
657
|
##
|
655
658
|
# Processes the existing path and appends the 'format' suffix onto the route.
|
656
659
|
# Used for calculating path in route method.
|
657
660
|
#
|
658
|
-
def process_path_for_provides(path
|
661
|
+
def process_path_for_provides(path)
|
659
662
|
path << "(.:format)" unless path[-10, 10] == '(.:format)'
|
660
663
|
end
|
661
664
|
|
@@ -688,6 +691,10 @@ module Padrino
|
|
688
691
|
#
|
689
692
|
def provides(*types)
|
690
693
|
@_use_format = true
|
694
|
+
provides_format(*types)
|
695
|
+
end
|
696
|
+
|
697
|
+
def provides_format(*types)
|
691
698
|
mime_types = types.map{ |type| mime_type(CONTENT_TYPE_ALIASES[type] || type) }
|
692
699
|
condition do
|
693
700
|
return provides_format?(types, params[:format].to_sym) if params[:format]
|
@@ -843,11 +850,11 @@ module Padrino
|
|
843
850
|
#
|
844
851
|
# Method for deliver static files.
|
845
852
|
#
|
846
|
-
def static!
|
853
|
+
def static!(options = {})
|
847
854
|
if path = static_file?(request.path_info)
|
848
855
|
env['sinatra.static_file'] = path
|
849
856
|
cache_control(*settings.static_cache_control) if settings.static_cache_control?
|
850
|
-
send_file(path,
|
857
|
+
send_file(path, options)
|
851
858
|
end
|
852
859
|
end
|
853
860
|
|
@@ -178,4 +178,24 @@ class HttpRouter
|
|
178
178
|
#{"end" unless route.match_partially}"
|
179
179
|
end
|
180
180
|
end
|
181
|
+
|
182
|
+
class Node::FreeRegex
|
183
|
+
def to_code
|
184
|
+
id = root.next_counter
|
185
|
+
"whole_path#{id} = \"/\#{request.joined_path}\"
|
186
|
+
if match = #{matcher.inspect}.match(whole_path#{id}) and match[0].size == whole_path#{id}.size
|
187
|
+
request.extra_env['router.regex_match'] = match
|
188
|
+
old_path = request.path
|
189
|
+
request.path = ['']
|
190
|
+
" << (use_named_captures? ?
|
191
|
+
"match.names.size.times{|i| request.params << match[i + 1]} if match.respond_to?(:names) && match.names" : "") << "
|
192
|
+
#{super}
|
193
|
+
request.path = old_path
|
194
|
+
request.extra_env.delete('router.regex_match')
|
195
|
+
" << (use_named_captures? ?
|
196
|
+
"request.params.slice!(-match.names.size, match.names.size)" : ""
|
197
|
+
) << "
|
198
|
+
end"
|
199
|
+
end
|
200
|
+
end
|
181
201
|
end
|
data/lib/padrino-core/filter.rb
CHANGED
@@ -3,7 +3,11 @@ module Padrino
|
|
3
3
|
attr_reader :block
|
4
4
|
|
5
5
|
def initialize(mode, scoped_controller, options, args, &block)
|
6
|
-
@mode
|
6
|
+
@mode = mode
|
7
|
+
@scoped_controller = scoped_controller
|
8
|
+
@options = options
|
9
|
+
@args = args
|
10
|
+
@block = block
|
7
11
|
end
|
8
12
|
|
9
13
|
def apply?(request)
|
@@ -27,7 +31,8 @@ module Padrino
|
|
27
31
|
end
|
28
32
|
|
29
33
|
def match_with_arguments?(request)
|
30
|
-
route
|
34
|
+
route = request.route_obj
|
35
|
+
path = request.path_info
|
31
36
|
@args.any? do |argument|
|
32
37
|
if argument.instance_of?(Symbol)
|
33
38
|
next unless route
|
data/lib/padrino-core/loader.rb
CHANGED
@@ -130,10 +130,10 @@ module Padrino
|
|
130
130
|
#
|
131
131
|
def require_dependencies(*paths)
|
132
132
|
options = paths.extract_options!.merge( :cyclic => true )
|
133
|
-
files = paths.flatten.
|
133
|
+
files = paths.flatten.flat_map{ |path| Dir.glob(path).sort_by{ |filename| filename.count('/') } }.uniq
|
134
134
|
|
135
135
|
until files.empty?
|
136
|
-
error
|
136
|
+
error = fatal = loaded = nil
|
137
137
|
|
138
138
|
files.dup.each do |file|
|
139
139
|
begin
|
data/lib/padrino-core/mounter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
1
3
|
module Padrino
|
2
4
|
##
|
3
5
|
# Represents a particular mounted Padrino application.
|
@@ -12,6 +14,55 @@ module Padrino
|
|
12
14
|
class MounterException < RuntimeError
|
13
15
|
end
|
14
16
|
|
17
|
+
class ApplicationWrapper < SimpleDelegator
|
18
|
+
attr_accessor :uri_root
|
19
|
+
attr_writer :public_folder
|
20
|
+
|
21
|
+
def initialize(app, options = {})
|
22
|
+
@options = options
|
23
|
+
super(app)
|
24
|
+
end
|
25
|
+
|
26
|
+
def dependencies
|
27
|
+
@__dependencies ||= Dir["#{root}/**/*.rb"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def prerequisite
|
31
|
+
@__prerequisite ||= []
|
32
|
+
end
|
33
|
+
|
34
|
+
def app_file
|
35
|
+
return @__app_file if @__app_file
|
36
|
+
obj = __getobj__
|
37
|
+
@__app_file = obj.respond_to?(:app_file) ? obj.app_file : @options[:app_file]
|
38
|
+
end
|
39
|
+
|
40
|
+
def root
|
41
|
+
return @__root if @__root
|
42
|
+
obj = __getobj__
|
43
|
+
@__root = obj.respond_to?(:root) ? obj.root : File.expand_path("#{app_file}/../")
|
44
|
+
end
|
45
|
+
|
46
|
+
def public_folder
|
47
|
+
return @public_folder if @public_folder
|
48
|
+
obj = __getobj__
|
49
|
+
@public_folder = obj.respond_to?(:public_folder) ? obj.public_folder : ""
|
50
|
+
end
|
51
|
+
|
52
|
+
def app_name
|
53
|
+
@__app_name ||= @options[:app_name] || __getobj__.to_s.underscore.to_sym
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup_application!
|
57
|
+
@configured ||=
|
58
|
+
begin
|
59
|
+
$LOAD_PATH.concat(prerequisite)
|
60
|
+
Padrino.require_dependencies(dependencies, :force => true)
|
61
|
+
true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
15
66
|
attr_accessor :name, :uri_root, :app_file, :app_class, :app_root, :app_obj, :app_host, :cascade
|
16
67
|
|
17
68
|
##
|
@@ -32,12 +83,19 @@ module Padrino
|
|
32
83
|
@app_file = options[:app_file] || locate_app_file
|
33
84
|
@app_obj = options[:app_obj] || app_constant || locate_app_object
|
34
85
|
ensure_app_file! || ensure_app_object!
|
86
|
+
@app_obj = ApplicationWrapper.new(@app_obj, options) unless padrino_application?
|
35
87
|
@app_root = options[:app_root] || (@app_obj.respond_to?(:root) && @app_obj.root || File.dirname(@app_file))
|
36
88
|
@uri_root = "/"
|
37
89
|
@cascade = options[:cascade] ? true == options[:cascade] ? DEFAULT_CASCADE.dup : Array(options[:cascade]) : []
|
38
90
|
Padrino::Reloader.exclude_constants << @app_class
|
39
91
|
end
|
40
92
|
|
93
|
+
def padrino_application?
|
94
|
+
@app_obj.ancestors.include?(Padrino::Application)
|
95
|
+
rescue NameError
|
96
|
+
false
|
97
|
+
end
|
98
|
+
|
41
99
|
##
|
42
100
|
# Registers the mounted application onto Padrino.
|
43
101
|
#
|
@@ -82,14 +140,20 @@ module Padrino
|
|
82
140
|
# @app.map_onto(router)
|
83
141
|
#
|
84
142
|
def map_onto(router)
|
85
|
-
app_data
|
86
|
-
app_obj
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
143
|
+
app_data = self
|
144
|
+
app_obj = @app_obj
|
145
|
+
if padrino_application?
|
146
|
+
app_obj.set :uri_root, app_data.uri_root
|
147
|
+
app_obj.set :app_name, app_data.app_obj.app_name.to_s
|
148
|
+
app_obj.set :app_file, app_data.app_file unless ::File.exist?(app_obj.app_file)
|
149
|
+
app_obj.set :root, app_data.app_root unless app_data.app_root.blank?
|
150
|
+
app_obj.set :public_folder, Padrino.root('public', app_data.uri_root) unless File.exist?(app_obj.public_folder)
|
151
|
+
app_obj.set :static, File.exist?(app_obj.public_folder) if app_obj.nil?
|
152
|
+
app_obj.set :cascade, app_data.cascade
|
153
|
+
else
|
154
|
+
app_obj.uri_root = app_data.uri_root
|
155
|
+
app_obj.public_folder = Padrino.root('public', app_data.uri_root) unless ::File.exist?(app_obj.public_folder)
|
156
|
+
end
|
93
157
|
app_obj.setup_application! # Initializes the app here with above settings.
|
94
158
|
router.map(:to => app_obj, :path => app_data.uri_root, :host => app_data.app_host)
|
95
159
|
end
|
@@ -269,6 +269,7 @@ module Padrino
|
|
269
269
|
def object_sources(target)
|
270
270
|
sources = Set.new
|
271
271
|
target.methods.each do |method_name|
|
272
|
+
next unless method_name.kind_of?(Symbol)
|
272
273
|
method_object = target.method(method_name)
|
273
274
|
if method_object.owner == (target.class == Class ? target.singleton_class : target.class)
|
274
275
|
sources << method_object.source_location.first
|
@@ -289,7 +290,10 @@ module Padrino
|
|
289
290
|
# Return the apps that allow reloading.
|
290
291
|
#
|
291
292
|
def reloadable_apps
|
292
|
-
Padrino.mounted_apps.select
|
293
|
+
Padrino.mounted_apps.select do |app|
|
294
|
+
next unless app.app_file.start_with?(Padrino.root)
|
295
|
+
app.app_obj.respond_to?(:reload) && app.app_obj.reload?
|
296
|
+
end
|
293
297
|
end
|
294
298
|
|
295
299
|
##
|
data/lib/padrino-core/server.rb
CHANGED
@@ -103,7 +103,7 @@ module Padrino
|
|
103
103
|
# Parses an array of server options.
|
104
104
|
#
|
105
105
|
def self.parse_server_options(options)
|
106
|
-
parsed_server_options = Array(options).
|
106
|
+
parsed_server_options = Array(options).flat_map{ |option| option.split('=', 2) }
|
107
107
|
Hash[*parsed_server_options].symbolize_keys
|
108
108
|
end
|
109
109
|
|
data/lib/padrino-core/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
class RackApp
|
3
|
+
def self.call(_)
|
4
|
+
[200, {}, ["hello rack app"]]
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
RackApp2 = lambda{|_| [200, {}, ["hello rack app2"]] }
|
9
|
+
|
10
|
+
class SinatraApp < Sinatra::Base
|
11
|
+
set :public_folder, File.dirname(__FILE__)
|
12
|
+
get "/" do
|
13
|
+
"hello sinatra app"
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
hello static file
|
data/test/test_core.rb
CHANGED
@@ -29,11 +29,6 @@ describe "Core" do
|
|
29
29
|
assert_equal Encoding.default_internal, Encoding::UTF_8
|
30
30
|
end
|
31
31
|
|
32
|
-
it 'should have load paths' do
|
33
|
-
skip
|
34
|
-
assert_equal [Padrino.root('lib'), Padrino.root('models'), Padrino.root('shared')], Padrino.load_paths
|
35
|
-
end
|
36
|
-
|
37
32
|
it 'should raise application error if I instantiate a new padrino application without mounted apps' do
|
38
33
|
text = capture_io { Padrino.application }
|
39
34
|
assert_match /No apps are mounted/, text.to_s
|
data/test/test_mounter.rb
CHANGED
@@ -253,5 +253,37 @@ describe "Mounter" do
|
|
253
253
|
assert_equal AppGem::App, mounter.app_obj
|
254
254
|
assert_equal Padrino.root('public'), mounter.app_obj.public_folder
|
255
255
|
end
|
256
|
+
|
257
|
+
it 'should support the Rack Application' do
|
258
|
+
path = File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/rack_apps')
|
259
|
+
require path
|
260
|
+
Padrino.mount('rack_app', :app_class => 'RackApp', :app_file => path).to('/rack_app')
|
261
|
+
Padrino.mount('rack_app2', :app_class => 'RackApp2', :app_file => path).to('/rack_app2')
|
262
|
+
Padrino.mount('sinatra_app', :app_class => 'SinatraApp', :app_file => path).to('/sinatra_app')
|
263
|
+
app = Padrino.application
|
264
|
+
res = Rack::MockRequest.new(app).get("/rack_app")
|
265
|
+
assert_equal "hello rack app", res.body
|
266
|
+
res = Rack::MockRequest.new(app).get("/rack_app2")
|
267
|
+
assert_equal "hello rack app2", res.body
|
268
|
+
res = Rack::MockRequest.new(app).get("/sinatra_app")
|
269
|
+
assert_equal "hello sinatra app", res.body
|
270
|
+
res = Rack::MockRequest.new(app).get("/sinatra_app/static.html")
|
271
|
+
assert_equal "hello static file\n", res.body
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'should support the Rack Application inside padrino project' do
|
275
|
+
path = File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/demo_project/app')
|
276
|
+
api_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/demo_project/api/app')
|
277
|
+
require path
|
278
|
+
require api_path
|
279
|
+
Padrino.mount('api_app', :app_class => 'DemoProject::API', :app_file => api_path).to('/api')
|
280
|
+
Padrino.mount('main_app', :app_class => 'DemoProject::App').to('/')
|
281
|
+
app = Padrino.application
|
282
|
+
res = Rack::MockRequest.new(app).get("/")
|
283
|
+
assert_equal "padrino app", res.body
|
284
|
+
res = Rack::MockRequest.new(app).get("/api/hey")
|
285
|
+
assert_equal "api app", res.body
|
286
|
+
assert defined?(DemoProject::APILib)
|
287
|
+
end
|
256
288
|
end
|
257
289
|
end
|
@@ -156,4 +156,28 @@ describe "Padrino::ParamsProtection" do
|
|
156
156
|
post '/family?names[]=Jack&names[]=Kim&names[]=Teri'
|
157
157
|
assert_equal({"names" => %w[Jack Kim Teri]}, result)
|
158
158
|
end
|
159
|
+
|
160
|
+
it 'should tolerate weird inflections' do
|
161
|
+
result = nil
|
162
|
+
mock_app do
|
163
|
+
post :i, :params => [ :gotta => [ :what ] ] do
|
164
|
+
result = params
|
165
|
+
''
|
166
|
+
end
|
167
|
+
end
|
168
|
+
post '/i?gotta[what]=go&gotta[who]=self'
|
169
|
+
assert_equal({"gotta" => {"what" => "go"}}, result)
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should drop the key if the data type does not match route configuration' do
|
173
|
+
result = nil
|
174
|
+
mock_app do
|
175
|
+
post :i, :params => [ :gotta => [ :what ] ] do
|
176
|
+
result = params
|
177
|
+
''
|
178
|
+
end
|
179
|
+
end
|
180
|
+
post '/i?gotta=go'
|
181
|
+
assert_equal({}, result)
|
182
|
+
end
|
159
183
|
end
|
@@ -43,8 +43,8 @@ describe "ComplexReloader" do
|
|
43
43
|
|
44
44
|
new_phrase = "The magick number is: #{rand(2**255)}!"
|
45
45
|
buffer = File.read(Complex1Demo.app_file)
|
46
|
-
new_buffer = buffer.
|
47
|
-
new_buffer.
|
46
|
+
new_buffer = buffer.sub(/The magick number is: \d+!/, new_phrase)
|
47
|
+
new_buffer.sub!(/get\(:destroy\)/, 'get(:destroy, :with => :id)')
|
48
48
|
begin
|
49
49
|
File.open(Complex1Demo.app_file, "w") { |f| f.write(new_buffer) }
|
50
50
|
Time.stub(:now, Time.now + 2) { get "/complex_2_demo" }
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/reloadable_apps/main/app')
|
3
|
+
|
4
|
+
describe "ExternalReloader" do
|
5
|
+
describe "for external app" do
|
6
|
+
before do
|
7
|
+
Padrino.clear!
|
8
|
+
Padrino.mount("ReloadableApp::External").to("/reloadable/external")
|
9
|
+
Padrino.mount("ReloadableApp::Main").to("/reloadable")
|
10
|
+
Padrino.load!
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should avoid reloading the file if its path is not started with Padrino.root" do
|
14
|
+
@app = Padrino.application
|
15
|
+
Padrino.stub(:root, File.expand_path(File.dirname(__FILE__) + '/fixtures/reloadable_apps/main')) do
|
16
|
+
get "/reloadable/external/base"
|
17
|
+
end
|
18
|
+
assert_equal "Hello External App", body
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -61,7 +61,7 @@ describe "SimpleReloader" do
|
|
61
61
|
assert ok?
|
62
62
|
new_phrase = "The magick number is: #{rand(2**255)}!"
|
63
63
|
buffer = File.read(SimpleDemo.app_file)
|
64
|
-
new_buffer = buffer.
|
64
|
+
new_buffer = buffer.sub(/The magick number is: \d+!/, new_phrase)
|
65
65
|
begin
|
66
66
|
File.open(SimpleDemo.app_file, "w") { |f| f.write(new_buffer) }
|
67
67
|
Time.stub(:now, Time.now + 2) { get "/" }
|
@@ -79,7 +79,7 @@ describe "SimpleReloader" do
|
|
79
79
|
get "/rand"
|
80
80
|
assert ok?
|
81
81
|
last_body = body
|
82
|
-
assert_equal
|
82
|
+
assert_equal 1, @app.filters[:before].size
|
83
83
|
assert_equal 1, @app.errors.size
|
84
84
|
assert_equal 2, @app.filters[:after].size # app + content-type + padrino-flash
|
85
85
|
assert_equal 0, @app.middleware.size
|
@@ -89,7 +89,7 @@ describe "SimpleReloader" do
|
|
89
89
|
@app.reload!
|
90
90
|
get "/rand"
|
91
91
|
refute_equal last_body, body
|
92
|
-
assert_equal
|
92
|
+
assert_equal 1, @app.filters[:before].size
|
93
93
|
assert_equal 1, @app.errors.size
|
94
94
|
assert_equal 2, @app.filters[:after].size
|
95
95
|
assert_equal 0, @app.middleware.size
|
@@ -46,16 +46,6 @@ describe "SystemReloader" do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
it 'should tamper with LOAD_PATH' do
|
50
|
-
skip
|
51
|
-
SystemDemo.load_paths.each do |lib_dir|
|
52
|
-
assert_includes $LOAD_PATH, lib_dir
|
53
|
-
end
|
54
|
-
Padrino.send(:default_load_paths).each do |lib_dir|
|
55
|
-
assert_includes $LOAD_PATH, lib_dir
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
49
|
it 'should not fail horribly on reload event with non-padrino apps' do
|
60
50
|
Padrino.mount("kiq").to("/")
|
61
51
|
Padrino.reload!
|
data/test/test_routing.rb
CHANGED
@@ -30,6 +30,22 @@ describe "Routing" do
|
|
30
30
|
assert_equal headers['Cache-Control'], 'public, must-revalidate, max-age=300'
|
31
31
|
end # static max_age
|
32
32
|
|
33
|
+
it 'should render static files with custom status via options' do
|
34
|
+
mock_app do
|
35
|
+
set :static, true
|
36
|
+
set :public_folder, File.dirname(__FILE__)
|
37
|
+
|
38
|
+
post '/*' do
|
39
|
+
static!(:status => params[:status])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
post "/#{File.basename(__FILE__)}?status=422"
|
44
|
+
assert_equal response.status, 422
|
45
|
+
assert_equal File.size(__FILE__).to_s, response['Content-Length']
|
46
|
+
assert response.headers.include?('Last-Modified')
|
47
|
+
end
|
48
|
+
|
33
49
|
it 'should ignore trailing delimiters for basic route' do
|
34
50
|
mock_app do
|
35
51
|
get("/foo"){ "okey" }
|
@@ -1824,8 +1840,6 @@ describe "Routing" do
|
|
1824
1840
|
end
|
1825
1841
|
|
1826
1842
|
it 'should reset provides for routes that did not use it' do
|
1827
|
-
skip
|
1828
|
-
#FIXME
|
1829
1843
|
mock_app do
|
1830
1844
|
get('/foo', :provides => :js){}
|
1831
1845
|
get('/bar'){}
|
@@ -2124,4 +2138,30 @@ describe "Routing" do
|
|
2124
2138
|
get '/users//'
|
2125
2139
|
assert_equal 404, status
|
2126
2140
|
end
|
2141
|
+
|
2142
|
+
it "should support splat params" do
|
2143
|
+
# This test will be fixed with the new router
|
2144
|
+
skip
|
2145
|
+
mock_app do
|
2146
|
+
get "/say/*/to/*" do
|
2147
|
+
params[:splat].inspect
|
2148
|
+
end
|
2149
|
+
end
|
2150
|
+
get "/say/hello/to/world"
|
2151
|
+
assert_equal ["hello", "world"], body
|
2152
|
+
end
|
2153
|
+
|
2154
|
+
it "should match correctly paths even if the free regex route exists" do
|
2155
|
+
mock_app do
|
2156
|
+
get %r{/b/(?<aa>\w+)/(?<bb>\w+)} do
|
2157
|
+
"free regex"
|
2158
|
+
end
|
2159
|
+
|
2160
|
+
put '/b/:b/:c', :csrf_protection => false do
|
2161
|
+
params.inspect
|
2162
|
+
end
|
2163
|
+
end
|
2164
|
+
put "/b/x/y"
|
2165
|
+
assert_equal '{"b"=>"x", "c"=>"y"}', body
|
2166
|
+
end
|
2127
2167
|
end
|
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.12.
|
4
|
+
version: 0.12.4
|
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: 2014-
|
14
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: padrino-support
|
@@ -19,14 +19,14 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - '='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.12.
|
22
|
+
version: 0.12.4
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.12.
|
29
|
+
version: 0.12.4
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: sinatra
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,6 +153,9 @@ files:
|
|
153
153
|
- test/fixtures/apps/complex.rb
|
154
154
|
- test/fixtures/apps/demo_app.rb
|
155
155
|
- test/fixtures/apps/demo_demo.rb
|
156
|
+
- test/fixtures/apps/demo_project/api/app.rb
|
157
|
+
- test/fixtures/apps/demo_project/api/lib/api_lib.rb
|
158
|
+
- test/fixtures/apps/demo_project/app.rb
|
156
159
|
- test/fixtures/apps/helpers/class_methods_helpers.rb
|
157
160
|
- test/fixtures/apps/helpers/instance_methods_helpers.rb
|
158
161
|
- test/fixtures/apps/helpers/support.rb
|
@@ -162,7 +165,9 @@ files:
|
|
162
165
|
- test/fixtures/apps/lib/myklass/mysubklass.rb
|
163
166
|
- test/fixtures/apps/models/child.rb
|
164
167
|
- test/fixtures/apps/models/parent.rb
|
168
|
+
- test/fixtures/apps/rack_apps.rb
|
165
169
|
- test/fixtures/apps/simple.rb
|
170
|
+
- test/fixtures/apps/static.html
|
166
171
|
- test/fixtures/apps/static.rb
|
167
172
|
- test/fixtures/apps/system.rb
|
168
173
|
- test/fixtures/apps/system_class_methods_demo.rb
|
@@ -174,6 +179,9 @@ files:
|
|
174
179
|
- test/fixtures/dependencies/circular/f.rb
|
175
180
|
- test/fixtures/dependencies/circular/g.rb
|
176
181
|
- test/fixtures/dependencies/d.rb
|
182
|
+
- test/fixtures/reloadable_apps/external/app/app.rb
|
183
|
+
- test/fixtures/reloadable_apps/external/app/controllers/base.rb
|
184
|
+
- test/fixtures/reloadable_apps/main/app.rb
|
177
185
|
- test/helper.rb
|
178
186
|
- test/test_application.rb
|
179
187
|
- test/test_core.rb
|
@@ -186,6 +194,7 @@ files:
|
|
186
194
|
- test/test_mounter.rb
|
187
195
|
- test/test_params_protection.rb
|
188
196
|
- test/test_reloader_complex.rb
|
197
|
+
- test/test_reloader_external.rb
|
189
198
|
- test/test_reloader_simple.rb
|
190
199
|
- test/test_reloader_system.rb
|
191
200
|
- test/test_restful_routing.rb
|
@@ -225,6 +234,9 @@ test_files:
|
|
225
234
|
- test/fixtures/apps/complex.rb
|
226
235
|
- test/fixtures/apps/demo_app.rb
|
227
236
|
- test/fixtures/apps/demo_demo.rb
|
237
|
+
- test/fixtures/apps/demo_project/api/app.rb
|
238
|
+
- test/fixtures/apps/demo_project/api/lib/api_lib.rb
|
239
|
+
- test/fixtures/apps/demo_project/app.rb
|
228
240
|
- test/fixtures/apps/helpers/class_methods_helpers.rb
|
229
241
|
- test/fixtures/apps/helpers/instance_methods_helpers.rb
|
230
242
|
- test/fixtures/apps/helpers/support.rb
|
@@ -234,7 +246,9 @@ test_files:
|
|
234
246
|
- test/fixtures/apps/lib/myklass/mysubklass.rb
|
235
247
|
- test/fixtures/apps/models/child.rb
|
236
248
|
- test/fixtures/apps/models/parent.rb
|
249
|
+
- test/fixtures/apps/rack_apps.rb
|
237
250
|
- test/fixtures/apps/simple.rb
|
251
|
+
- test/fixtures/apps/static.html
|
238
252
|
- test/fixtures/apps/static.rb
|
239
253
|
- test/fixtures/apps/system.rb
|
240
254
|
- test/fixtures/apps/system_class_methods_demo.rb
|
@@ -246,6 +260,9 @@ test_files:
|
|
246
260
|
- test/fixtures/dependencies/circular/f.rb
|
247
261
|
- test/fixtures/dependencies/circular/g.rb
|
248
262
|
- test/fixtures/dependencies/d.rb
|
263
|
+
- test/fixtures/reloadable_apps/external/app/app.rb
|
264
|
+
- test/fixtures/reloadable_apps/external/app/controllers/base.rb
|
265
|
+
- test/fixtures/reloadable_apps/main/app.rb
|
249
266
|
- test/helper.rb
|
250
267
|
- test/test_application.rb
|
251
268
|
- test/test_core.rb
|
@@ -258,6 +275,7 @@ test_files:
|
|
258
275
|
- test/test_mounter.rb
|
259
276
|
- test/test_params_protection.rb
|
260
277
|
- test/test_reloader_complex.rb
|
278
|
+
- test/test_reloader_external.rb
|
261
279
|
- test/test_reloader_simple.rb
|
262
280
|
- test/test_reloader_system.rb
|
263
281
|
- test/test_restful_routing.rb
|