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.
- checksums.yaml +4 -4
- data/lib/padrino-core/application/authenticity_token.rb +25 -0
- data/lib/padrino-core/application/rendering/extensions/erubis.rb +11 -7
- data/lib/padrino-core/application/rendering/extensions/haml.rb +3 -2
- data/lib/padrino-core/application/rendering/extensions/slim.rb +10 -3
- data/lib/padrino-core/application/rendering.rb +13 -5
- data/lib/padrino-core/application/routing.rb +62 -19
- data/lib/padrino-core/application.rb +136 -50
- data/lib/padrino-core/cli/base.rb +32 -1
- data/lib/padrino-core/loader.rb +68 -68
- data/lib/padrino-core/logger.rb +6 -6
- data/lib/padrino-core/mounter.rb +9 -4
- data/lib/padrino-core/reloader/rack.rb +26 -0
- data/lib/padrino-core/reloader/storage.rb +55 -0
- data/lib/padrino-core/reloader.rb +192 -287
- data/lib/padrino-core/router.rb +11 -12
- data/lib/padrino-core/server.rb +5 -0
- data/lib/padrino-core/support_lite.rb +31 -32
- data/lib/padrino-core/version.rb +1 -1
- data/lib/padrino-core.rb +22 -30
- data/padrino-core.gemspec +2 -1
- data/test/fixtures/apps/helpers/system_helpers.rb +8 -0
- data/test/fixtures/apps/kiq.rb +3 -0
- data/test/fixtures/apps/lib/myklass/mysubklass.rb +4 -0
- data/test/fixtures/apps/lib/myklass.rb +2 -0
- data/test/fixtures/apps/models/child.rb +2 -0
- data/test/fixtures/apps/models/parent.rb +5 -0
- data/test/fixtures/apps/render.rb +13 -0
- data/test/fixtures/apps/system.rb +13 -0
- data/test/fixtures/apps/views/blog/post.erb +1 -0
- data/test/helper.rb +1 -1
- data/test/mini_shoulda.rb +4 -4
- data/test/test_application.rb +5 -13
- data/test/test_core.rb +2 -6
- data/test/test_csrf_protection.rb +67 -1
- data/test/test_dependencies.rb +14 -1
- data/test/test_mounter.rb +50 -6
- data/test/test_reloader_complex.rb +2 -2
- data/test/test_reloader_simple.rb +1 -1
- data/test/test_reloader_system.rb +52 -0
- data/test/test_rendering.rb +54 -0
- data/test/test_router.rb +121 -2
- data/test/test_routing.rb +84 -15
- metadata +29 -11
data/lib/padrino-core.rb
CHANGED
@@ -14,7 +14,6 @@ require 'padrino-core/server'
|
|
14
14
|
require 'padrino-core/tasks'
|
15
15
|
require 'padrino-core/module'
|
16
16
|
|
17
|
-
|
18
17
|
PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless defined?(PADRINO_ENV)
|
19
18
|
PADRINO_ROOT = ENV["PADRINO_ROOT"] ||= File.dirname(Padrino.first_caller) unless defined?(PADRINO_ROOT)
|
20
19
|
|
@@ -22,6 +21,8 @@ module Padrino
|
|
22
21
|
class ApplicationLoadError < RuntimeError # @private
|
23
22
|
end
|
24
23
|
|
24
|
+
extend Loader
|
25
|
+
|
25
26
|
class << self
|
26
27
|
##
|
27
28
|
# Helper method for file references.
|
@@ -61,18 +62,10 @@ module Padrino
|
|
61
62
|
# No applications were mounted.
|
62
63
|
#
|
63
64
|
def application
|
64
|
-
raise ApplicationLoadError, "At least one app must be mounted!" unless Padrino.mounted_apps
|
65
|
+
raise ApplicationLoadError, "At least one app must be mounted!" unless Padrino.mounted_apps.present?
|
65
66
|
router = Padrino::Router.new
|
66
67
|
Padrino.mounted_apps.each { |app| app.map_onto(router) }
|
67
|
-
|
68
|
-
if middleware.present?
|
69
|
-
builder = Rack::Builder.new
|
70
|
-
middleware.each { |c,a,b| builder.use(c, *a, &b) }
|
71
|
-
builder.run(router)
|
72
|
-
builder.to_app
|
73
|
-
else
|
74
|
-
router
|
75
|
-
end
|
68
|
+
middleware.present? ? add_middleware(router) : router
|
76
69
|
end
|
77
70
|
|
78
71
|
##
|
@@ -90,21 +83,14 @@ module Padrino
|
|
90
83
|
#
|
91
84
|
def configure_apps(&block)
|
92
85
|
return unless block_given?
|
93
|
-
|
94
|
-
@@_global_configurations << block
|
95
|
-
@_global_configuration = lambda do |app|
|
96
|
-
@@_global_configurations.each do |configuration|
|
97
|
-
app.class_eval(&configuration)
|
98
|
-
end
|
99
|
-
end
|
86
|
+
global_configurations << block
|
100
87
|
end
|
101
88
|
|
102
89
|
##
|
103
|
-
#
|
104
|
-
# {configure_apps} block.
|
90
|
+
# Stores global configuration blocks.
|
105
91
|
#
|
106
|
-
def
|
107
|
-
@
|
92
|
+
def global_configurations
|
93
|
+
@_global_configurations ||= []
|
108
94
|
end
|
109
95
|
|
110
96
|
##
|
@@ -119,15 +105,21 @@ module Padrino
|
|
119
105
|
# @return [NilClass]
|
120
106
|
#
|
121
107
|
def set_encoding
|
122
|
-
|
123
|
-
|
124
|
-
else
|
125
|
-
Encoding.default_external = Encoding::UTF_8
|
126
|
-
Encoding.default_internal = Encoding::UTF_8
|
127
|
-
end
|
108
|
+
Encoding.default_external = Encoding::UTF_8
|
109
|
+
Encoding.default_internal = Encoding::UTF_8
|
128
110
|
nil
|
129
111
|
end
|
130
112
|
|
113
|
+
##
|
114
|
+
# Creates Rack stack with the router added to the middleware chain.
|
115
|
+
#
|
116
|
+
def add_middleware(router)
|
117
|
+
builder = Rack::Builder.new
|
118
|
+
middleware.each{ |mw,args,block| builder.use(mw, *args, &block) }
|
119
|
+
builder.run(router)
|
120
|
+
builder.to_app
|
121
|
+
end
|
122
|
+
|
131
123
|
##
|
132
124
|
# A Rack::Builder object that allows to add middlewares in front of all
|
133
125
|
# Padrino applications.
|
@@ -161,8 +153,8 @@ module Padrino
|
|
161
153
|
# @yield []
|
162
154
|
# The given block will be passed to the initialized middleware.
|
163
155
|
#
|
164
|
-
def use(
|
165
|
-
middleware << [
|
156
|
+
def use(mw, *args, &block)
|
157
|
+
middleware << [mw, args, block]
|
166
158
|
end
|
167
159
|
|
168
160
|
##
|
data/padrino-core.gemspec
CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.required_rubygems_version = ">= 1.3.6"
|
15
15
|
s.version = Padrino.version
|
16
16
|
s.date = Time.now.strftime("%Y-%m-%d")
|
17
|
+
s.license = "MIT"
|
17
18
|
|
18
19
|
s.extra_rdoc_files = Dir["*.rdoc"]
|
19
20
|
s.files = `git ls-files`.split("\n")
|
@@ -38,6 +39,6 @@ Gem::Specification.new do |s|
|
|
38
39
|
end
|
39
40
|
s.add_dependency("http_router", "~> 0.11.0")
|
40
41
|
s.add_dependency("thor", "~> 0.17.0")
|
41
|
-
s.add_dependency("activesupport", ">= 3.1"
|
42
|
+
s.add_dependency("activesupport", ">= 3.1")
|
42
43
|
s.add_dependency("rack-protection", ">= 1.5.0")
|
43
44
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
okay
|
data/test/helper.rb
CHANGED
@@ -56,7 +56,7 @@ class MiniTest::Spec
|
|
56
56
|
path = "/views/#{name}"
|
57
57
|
path += ".#{options.delete(:locale)}" if options[:locale].present?
|
58
58
|
path += ".#{options[:format]}" if options[:format].present?
|
59
|
-
path += ".erb" unless options[:format].to_s =~ /haml|rss|atom/
|
59
|
+
path += ".erb" unless options[:format].to_s =~ /erb|slim|haml|rss|atom/
|
60
60
|
path += ".builder" if options[:format].to_s =~ /rss|atom/
|
61
61
|
file = File.dirname(__FILE__) + path
|
62
62
|
File.open(file, 'w') { |io| io.write content }
|
data/test/mini_shoulda.rb
CHANGED
@@ -29,10 +29,10 @@ class ColoredIO
|
|
29
29
|
|
30
30
|
def print(o)
|
31
31
|
case o
|
32
|
-
when "." then @io.send(:print, o.green)
|
33
|
-
when "E" then @io.send(:print, o.red)
|
34
|
-
when "F" then @io.send(:print, o.yellow)
|
35
|
-
when "S" then @io.send(:print, o.magenta)
|
32
|
+
when "." then @io.send(:print, o.colorize(:green))
|
33
|
+
when "E" then @io.send(:print, o.colorize(:red))
|
34
|
+
when "F" then @io.send(:print, o.colorize(:yellow))
|
35
|
+
when "S" then @io.send(:print, o.colorize(:magenta))
|
36
36
|
else @io.send(:print, o)
|
37
37
|
end
|
38
38
|
end
|
data/test/test_application.rb
CHANGED
@@ -25,19 +25,6 @@ describe "Application" do
|
|
25
25
|
assert !Padrino.configure_apps
|
26
26
|
end
|
27
27
|
|
28
|
-
should 'check haml options on production' do
|
29
|
-
assert defined?(Haml), 'Haml not defined'
|
30
|
-
assert_equal :test, PadrinoPristine.environment
|
31
|
-
assert !PadrinoPristine.haml[:ugly]
|
32
|
-
Padrino.stub :env, :production do
|
33
|
-
PadrinoPristine.send :default_configuration!
|
34
|
-
assert_equal :production, Padrino.env
|
35
|
-
assert_equal :production, PadrinoPristine.environment
|
36
|
-
assert PadrinoPristine.haml[:ugly]
|
37
|
-
PadrinoPristine.environment = :test
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
28
|
should 'check padrino specific options' do
|
42
29
|
assert !PadrinoPristine.instance_variable_get(:@_configured)
|
43
30
|
PadrinoPristine.send(:setup_application!)
|
@@ -97,6 +84,11 @@ describe "Application" do
|
|
97
84
|
assert_equal "Foo in nil", body
|
98
85
|
end
|
99
86
|
|
87
|
+
should "resolve views and layouts paths" do
|
88
|
+
assert_equal Padrino.root('views')+'/users/index', PadrinoPristine.view_path('users/index')
|
89
|
+
assert_equal Padrino.root('views')+'/layouts/app', PadrinoPristine.layout_path(:app)
|
90
|
+
end
|
91
|
+
|
100
92
|
context "errors" do
|
101
93
|
should "haven't mapped errors on development" do
|
102
94
|
mock_app { get('/'){ 'HI' } }
|
data/test/test_core.rb
CHANGED
@@ -27,12 +27,8 @@ describe "Core" do
|
|
27
27
|
|
28
28
|
should 'set correct utf-8 encoding' do
|
29
29
|
Padrino.set_encoding
|
30
|
-
|
31
|
-
|
32
|
-
else
|
33
|
-
assert_equal Encoding.default_external, Encoding::UTF_8
|
34
|
-
assert_equal Encoding.default_internal, Encoding::UTF_8
|
35
|
-
end
|
30
|
+
assert_equal Encoding.default_external, Encoding::UTF_8
|
31
|
+
assert_equal Encoding.default_internal, Encoding::UTF_8
|
36
32
|
end
|
37
33
|
|
38
34
|
should 'have load paths' do
|
@@ -76,5 +76,71 @@ describe "Application" do
|
|
76
76
|
assert_equal 403, status
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
context "with :except option that is using Proc" do
|
81
|
+
before do
|
82
|
+
mock_app do
|
83
|
+
enable :sessions
|
84
|
+
set :protect_from_csrf, :except => proc{|env| ["/", "/foo"].any?{|path| path == env['PATH_INFO'] }}
|
85
|
+
post("/") { "Hello" }
|
86
|
+
post("/foo") { "Hello, foo" }
|
87
|
+
post("/bar") { "Hello, bar" }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
should "allow ignoring CSRF protection on specific routes" do
|
92
|
+
post "/"
|
93
|
+
assert_equal 200, status
|
94
|
+
post "/foo"
|
95
|
+
assert_equal 200, status
|
96
|
+
post "/bar"
|
97
|
+
assert_equal 403, status
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "with :except option that is using String and Regexp" do
|
102
|
+
before do
|
103
|
+
mock_app do
|
104
|
+
enable :sessions
|
105
|
+
set :protect_from_csrf, :except => ["/a", %r{^/a.c$}]
|
106
|
+
post("/a") { "a" }
|
107
|
+
post("/abc") { "abc" }
|
108
|
+
post("/foo") { "foo" }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
should "allow ignoring CSRF protection on specific routes" do
|
113
|
+
post "/a"
|
114
|
+
assert_equal 200, status
|
115
|
+
post "/abc"
|
116
|
+
assert_equal 200, status
|
117
|
+
post "/foo"
|
118
|
+
assert_equal 403, status
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "with middleware" do
|
123
|
+
before do
|
124
|
+
class Middleware < Sinatra::Base
|
125
|
+
post("/middleware") { "Hello, middleware" }
|
126
|
+
post("/dummy") { "Hello, dummy" }
|
127
|
+
end
|
128
|
+
mock_app do
|
129
|
+
enable :sessions
|
130
|
+
set :protect_from_csrf, :except => proc{|env| ["/", "/middleware"].any?{|path| path == env['PATH_INFO'] }}
|
131
|
+
use Middleware
|
132
|
+
post("/") { "Hello" }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
should "allow ignoring CSRF protection on specific routes of middleware" do
|
137
|
+
post "/"
|
138
|
+
assert_equal 200, status
|
139
|
+
post "/middleware"
|
140
|
+
assert_equal 200, status
|
141
|
+
post "/dummy"
|
142
|
+
assert_equal 403, status
|
143
|
+
end
|
144
|
+
end
|
79
145
|
end
|
80
|
-
end
|
146
|
+
end
|
data/test/test_dependencies.rb
CHANGED
@@ -2,6 +2,17 @@ require File.expand_path(File.dirname(__FILE__) + '/helper')
|
|
2
2
|
|
3
3
|
describe "Dependencies" do
|
4
4
|
context 'when we require a dependency that have another dependency' do
|
5
|
+
setup do
|
6
|
+
@log_level = Padrino::Logger::Config[:test]
|
7
|
+
@io = StringIO.new
|
8
|
+
Padrino::Logger::Config[:test] = { :log_level => :error, :stream => @io }
|
9
|
+
Padrino::Logger.setup!
|
10
|
+
end
|
11
|
+
|
12
|
+
teardown do
|
13
|
+
Padrino::Logger::Config[:test] = @log_level
|
14
|
+
Padrino::Logger.setup!
|
15
|
+
end
|
5
16
|
|
6
17
|
should 'raise an error without reloading it twice' do
|
7
18
|
capture_io do
|
@@ -15,6 +26,7 @@ describe "Dependencies" do
|
|
15
26
|
end
|
16
27
|
end
|
17
28
|
assert_equal 1, D
|
29
|
+
assert_match /RuntimeError: SomeThing/, @io.string
|
18
30
|
end
|
19
31
|
|
20
32
|
should 'resolve dependency problems' do
|
@@ -27,6 +39,7 @@ describe "Dependencies" do
|
|
27
39
|
end
|
28
40
|
assert_equal ["B", "C"], A_result
|
29
41
|
assert_equal "C", B_result
|
42
|
+
assert_equal "", @io.string
|
30
43
|
end
|
31
44
|
|
32
45
|
should 'remove partially loaded constants' do
|
@@ -37,8 +50,8 @@ describe "Dependencies" do
|
|
37
50
|
Padrino.root("fixtures/dependencies/circular/g.rb")
|
38
51
|
)
|
39
52
|
end
|
40
|
-
|
41
53
|
assert_equal ["name"], F.fields
|
54
|
+
assert_equal "", @io.string
|
42
55
|
end
|
43
56
|
end
|
44
57
|
end
|
data/test/test_mounter.rb
CHANGED
@@ -24,7 +24,14 @@ describe "Mounter" do
|
|
24
24
|
assert_equal "TestApp", mounter.app_class
|
25
25
|
assert_equal "/path/to/test.rb", mounter.app_file
|
26
26
|
assert_equal "/test_app", mounter.uri_root
|
27
|
-
assert_equal
|
27
|
+
assert_equal Padrino.root, mounter.app_root
|
28
|
+
end
|
29
|
+
|
30
|
+
should 'use app.root if available' do
|
31
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/kiq')
|
32
|
+
mounter = Padrino::Mounter.new("kiq", :app_class => "Kiq")
|
33
|
+
mounter.to("/test_app")
|
34
|
+
assert_equal '/weird', mounter.app_root
|
28
35
|
end
|
29
36
|
|
30
37
|
should 'check locate_app_file with __FILE__' do
|
@@ -53,6 +60,17 @@ describe "Mounter" do
|
|
53
60
|
assert_equal ["some_namespace/an_app"], Padrino.mounted_apps.map(&:name)
|
54
61
|
end
|
55
62
|
|
63
|
+
should 'correctly set a name of a namespaced app' do
|
64
|
+
module ::SomeNamespace2
|
65
|
+
class AnApp < Padrino::Application
|
66
|
+
get(:index) { settings.app_name }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
Padrino.mount("SomeNamespace2::AnApp").to("/")
|
70
|
+
res = Rack::MockRequest.new(Padrino.application).get("/")
|
71
|
+
assert_equal "some_namespace2/an_app", res.body
|
72
|
+
end
|
73
|
+
|
56
74
|
should 'mount a primary app to root uri' do
|
57
75
|
mounter = Padrino.mount("test_app", :app_file => __FILE__).to("/")
|
58
76
|
assert_equal "test_app", mounter.name
|
@@ -130,30 +148,56 @@ describe "Mounter" do
|
|
130
148
|
put(:update) { "users update" }
|
131
149
|
delete(:destroy) { "users delete" }
|
132
150
|
end
|
151
|
+
controllers :foo_bar do
|
152
|
+
get(:index) { "foo bar index" }
|
153
|
+
get(:new) { "foo bar new" }
|
154
|
+
post(:create) { "foo bar create" }
|
155
|
+
put(:update) { "foo bar update" }
|
156
|
+
delete(:destroy) { "foo bar delete" }
|
157
|
+
end
|
133
158
|
end
|
134
159
|
|
135
160
|
Padrino.mount("one_app").to("/")
|
136
161
|
Padrino.mount("two_app").to("/two_app")
|
137
162
|
|
138
163
|
assert_equal 15, Padrino.mounted_apps[0].routes.size
|
139
|
-
assert_equal
|
164
|
+
assert_equal 14, Padrino.mounted_apps[1].routes.size
|
140
165
|
assert_equal 6, Padrino.mounted_apps[0].named_routes.size
|
141
|
-
assert_equal
|
166
|
+
assert_equal 10, Padrino.mounted_apps[1].named_routes.size
|
142
167
|
|
143
168
|
first_route = Padrino.mounted_apps[0].named_routes[3]
|
144
|
-
assert_equal "
|
169
|
+
assert_equal "posts show", first_route.identifier.to_s
|
145
170
|
assert_equal "(:posts, :show)", first_route.name
|
146
171
|
assert_equal "GET", first_route.verb
|
147
172
|
assert_equal "/posts/show/:id(.:format)", first_route.path
|
148
173
|
another_route = Padrino.mounted_apps[1].named_routes[2]
|
149
|
-
assert_equal "
|
174
|
+
assert_equal "users create", another_route.identifier.to_s
|
150
175
|
assert_equal "(:users, :create)", another_route.name
|
151
176
|
assert_equal "POST", another_route.verb
|
152
177
|
assert_equal "/two_app/users/create", another_route.path
|
153
178
|
regexp_route = Padrino.mounted_apps[0].named_routes[5]
|
154
|
-
assert_equal "
|
179
|
+
assert_equal "posts regexp", regexp_route.identifier.to_s
|
155
180
|
assert_equal "(:posts, :regexp)", regexp_route.name
|
156
181
|
assert_equal "/\\/foo|\\/baz/", regexp_route.path
|
182
|
+
foo_bar_route = Padrino.mounted_apps[1].named_routes[5]
|
183
|
+
assert_equal "(:foo_bar, :index)", foo_bar_route.name
|
184
|
+
end
|
185
|
+
|
186
|
+
should "configure cascade apps" do
|
187
|
+
class ::App1 < Padrino::Application
|
188
|
+
get(:index) { halt 404, 'index1' }
|
189
|
+
end
|
190
|
+
class ::App2 < Padrino::Application
|
191
|
+
get(:index) { halt 404, 'index2' }
|
192
|
+
end
|
193
|
+
class ::App3 < Padrino::Application
|
194
|
+
get(:index) { halt 404, 'index3' }
|
195
|
+
end
|
196
|
+
Padrino.mount('app1', :cascade => true).to('/foo')
|
197
|
+
Padrino.mount('app2').to('/foo')
|
198
|
+
Padrino.mount('app3').to('/foo')
|
199
|
+
res = Rack::MockRequest.new(Padrino.application).get("/foo")
|
200
|
+
assert_equal 'index2', res.body
|
157
201
|
end
|
158
202
|
|
159
203
|
should 'correctly instantiate a new padrino application' do
|
@@ -47,7 +47,7 @@ describe "ComplexReloader" do
|
|
47
47
|
new_buffer.gsub!(/get\(:destroy\)/, 'get(:destroy, :with => :id)')
|
48
48
|
begin
|
49
49
|
File.open(Complex1Demo.app_file, "w") { |f| f.write(new_buffer) }
|
50
|
-
sleep 1.
|
50
|
+
sleep 1.1 # We need at least a cooldown of 1 sec.
|
51
51
|
get "/complex_2_demo"
|
52
52
|
assert_equal new_phrase, body
|
53
53
|
|
@@ -65,7 +65,7 @@ describe "ComplexReloader" do
|
|
65
65
|
assert_equal 200, status
|
66
66
|
|
67
67
|
get "/complex_2_demo/var/destroy/variable"
|
68
|
-
assert_equal '{
|
68
|
+
assert_equal '{"id"=>"variable"}', body
|
69
69
|
ensure
|
70
70
|
# Now we need to prevent to commit a new changed file so we revert it
|
71
71
|
File.open(Complex1Demo.app_file, "w") { |f| f.write(buffer) }
|
@@ -61,7 +61,7 @@ describe "SimpleReloader" do
|
|
61
61
|
buffer = File.read(SimpleDemo.app_file)
|
62
62
|
new_buffer = buffer.gsub(/The magick number is: \d+!/, new_phrase)
|
63
63
|
File.open(SimpleDemo.app_file, "w") { |f| f.write(new_buffer) }
|
64
|
-
sleep
|
64
|
+
sleep 1.1 # We need at least a cooldown of 1 sec.
|
65
65
|
get "/"
|
66
66
|
assert_equal new_phrase, body
|
67
67
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/system')
|
3
|
+
|
4
|
+
describe "SystemReloader" do
|
5
|
+
context 'for wierd and difficult reload events' do
|
6
|
+
should 'reload system features if they were required only in helper' do
|
7
|
+
@app = SystemDemo
|
8
|
+
@app.reload!
|
9
|
+
get '/'
|
10
|
+
assert_equal 'Resolv', body
|
11
|
+
end
|
12
|
+
|
13
|
+
should 'reload children on parent change' do
|
14
|
+
@app = SystemDemo
|
15
|
+
assert_equal Child.new.family, 'Danes'
|
16
|
+
parent_file = File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/models/parent.rb')
|
17
|
+
new_class = <<-DOC
|
18
|
+
class Parent
|
19
|
+
def family
|
20
|
+
'Dancy'
|
21
|
+
end
|
22
|
+
def shmamily
|
23
|
+
'Shmancy'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
DOC
|
27
|
+
begin
|
28
|
+
backup = File.read(parent_file)
|
29
|
+
Padrino::Reloader.reload!
|
30
|
+
assert_equal 'Danes', Parent.new.family
|
31
|
+
assert_equal 'Danes', Child.new.family
|
32
|
+
File.open(parent_file, "w") { |f| f.write(new_class) }
|
33
|
+
Padrino::Reloader.reload!
|
34
|
+
assert_equal 'Dancy', Parent.new.family
|
35
|
+
assert_equal 'Shmancy', Parent.new.shmamily
|
36
|
+
assert_equal 'Dancy', Child.new.family
|
37
|
+
assert_equal 'Shmancy', Child.new.shmamily
|
38
|
+
ensure
|
39
|
+
File.open(parent_file, "w") { |f| f.write(backup) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
should 'tamper with LOAD_PATH' do
|
44
|
+
SystemDemo.load_paths.each do |lib_dir|
|
45
|
+
assert_includes $LOAD_PATH, lib_dir
|
46
|
+
end
|
47
|
+
Padrino.send(:load_paths_was).each do |lib_dir|
|
48
|
+
assert_includes $LOAD_PATH, lib_dir
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/test/test_rendering.rb
CHANGED
@@ -209,6 +209,43 @@ describe "Rendering" do
|
|
209
209
|
assert_equal "haml", body.chomp
|
210
210
|
end
|
211
211
|
|
212
|
+
should 'allow to render template with layout option that using other template engine.' do
|
213
|
+
create_layout :"layouts/foo", "application layout for <%= yield %>", :format => :erb
|
214
|
+
create_view :slim, "| slim", :format => :slim
|
215
|
+
create_view :haml, "haml", :format => :haml
|
216
|
+
create_view :erb, "erb", :format => :erb
|
217
|
+
mock_app do
|
218
|
+
get("/slim") { render("slim.slim", :layout => "foo.erb") }
|
219
|
+
get("/haml") { render("haml.haml", :layout => "foo.erb") }
|
220
|
+
get("/erb") { render("erb.erb", :layout => "foo.erb") }
|
221
|
+
end
|
222
|
+
get "/slim"
|
223
|
+
assert_equal "application layout for slim", body.chomp
|
224
|
+
get "/haml"
|
225
|
+
assert_equal "application layout for haml", body.chomp
|
226
|
+
get "/erb"
|
227
|
+
assert_equal "application layout for erb", body.chomp
|
228
|
+
end
|
229
|
+
|
230
|
+
should 'allow to use extension with layout method.' do
|
231
|
+
create_layout :"layouts/bar", "application layout for <%= yield %>", :format => :erb
|
232
|
+
create_view :slim, "| slim", :format => :slim
|
233
|
+
create_view :haml, "haml", :format => :haml
|
234
|
+
create_view :erb, "erb", :format => :erb
|
235
|
+
mock_app do
|
236
|
+
layout "bar.erb"
|
237
|
+
get("/slim") { render("slim.slim") }
|
238
|
+
get("/haml") { render("haml.haml") }
|
239
|
+
get("/erb") { render("erb.erb") }
|
240
|
+
end
|
241
|
+
get "/slim"
|
242
|
+
assert_equal "application layout for slim", body.chomp
|
243
|
+
get "/haml"
|
244
|
+
assert_equal "application layout for haml", body.chomp
|
245
|
+
get "/erb"
|
246
|
+
assert_equal "application layout for erb", body.chomp
|
247
|
+
end
|
248
|
+
|
212
249
|
context 'for application render functionality' do
|
213
250
|
|
214
251
|
should "work properly with logging and missing layout" do
|
@@ -385,11 +422,15 @@ describe "Rendering" do
|
|
385
422
|
mock_app do
|
386
423
|
get("/foo", :provides => [:html, :js]) { render :foo }
|
387
424
|
end
|
425
|
+
|
426
|
+
I18n.enforce_available_locales = false
|
388
427
|
I18n.locale = :none
|
389
428
|
get "/foo.js"
|
390
429
|
assert_equal "Im Js", body
|
391
430
|
get "/foo"
|
392
431
|
assert_equal "Im Erb", body
|
432
|
+
I18n.enforce_available_locales = true
|
433
|
+
|
393
434
|
I18n.locale = :en
|
394
435
|
get "/foo"
|
395
436
|
assert_equal "Im English Erb", body
|
@@ -405,6 +446,7 @@ describe "Rendering" do
|
|
405
446
|
I18n.locale = :en
|
406
447
|
get "/foo.pk"
|
407
448
|
assert_equal 404, status
|
449
|
+
|
408
450
|
end
|
409
451
|
|
410
452
|
should 'resolve template content_type and locale with layout' do
|
@@ -425,11 +467,15 @@ describe "Rendering" do
|
|
425
467
|
layout :foo
|
426
468
|
get("/bar", :provides => [:html, :js, :json]) { render :bar }
|
427
469
|
end
|
470
|
+
|
471
|
+
I18n.enforce_available_locales = false
|
428
472
|
I18n.locale = :none
|
429
473
|
get "/bar.js"
|
430
474
|
assert_equal "Hello Im Js in a Js layout", body
|
431
475
|
get "/bar"
|
432
476
|
assert_equal "Hello Im Erb in a Erb layout", body
|
477
|
+
I18n.enforce_available_locales = true
|
478
|
+
|
433
479
|
I18n.locale = :en
|
434
480
|
get "/bar"
|
435
481
|
assert_equal "Hello Im English Erb in a Erb-En layout", body
|
@@ -447,6 +493,14 @@ describe "Rendering" do
|
|
447
493
|
assert_equal "Im a json", body
|
448
494
|
get "/bar.pk"
|
449
495
|
assert_equal 404, status
|
496
|
+
|
497
|
+
end
|
498
|
+
|
499
|
+
should 'resolve template location relative to controller name' do
|
500
|
+
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/render')
|
501
|
+
@app = RenderDemo
|
502
|
+
get '/blog'
|
503
|
+
assert_equal 'okay', body
|
450
504
|
end
|
451
505
|
|
452
506
|
should 'renders erb with blocks' do
|