padrino-core 0.16.0.pre4 → 0.16.0
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/README.rdoc +8 -8
- data/Rakefile +1 -1
- data/bin/padrino +1 -1
- data/lib/padrino-core/application/application_setup.rb +28 -26
- data/lib/padrino-core/application/authenticity_token.rb +3 -2
- data/lib/padrino-core/application/flash.rb +4 -5
- data/lib/padrino-core/application/params_protection.rb +34 -37
- data/lib/padrino-core/application/routing.rb +165 -164
- data/lib/padrino-core/application/show_exceptions.rb +5 -7
- data/lib/padrino-core/application.rb +4 -4
- data/lib/padrino-core/caller.rb +6 -7
- data/lib/padrino-core/cli/adapter.rb +4 -4
- data/lib/padrino-core/cli/base.rb +31 -32
- data/lib/padrino-core/cli/binstub.rb +9 -8
- data/lib/padrino-core/cli/console.rb +1 -1
- data/lib/padrino-core/cli/launcher.rb +45 -42
- data/lib/padrino-core/cli/rake.rb +16 -14
- data/lib/padrino-core/cli/rake_tasks.rb +18 -20
- data/lib/padrino-core/command.rb +1 -1
- data/lib/padrino-core/ext/sinatra.rb +3 -2
- data/lib/padrino-core/filter.rb +3 -3
- data/lib/padrino-core/loader.rb +10 -12
- data/lib/padrino-core/logger.rb +85 -77
- data/lib/padrino-core/mounter/application_extension.rb +2 -2
- data/lib/padrino-core/mounter.rb +33 -34
- data/lib/padrino-core/path_router/compiler.rb +8 -8
- data/lib/padrino-core/path_router/matcher.rb +11 -11
- data/lib/padrino-core/path_router/route.rb +15 -15
- data/lib/padrino-core/path_router.rb +4 -3
- data/lib/padrino-core/reloader/rack.rb +1 -1
- data/lib/padrino-core/reloader/storage.rb +12 -11
- data/lib/padrino-core/reloader.rb +18 -19
- data/lib/padrino-core/router.rb +14 -14
- data/lib/padrino-core/server.rb +20 -24
- data/lib/padrino-core/tasks.rb +0 -1
- data/lib/padrino-core/version.rb +1 -1
- data/lib/padrino-core.rb +9 -10
- data/padrino-core.gemspec +18 -18
- data/test/fixtures/app_gem/app_gem.gemspec +8 -7
- data/test/fixtures/app_gem/lib/app_gem/version.rb +1 -1
- data/test/fixtures/apps/complex.rb +6 -6
- data/test/fixtures/apps/concerned/app.rb +1 -1
- data/test/fixtures/apps/custom_dependencies/custom_dependencies.rb +3 -3
- data/test/fixtures/apps/demo_app.rb +1 -1
- data/test/fixtures/apps/demo_demo.rb +1 -1
- data/test/fixtures/apps/demo_project/api/app.rb +1 -1
- data/test/fixtures/apps/demo_project/app.rb +1 -1
- data/test/fixtures/apps/helpers/class_methods_helpers.rb +1 -0
- data/test/fixtures/apps/helpers/instance_methods_helpers.rb +1 -0
- data/test/fixtures/apps/helpers/system_helpers.rb +0 -1
- data/test/fixtures/apps/lib/myklass/mysubklass.rb +2 -2
- data/test/fixtures/apps/mountable_apps/rack_apps.rb +7 -7
- data/test/fixtures/apps/precompiled_app.rb +6 -5
- data/test/fixtures/apps/simple.rb +5 -5
- data/test/fixtures/apps/static.rb +2 -2
- data/test/fixtures/apps/stealthy/app.rb +1 -1
- data/test/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb +1 -1
- data/test/fixtures/apps/system.rb +1 -1
- data/test/fixtures/apps/system_class_methods_demo.rb +1 -1
- data/test/fixtures/apps/system_instance_methods_demo.rb +1 -1
- data/test/fixtures/dependencies/a.rb +1 -1
- data/test/fixtures/dependencies/b.rb +1 -1
- data/test/fixtures/dependencies/c.rb +1 -1
- data/test/fixtures/dependencies/circular/e.rb +2 -1
- data/test/fixtures/dependencies/d.rb +1 -1
- data/test/fixtures/dependencies/linear/i.rb +1 -1
- data/test/fixtures/dependencies/nested/l.rb +2 -2
- data/test/fixtures/dependencies/nested/m.rb +1 -1
- data/test/fixtures/dependencies/nested/qqq.rb +2 -2
- data/test/fixtures/dependencies/nested/rrr.rb +1 -1
- data/test/fixtures/dependencies/nested/sss.rb +1 -1
- data/test/fixtures/reloadable_apps/external/app/app.rb +0 -1
- data/test/fixtures/reloadable_apps/external/app/controllers/base.rb +1 -2
- data/test/fixtures/reloadable_apps/main/app.rb +2 -2
- data/test/helper.rb +2 -2
- data/test/test_application.rb +59 -60
- data/test/test_configuration.rb +2 -2
- data/test/test_core.rb +13 -13
- data/test/test_csrf_protection.rb +67 -63
- data/test/test_dependencies.rb +33 -34
- data/test/test_filters.rb +46 -47
- data/test/test_flash.rb +14 -14
- data/test/test_locale.rb +2 -2
- data/test/test_logger.rb +64 -64
- data/test/test_mounter.rb +133 -123
- data/test/test_params_protection.rb +40 -40
- data/test/test_reloader_complex.rb +23 -23
- data/test/test_reloader_external.rb +10 -10
- data/test/test_reloader_simple.rb +26 -23
- data/test/test_reloader_storage.rb +9 -12
- data/test/test_reloader_system.rb +29 -29
- data/test/test_restful_routing.rb +19 -19
- data/test/test_router.rb +126 -145
- data/test/test_routing.rb +882 -894
- metadata +6 -6
data/test/test_mounter.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe 'Mounter' do
|
|
4
4
|
class ::TestApp < Padrino::Application; end
|
|
5
5
|
|
|
6
6
|
def setup
|
|
@@ -14,50 +14,50 @@ describe "Mounter" do
|
|
|
14
14
|
|
|
15
15
|
describe 'for mounter functionality' do
|
|
16
16
|
it 'should check methods' do
|
|
17
|
-
mounter = Padrino::Mounter.new(
|
|
18
|
-
mounter.to(
|
|
17
|
+
mounter = Padrino::Mounter.new('test_app', app_file: '/path/to/test.rb')
|
|
18
|
+
mounter.to('/test_app')
|
|
19
19
|
assert_kind_of Padrino::Mounter, mounter
|
|
20
20
|
assert_respond_to Padrino::Mounter, :new
|
|
21
21
|
assert_respond_to mounter, :to
|
|
22
22
|
assert_respond_to mounter, :map_onto
|
|
23
|
-
assert_equal
|
|
24
|
-
assert_equal
|
|
25
|
-
assert_equal
|
|
26
|
-
assert_equal
|
|
23
|
+
assert_equal 'test_app', mounter.name
|
|
24
|
+
assert_equal 'TestApp', mounter.app_class
|
|
25
|
+
assert_equal '/path/to/test.rb', mounter.app_file
|
|
26
|
+
assert_equal '/test_app', mounter.uri_root
|
|
27
27
|
assert_equal Padrino.root, mounter.app_root
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
it 'should use app.root if available' do
|
|
31
|
-
require File.expand_path(
|
|
32
|
-
mounter = Padrino::Mounter.new(
|
|
33
|
-
mounter.to(
|
|
31
|
+
require File.expand_path("#{__dir__}/fixtures/apps/kiq")
|
|
32
|
+
mounter = Padrino::Mounter.new('kiq', app_class: 'Kiq')
|
|
33
|
+
mounter.to('/test_app')
|
|
34
34
|
assert_equal '/weird', mounter.app_root
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it 'should check locate_app_file with __FILE__' do
|
|
38
|
-
mounter = Padrino::Mounter.new(
|
|
39
|
-
mounter.to(
|
|
40
|
-
assert_equal
|
|
41
|
-
assert_equal
|
|
38
|
+
mounter = Padrino::Mounter.new('test_app', app_file: __FILE__)
|
|
39
|
+
mounter.to('/test_app')
|
|
40
|
+
assert_equal 'test_app', mounter.name
|
|
41
|
+
assert_equal 'TestApp', mounter.app_class
|
|
42
42
|
assert_equal __FILE__, mounter.app_file
|
|
43
|
-
assert_equal
|
|
43
|
+
assert_equal '/test_app', mounter.uri_root
|
|
44
44
|
assert_equal File.dirname(mounter.app_file), mounter.app_root
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it 'should mount an app' do
|
|
48
48
|
class ::AnApp < Padrino::Application; end
|
|
49
|
-
Padrino.mount(
|
|
49
|
+
Padrino.mount('an_app').to('/')
|
|
50
50
|
assert_equal AnApp, Padrino.mounted_apps.first.app_obj
|
|
51
|
-
assert_equal [
|
|
51
|
+
assert_equal ['an_app'], Padrino.mounted_apps.map(&:name)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
it 'should correctly mount an app in a namespace' do
|
|
55
55
|
module ::SomeNamespace
|
|
56
56
|
class AnApp < Padrino::Application; end
|
|
57
57
|
end
|
|
58
|
-
Padrino.mount(
|
|
58
|
+
Padrino.mount('some_namespace/an_app').to('/')
|
|
59
59
|
assert_equal SomeNamespace::AnApp, Padrino.mounted_apps.first.app_obj
|
|
60
|
-
assert_equal [
|
|
60
|
+
assert_equal ['some_namespace/an_app'], Padrino.mounted_apps.map(&:name)
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it 'should correctly set a name of a namespaced app' do
|
|
@@ -66,28 +66,28 @@ describe "Mounter" do
|
|
|
66
66
|
get(:index) { settings.app_name }
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
|
-
Padrino.mount(
|
|
70
|
-
res = Rack::MockRequest.new(Padrino.application).get(
|
|
71
|
-
assert_equal
|
|
69
|
+
Padrino.mount('SomeNamespace2::AnApp').to('/')
|
|
70
|
+
res = Rack::MockRequest.new(Padrino.application).get('/')
|
|
71
|
+
assert_equal 'some_namespace2/an_app', res.body
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
it 'should mount a primary app to root uri' do
|
|
75
|
-
mounter = Padrino.mount(
|
|
76
|
-
assert_equal
|
|
77
|
-
assert_equal
|
|
75
|
+
mounter = Padrino.mount('test_app', app_file: __FILE__).to('/')
|
|
76
|
+
assert_equal 'test_app', mounter.name
|
|
77
|
+
assert_equal 'TestApp', mounter.app_class
|
|
78
78
|
assert_equal TestApp, mounter.app_obj
|
|
79
79
|
assert_equal __FILE__, mounter.app_file
|
|
80
|
-
assert_equal
|
|
80
|
+
assert_equal '/', mounter.uri_root
|
|
81
81
|
assert_equal File.dirname(mounter.app_file), mounter.app_root
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
it 'should mount a primary app to sub_uri' do
|
|
85
|
-
mounter = Padrino.mount(
|
|
86
|
-
assert_equal
|
|
87
|
-
assert_equal
|
|
85
|
+
mounter = Padrino.mount('test_app', app_file: __FILE__).to('/me')
|
|
86
|
+
assert_equal 'test_app', mounter.name
|
|
87
|
+
assert_equal 'TestApp', mounter.app_class
|
|
88
88
|
assert_equal TestApp, mounter.app_obj
|
|
89
89
|
assert_equal __FILE__, mounter.app_file
|
|
90
|
-
assert_equal
|
|
90
|
+
assert_equal '/me', mounter.uri_root
|
|
91
91
|
assert_equal File.dirname(mounter.app_file), mounter.app_root
|
|
92
92
|
end
|
|
93
93
|
|
|
@@ -98,7 +98,7 @@ describe "Mounter" do
|
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
it 'should raise error when app has no located object' do
|
|
101
|
-
assert_raises(Padrino::Mounter::MounterException) { Padrino.mount(
|
|
101
|
+
assert_raises(Padrino::Mounter::MounterException) { Padrino.mount('tester_app', app_file: '/path/to/file.rb').to('/test') }
|
|
102
102
|
assert_equal 0, Padrino.mounted_apps.size
|
|
103
103
|
end
|
|
104
104
|
|
|
@@ -106,21 +106,21 @@ describe "Mounter" do
|
|
|
106
106
|
class ::OneApp < Padrino::Application; end
|
|
107
107
|
class ::TwoApp < Padrino::Application; end
|
|
108
108
|
|
|
109
|
-
Padrino.mount(
|
|
110
|
-
Padrino.mount(
|
|
109
|
+
Padrino.mount('one_app').to('/one_app')
|
|
110
|
+
Padrino.mount('two_app').to('/two_app')
|
|
111
111
|
# And testing no duplicates
|
|
112
|
-
Padrino.mount(
|
|
113
|
-
Padrino.mount(
|
|
112
|
+
Padrino.mount('one_app').to('/one_app')
|
|
113
|
+
Padrino.mount('two_app').to('/two_app')
|
|
114
114
|
|
|
115
115
|
assert_equal OneApp, Padrino.mounted_apps[0].app_obj
|
|
116
116
|
assert_equal TwoApp, Padrino.mounted_apps[1].app_obj
|
|
117
|
-
assert_equal 2, Padrino.mounted_apps.size,
|
|
118
|
-
assert_equal [
|
|
117
|
+
assert_equal 2, Padrino.mounted_apps.size, 'should not mount duplicate apps'
|
|
118
|
+
assert_equal %w[one_app two_app], Padrino.mounted_apps.map(&:name)
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
it 'should mount app with the same name as the module' do
|
|
122
|
-
Padrino.mount(
|
|
123
|
-
Padrino.mount(
|
|
122
|
+
Padrino.mount('Demo::App', app_file: File.expand_path("#{__dir__}/fixtures/apps/demo_app.rb")).to('/app')
|
|
123
|
+
Padrino.mount('Demo::Demo', app_file: File.expand_path("#{__dir__}/fixtures/apps/demo_demo.rb")).to('/')
|
|
124
124
|
|
|
125
125
|
Padrino.mounted_apps.each do |app|
|
|
126
126
|
assert_equal app.app_obj.setup_application!, true
|
|
@@ -128,49 +128,53 @@ describe "Mounter" do
|
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
it 'should change mounted_root' do
|
|
131
|
-
Padrino.mounted_root =
|
|
132
|
-
assert_equal Padrino.root(
|
|
133
|
-
Padrino.mounted_root =
|
|
134
|
-
assert_equal Padrino.root(
|
|
131
|
+
Padrino.mounted_root = 'fixtures'
|
|
132
|
+
assert_equal Padrino.root('fixtures', 'test', 'app.rb'), Padrino.mounted_root('test', 'app.rb')
|
|
133
|
+
Padrino.mounted_root = 'apps'
|
|
134
|
+
assert_equal Padrino.root('apps', 'test', 'app.rb'), Padrino.mounted_root('test', 'app.rb')
|
|
135
135
|
Padrino.mounted_root = nil
|
|
136
|
-
assert_equal Padrino.root(
|
|
136
|
+
assert_equal Padrino.root('test', 'app.rb'), Padrino.mounted_root('test', 'app.rb')
|
|
137
137
|
end
|
|
138
138
|
|
|
139
139
|
it 'should be able to access routes data for mounted apps' do
|
|
140
140
|
class ::OneApp < Padrino::Application
|
|
141
|
-
get(
|
|
142
|
-
get(:index, :
|
|
143
|
-
get(%r{/foo|/baz}) {
|
|
141
|
+
get('/test') { 'test' }
|
|
142
|
+
get(:index, provides: %i[js json]) { 'index' }
|
|
143
|
+
get(%r{/foo|/baz}) { 'regexp' }
|
|
144
|
+
|
|
144
145
|
controllers :posts do
|
|
145
|
-
get(:index) {
|
|
146
|
-
get(:new, :
|
|
147
|
-
get(:show, :
|
|
148
|
-
post(:create, :
|
|
149
|
-
get(:regexp, :
|
|
146
|
+
get(:index) { 'index' }
|
|
147
|
+
get(:new, provides: :js) { 'new' }
|
|
148
|
+
get(:show, provides: %i[js html], with: :id) { 'show' }
|
|
149
|
+
post(:create, provides: :js, with: :id) { 'create' }
|
|
150
|
+
get(:regexp, map: %r{/foo|/baz}) { 'regexp' }
|
|
150
151
|
end
|
|
151
152
|
end
|
|
153
|
+
|
|
152
154
|
class ::TwoApp < Padrino::Application
|
|
153
155
|
controllers :users do
|
|
154
|
-
get(:index) {
|
|
155
|
-
get(:new) {
|
|
156
|
-
post(:create) {
|
|
157
|
-
put(:update) {
|
|
158
|
-
delete(:destroy) {
|
|
156
|
+
get(:index) { 'users' }
|
|
157
|
+
get(:new) { 'users new' }
|
|
158
|
+
post(:create) { 'users create' }
|
|
159
|
+
put(:update) { 'users update' }
|
|
160
|
+
delete(:destroy) { 'users delete' }
|
|
159
161
|
end
|
|
162
|
+
|
|
160
163
|
controllers :foo_bar do
|
|
161
|
-
get(:index) {
|
|
162
|
-
get(:new) {
|
|
163
|
-
post(:create) {
|
|
164
|
-
put(:update) {
|
|
165
|
-
delete(:destroy) {
|
|
164
|
+
get(:index) { 'foo bar index' }
|
|
165
|
+
get(:new) { 'foo bar new' }
|
|
166
|
+
post(:create) { 'foo bar create' }
|
|
167
|
+
put(:update) { 'foo bar update' }
|
|
168
|
+
delete(:destroy) { 'foo bar delete' }
|
|
166
169
|
end
|
|
170
|
+
|
|
167
171
|
controllers :test, :nested do
|
|
168
|
-
get(:test1){
|
|
172
|
+
get(:test1) { 'test1' }
|
|
169
173
|
end
|
|
170
174
|
end
|
|
171
175
|
|
|
172
|
-
Padrino.mount(
|
|
173
|
-
Padrino.mount(
|
|
176
|
+
Padrino.mount('one_app').to('/')
|
|
177
|
+
Padrino.mount('two_app').to('/two_app')
|
|
174
178
|
|
|
175
179
|
assert_equal 15, Padrino.mounted_apps[0].routes.size
|
|
176
180
|
assert_equal 16, Padrino.mounted_apps[1].routes.size
|
|
@@ -178,136 +182,142 @@ describe "Mounter" do
|
|
|
178
182
|
assert_equal 11, Padrino.mounted_apps[1].named_routes.size
|
|
179
183
|
|
|
180
184
|
first_route = Padrino.mounted_apps[0].named_routes[3]
|
|
181
|
-
assert_equal
|
|
182
|
-
assert_equal
|
|
183
|
-
assert_equal
|
|
184
|
-
assert_equal
|
|
185
|
+
assert_equal 'posts show', first_route.identifier.to_s
|
|
186
|
+
assert_equal '(:posts, :show)', first_route.name
|
|
187
|
+
assert_equal 'GET', first_route.verb
|
|
188
|
+
assert_equal '/posts/show/:id(.:format)?', first_route.path
|
|
185
189
|
another_route = Padrino.mounted_apps[1].named_routes[2]
|
|
186
|
-
assert_equal
|
|
187
|
-
assert_equal
|
|
188
|
-
assert_equal
|
|
189
|
-
assert_equal
|
|
190
|
+
assert_equal 'users create', another_route.identifier.to_s
|
|
191
|
+
assert_equal '(:users, :create)', another_route.name
|
|
192
|
+
assert_equal 'POST', another_route.verb
|
|
193
|
+
assert_equal '/two_app/users/create', another_route.path
|
|
190
194
|
regexp_route = Padrino.mounted_apps[0].named_routes[5]
|
|
191
|
-
assert_equal
|
|
192
|
-
assert_equal
|
|
193
|
-
assert_equal
|
|
195
|
+
assert_equal 'posts regexp', regexp_route.identifier.to_s
|
|
196
|
+
assert_equal '(:posts, :regexp)', regexp_route.name
|
|
197
|
+
assert_equal '/\\/foo|\\/baz/', regexp_route.path
|
|
194
198
|
foo_bar_route = Padrino.mounted_apps[1].named_routes[5]
|
|
195
|
-
assert_equal
|
|
199
|
+
assert_equal '(:foo_bar, :index)', foo_bar_route.name
|
|
196
200
|
nested_route = Padrino.mounted_apps[1].named_routes[10]
|
|
197
|
-
assert_equal
|
|
201
|
+
assert_equal '(:test_nested, :test1)', nested_route.name
|
|
198
202
|
end
|
|
199
|
-
|
|
203
|
+
|
|
200
204
|
it 'should configure cascade apps' do
|
|
201
205
|
class ::App1 < Padrino::Application
|
|
202
206
|
get(:index) { halt 404, 'index1' }
|
|
203
207
|
end
|
|
208
|
+
|
|
204
209
|
class ::App2 < Padrino::Application
|
|
205
210
|
get(:index) { halt 404, 'index2' }
|
|
206
211
|
end
|
|
212
|
+
|
|
207
213
|
class ::App3 < Padrino::Application
|
|
208
214
|
get(:index) { halt 404, 'index3' }
|
|
209
215
|
end
|
|
210
|
-
|
|
216
|
+
|
|
217
|
+
Padrino.mount('app1', cascade: true).to('/foo')
|
|
211
218
|
Padrino.mount('app2').to('/foo')
|
|
212
219
|
Padrino.mount('app3').to('/foo')
|
|
213
|
-
res = Rack::MockRequest.new(Padrino.application).get(
|
|
220
|
+
res = Rack::MockRequest.new(Padrino.application).get('/foo')
|
|
214
221
|
assert_equal 'index2', res.body
|
|
215
222
|
end
|
|
216
223
|
|
|
217
224
|
it 'should correctly instantiate a new padrino application' do
|
|
218
225
|
mock_app do
|
|
219
|
-
get(
|
|
220
|
-
get(
|
|
226
|
+
get('/demo_1') { 'Im Demo 1' }
|
|
227
|
+
get('/demo_2') { 'Im Demo 2' }
|
|
221
228
|
end
|
|
222
229
|
|
|
223
230
|
get '/demo_1'
|
|
224
|
-
assert_equal
|
|
231
|
+
assert_equal 'Im Demo 1', response.body
|
|
225
232
|
get '/demo_2'
|
|
226
|
-
assert_equal
|
|
233
|
+
assert_equal 'Im Demo 2', response.body
|
|
227
234
|
end
|
|
228
235
|
|
|
229
236
|
it 'should not clobber the public setting when mounting an app' do
|
|
230
237
|
class ::PublicApp < Padrino::Application
|
|
231
|
-
set :root,
|
|
238
|
+
set :root, '/root'
|
|
232
239
|
set :public_folder, __dir__
|
|
233
240
|
end
|
|
234
241
|
|
|
235
|
-
Padrino.mount(
|
|
236
|
-
res = Rack::MockRequest.new(Padrino.application).get(
|
|
242
|
+
Padrino.mount('public_app').to('/public')
|
|
243
|
+
res = Rack::MockRequest.new(Padrino.application).get('/public/test_mounter.rb')
|
|
237
244
|
assert res.ok?
|
|
238
245
|
assert_equal File.read(__FILE__), res.body
|
|
239
246
|
end
|
|
240
247
|
|
|
241
248
|
it 'should load apps from gems' do
|
|
242
|
-
spec_file = Padrino.root(
|
|
249
|
+
spec_file = Padrino.root('fixtures', 'app_gem', 'app_gem.gemspec')
|
|
243
250
|
spec = Gem::Specification.load(spec_file)
|
|
244
251
|
spec.activate
|
|
245
252
|
def spec.full_gem_path
|
|
246
|
-
Padrino.root(
|
|
253
|
+
Padrino.root('fixtures', 'app_gem')
|
|
247
254
|
end
|
|
248
255
|
|
|
249
|
-
require Padrino.root(
|
|
256
|
+
require Padrino.root('fixtures', 'app_gem', 'lib', 'app_gem')
|
|
250
257
|
|
|
251
|
-
Padrino.mount(
|
|
258
|
+
Padrino.mount('AppGem::App').to('/from_gem')
|
|
252
259
|
mounter = Padrino.mounted_apps[0]
|
|
253
260
|
assert_equal AppGem::App, mounter.app_obj
|
|
254
261
|
assert_equal Padrino.root('public'), mounter.app_obj.public_folder
|
|
255
262
|
end
|
|
256
263
|
|
|
257
264
|
it 'should support the Rack Application' do
|
|
258
|
-
path = File.expand_path(
|
|
265
|
+
path = File.expand_path("#{__dir__}/fixtures/apps/mountable_apps/rack_apps")
|
|
259
266
|
require path
|
|
260
|
-
Padrino.mount('rack_app', :
|
|
261
|
-
Padrino.mount('rack_app2', :
|
|
262
|
-
Padrino.mount('sinatra_app', :
|
|
267
|
+
Padrino.mount('rack_app', app_class: 'RackApp', app_file: path).to('/rack_app')
|
|
268
|
+
Padrino.mount('rack_app2', app_class: 'RackApp2', app_file: path).to('/rack_app2')
|
|
269
|
+
Padrino.mount('sinatra_app', app_class: 'SinatraApp', app_file: path).to('/sinatra_app')
|
|
263
270
|
app = Padrino.application
|
|
264
|
-
res = Rack::MockRequest.new(app).get(
|
|
265
|
-
assert_equal
|
|
266
|
-
res = Rack::MockRequest.new(app).get(
|
|
267
|
-
assert_equal
|
|
268
|
-
res = Rack::MockRequest.new(app).get(
|
|
269
|
-
assert_equal
|
|
270
|
-
res = Rack::MockRequest.new(app).get(
|
|
271
|
+
res = Rack::MockRequest.new(app).get('/rack_app')
|
|
272
|
+
assert_equal 'hello rack app', res.body
|
|
273
|
+
res = Rack::MockRequest.new(app).get('/rack_app2')
|
|
274
|
+
assert_equal 'hello rack app2', res.body
|
|
275
|
+
res = Rack::MockRequest.new(app).get('/sinatra_app')
|
|
276
|
+
assert_equal 'hello sinatra app', res.body
|
|
277
|
+
res = Rack::MockRequest.new(app).get('/sinatra_app/static.html')
|
|
271
278
|
assert_equal "hello static file\n", res.body
|
|
272
279
|
assert_empty RackApp.prerequisites
|
|
273
280
|
end
|
|
274
281
|
|
|
275
282
|
it 'should support the Rack Application with cascading style' do
|
|
276
|
-
path = File.expand_path(
|
|
283
|
+
path = File.expand_path("#{__dir__}/fixtures/apps/mountable_apps/rack_apps")
|
|
277
284
|
require path
|
|
278
|
-
Padrino.mount('rack_app', :
|
|
279
|
-
Padrino.mount('sinatra_app', :
|
|
285
|
+
Padrino.mount('rack_app', app_class: 'RackApp', app_file: path, cascade: false).to('/rack_app')
|
|
286
|
+
Padrino.mount('sinatra_app', app_class: 'SinatraApp', app_file: path).to('/')
|
|
280
287
|
app = Padrino.application
|
|
281
|
-
res = Rack::MockRequest.new(app).get(
|
|
282
|
-
assert_equal
|
|
288
|
+
res = Rack::MockRequest.new(app).get('/rack_app/404')
|
|
289
|
+
assert_equal 'not found ;(', res.body
|
|
283
290
|
end
|
|
284
291
|
|
|
285
292
|
it 'should support the Rack Application inside padrino project' do
|
|
286
|
-
path = File.expand_path(
|
|
287
|
-
api_path = File.expand_path(
|
|
293
|
+
path = File.expand_path("#{__dir__}/fixtures/apps/demo_project/app")
|
|
294
|
+
api_path = File.expand_path("#{__dir__}/fixtures/apps/demo_project/api/app")
|
|
288
295
|
require path
|
|
289
296
|
require api_path
|
|
290
|
-
Padrino.mount('api_app', :
|
|
291
|
-
Padrino.mount('main_app', :
|
|
297
|
+
Padrino.mount('api_app', app_class: 'DemoProject::API', app_file: api_path).to('/api')
|
|
298
|
+
Padrino.mount('main_app', app_class: 'DemoProject::App').to('/')
|
|
292
299
|
app = Padrino.application
|
|
293
|
-
res = Rack::MockRequest.new(app).get(
|
|
294
|
-
assert_equal
|
|
295
|
-
res = Rack::MockRequest.new(app).get(
|
|
296
|
-
assert_equal
|
|
300
|
+
res = Rack::MockRequest.new(app).get('/')
|
|
301
|
+
assert_equal 'padrino app', res.body
|
|
302
|
+
res = Rack::MockRequest.new(app).get('/api/hey')
|
|
303
|
+
assert_equal 'api app', res.body
|
|
297
304
|
assert defined?(DemoProject::APILib)
|
|
298
305
|
end
|
|
299
306
|
|
|
300
307
|
it "should not load dependency files if app's root isn't started with Padrino.root" do
|
|
301
|
-
path = File.expand_path(
|
|
302
|
-
fake_path = File.expand_path(
|
|
308
|
+
path = File.expand_path("#{__dir__}/fixtures/apps/demo_project/app")
|
|
309
|
+
fake_path = File.expand_path("#{__dir__}/fixtures/apps/external_apps/fake_root")
|
|
310
|
+
|
|
303
311
|
require path
|
|
304
312
|
require fake_path
|
|
305
|
-
|
|
306
|
-
Padrino.mount('
|
|
307
|
-
Padrino.
|
|
313
|
+
|
|
314
|
+
Padrino.mount('fake_root', app_class: 'FakeRoot').to('/fake_root')
|
|
315
|
+
Padrino.mount('main_app', app_class: 'DemoProject::App').to('/')
|
|
316
|
+
Padrino.stub(:root, File.expand_path("#{__dir__}/fixtures/apps/demo_project")) do
|
|
308
317
|
Padrino.application
|
|
309
318
|
end
|
|
310
|
-
|
|
319
|
+
|
|
320
|
+
refute defined?(FakeLib)
|
|
311
321
|
end
|
|
312
322
|
end
|
|
313
323
|
end
|