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
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe 'Padrino::ParamsProtection' do
|
|
4
4
|
before do
|
|
5
5
|
@teri = { 'name' => 'Teri Bauer', 'position' => 'baby' }
|
|
6
6
|
@kim = { 'name' => 'Kim Bauer', 'position' => 'daughter', 'child' => @teri }
|
|
@@ -12,36 +12,36 @@ describe "Padrino::ParamsProtection" do
|
|
|
12
12
|
it 'should drop all parameters except allowed ones' do
|
|
13
13
|
result = nil
|
|
14
14
|
mock_app do
|
|
15
|
-
post :basic, :
|
|
15
|
+
post :basic, params: [:name] do
|
|
16
16
|
result = params
|
|
17
17
|
''
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
|
-
post
|
|
20
|
+
post "/basic?#{@jack_query}"
|
|
21
21
|
assert_equal({ 'name' => @jack['name'] }, result)
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it 'should preserve original params' do
|
|
25
25
|
result = nil
|
|
26
26
|
mock_app do
|
|
27
|
-
post :basic, :
|
|
27
|
+
post :basic, params: [:name] do
|
|
28
28
|
result = original_params
|
|
29
29
|
''
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
|
-
post
|
|
32
|
+
post "/basic?#{@jack_query}"
|
|
33
33
|
assert_equal(@jack, result)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it 'should work with recursive data' do
|
|
37
37
|
result = nil
|
|
38
38
|
mock_app do
|
|
39
|
-
post :basic, :
|
|
39
|
+
post :basic, params: [:name, { child: [:name, { child: [:name] }] }] do
|
|
40
40
|
result = [params, original_params]
|
|
41
41
|
''
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
|
-
post
|
|
44
|
+
post "/basic?#{@jack_query}"
|
|
45
45
|
assert_equal(
|
|
46
46
|
[
|
|
47
47
|
{ 'name' => @jack['name'], 'child' => { 'name' => @kim['name'], 'child' => { 'name' => @teri['name'] } } },
|
|
@@ -54,93 +54,93 @@ describe "Padrino::ParamsProtection" do
|
|
|
54
54
|
it 'should be able to process the data' do
|
|
55
55
|
result = nil
|
|
56
56
|
mock_app do
|
|
57
|
-
post :basic, :
|
|
57
|
+
post :basic, params: [:name, { position: proc { |v| "anti-#{v}" } }] do
|
|
58
58
|
result = params
|
|
59
59
|
''
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
|
-
post
|
|
62
|
+
post "/basic?#{@jack_query}"
|
|
63
63
|
assert_equal({ 'name' => @jack['name'], 'position' => 'anti-terrorist' }, result)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
it 'should pass :with parameters' do
|
|
67
67
|
result = nil
|
|
68
68
|
mock_app do
|
|
69
|
-
post :basic, :
|
|
69
|
+
post :basic, with: %i[id tag], params: [:name] do
|
|
70
70
|
result = params
|
|
71
71
|
''
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
|
-
post
|
|
74
|
+
post "/basic/24/42?#{@jack_query}"
|
|
75
75
|
assert_equal({ 'name' => @jack['name'], 'id' => '24', 'tag' => '42' }, result)
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
it 'should not fail if :with is not an Array' do
|
|
79
79
|
result = nil
|
|
80
80
|
mock_app do
|
|
81
|
-
post :basic, :
|
|
81
|
+
post :basic, with: :id, params: [:id] do
|
|
82
82
|
result = params
|
|
83
83
|
''
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
|
-
post
|
|
86
|
+
post "/basic/24?#{@jack_query}"
|
|
87
87
|
assert_equal({ 'id' => '24' }, result)
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
it 'should understand true or false values' do
|
|
91
91
|
result = nil
|
|
92
92
|
mock_app do
|
|
93
|
-
get :hide, :
|
|
93
|
+
get :hide, with: [:id], params: false do
|
|
94
94
|
result = params
|
|
95
95
|
''
|
|
96
96
|
end
|
|
97
|
-
get :show, :
|
|
97
|
+
get :show, with: [:id], params: true do
|
|
98
98
|
result = params
|
|
99
99
|
''
|
|
100
100
|
end
|
|
101
101
|
end
|
|
102
|
-
get
|
|
103
|
-
assert_equal({
|
|
104
|
-
get
|
|
105
|
-
assert_equal({
|
|
102
|
+
get "/hide/1?#{@jack_query}"
|
|
103
|
+
assert_equal({ 'id' => '1' }, result)
|
|
104
|
+
get "/show/1?#{@jack_query}"
|
|
105
|
+
assert_equal({ 'id' => '1' }.merge(@jack), result)
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
it 'should be configurable with controller options' do
|
|
109
109
|
result = nil
|
|
110
110
|
mock_app do
|
|
111
|
-
controller :persons, :
|
|
112
|
-
post :create, :
|
|
111
|
+
controller :persons, params: [:name] do
|
|
112
|
+
post :create, params: %i[name position] do
|
|
113
113
|
result = params
|
|
114
114
|
''
|
|
115
115
|
end
|
|
116
|
-
post :update, :
|
|
116
|
+
post :update, with: [:id] do
|
|
117
117
|
result = params
|
|
118
118
|
''
|
|
119
119
|
end
|
|
120
|
-
post :delete, :
|
|
120
|
+
post :delete, params: true do
|
|
121
121
|
result = params
|
|
122
122
|
''
|
|
123
123
|
end
|
|
124
|
-
post :destroy, :
|
|
124
|
+
post :destroy, with: [:id], params: false do
|
|
125
125
|
result = params
|
|
126
126
|
''
|
|
127
127
|
end
|
|
128
128
|
end
|
|
129
|
-
controller :noparam, :
|
|
129
|
+
controller :noparam, params: false do
|
|
130
130
|
get :index do
|
|
131
131
|
result = params
|
|
132
132
|
''
|
|
133
133
|
end
|
|
134
134
|
end
|
|
135
135
|
end
|
|
136
|
-
post
|
|
136
|
+
post "/persons/create?#{@jack_query}"
|
|
137
137
|
assert_equal({ 'name' => @jack['name'], 'position' => 'terrorist' }, result)
|
|
138
138
|
post '/persons/update/1?name=Chloe+O\'Brian&position=hacker'
|
|
139
139
|
assert_equal({ 'id' => '1', 'name' => 'Chloe O\'Brian' }, result)
|
|
140
|
-
post
|
|
140
|
+
post "/persons/delete?#{@jack_query}"
|
|
141
141
|
assert_equal(@jack, result)
|
|
142
|
-
post
|
|
143
|
-
assert_equal({
|
|
142
|
+
post "/persons/destroy/1?#{@jack_query}"
|
|
143
|
+
assert_equal({ 'id' => '1' }, result)
|
|
144
144
|
get '/noparam?a=1;b=2'
|
|
145
145
|
assert_empty(result)
|
|
146
146
|
end
|
|
@@ -148,43 +148,43 @@ describe "Padrino::ParamsProtection" do
|
|
|
148
148
|
it 'should successfully filter hashes' do
|
|
149
149
|
result = nil
|
|
150
150
|
mock_app do
|
|
151
|
-
post :family, :
|
|
151
|
+
post :family, params: [persons: [:name]] do
|
|
152
152
|
result = params
|
|
153
153
|
''
|
|
154
154
|
end
|
|
155
155
|
end
|
|
156
|
-
post
|
|
157
|
-
assert_equal({
|
|
156
|
+
post "/family?#{Padrino::Utils.build_uri_query(@family)}"
|
|
157
|
+
assert_equal({ 'persons' => { '3' => { 'name' => @jack['name'] }, '2' => { 'name' => @kim['name'] }, '1' => { 'name' => @teri['name'] } } }, result)
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
it 'should pass arrays' do
|
|
161
161
|
result = nil
|
|
162
162
|
mock_app do
|
|
163
|
-
post :family, :
|
|
163
|
+
post :family, params: [names: []] do
|
|
164
164
|
result = params
|
|
165
165
|
''
|
|
166
166
|
end
|
|
167
167
|
end
|
|
168
|
-
post
|
|
169
|
-
assert_equal({
|
|
168
|
+
post "/family?#{Padrino::Utils.build_uri_query(names: %w[Jack Kim Teri])}"
|
|
169
|
+
assert_equal({ 'names' => %w[Jack Kim Teri] }, result)
|
|
170
170
|
end
|
|
171
171
|
|
|
172
172
|
it 'should tolerate weird inflections' do
|
|
173
173
|
result = nil
|
|
174
174
|
mock_app do
|
|
175
|
-
post :i, :
|
|
175
|
+
post :i, params: [gotta: [:what]] do
|
|
176
176
|
result = params
|
|
177
177
|
''
|
|
178
178
|
end
|
|
179
179
|
end
|
|
180
|
-
post
|
|
181
|
-
assert_equal({
|
|
180
|
+
post "/i?#{Padrino::Utils.build_uri_query(gotta: { what: 'go', who: 'self' })}"
|
|
181
|
+
assert_equal({ 'gotta' => { 'what' => 'go' } }, result)
|
|
182
182
|
end
|
|
183
183
|
|
|
184
184
|
it 'should drop the key if the data type does not match route configuration' do
|
|
185
185
|
result = nil
|
|
186
186
|
mock_app do
|
|
187
|
-
post :i, :
|
|
187
|
+
post :i, params: [gotta: [:what]] do
|
|
188
188
|
result = params
|
|
189
189
|
''
|
|
190
190
|
end
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
describe "ComplexReloader" do
|
|
1
|
+
require_relative 'helper'
|
|
2
|
+
require_relative 'fixtures/apps/complex'
|
|
5
3
|
|
|
4
|
+
describe 'ComplexReloader' do
|
|
6
5
|
describe 'for complex reload functionality' do
|
|
7
6
|
before do
|
|
8
7
|
Padrino.clear!
|
|
9
|
-
Padrino.mount(
|
|
10
|
-
Padrino.mount(
|
|
8
|
+
Padrino.mount('complex_1_demo').to('/complex_1_demo')
|
|
9
|
+
Padrino.mount('complex_2_demo').to('/complex_2_demo')
|
|
11
10
|
end
|
|
12
11
|
|
|
13
12
|
it 'should correctly instantiate Complex(1-2)Demo fixture' do
|
|
14
|
-
assert_equal [
|
|
15
|
-
assert_equal [
|
|
13
|
+
assert_equal ['/complex_1_demo', '/complex_2_demo'], Padrino.mounted_apps.map(&:uri_root)
|
|
14
|
+
assert_equal %w[complex_1_demo complex_2_demo], Padrino.mounted_apps.map(&:name)
|
|
16
15
|
assert Complex1Demo.reload?
|
|
17
16
|
assert Complex2Demo.reload?
|
|
18
17
|
assert_match %r{fixtures/apps/complex.rb}, Complex1Demo.app_file
|
|
@@ -23,51 +22,52 @@ describe "ComplexReloader" do
|
|
|
23
22
|
assert_match %r{fixtures/apps/complex.rb}, Complex1Demo.app_file
|
|
24
23
|
@app = Padrino.application
|
|
25
24
|
|
|
26
|
-
get
|
|
25
|
+
get '/'
|
|
27
26
|
assert_equal 404, status
|
|
28
27
|
|
|
29
|
-
get
|
|
28
|
+
get '/complex_1_demo'
|
|
30
29
|
assert_equal "Given random #{LibDemo.give_me_a_random}", body
|
|
31
30
|
|
|
32
|
-
get
|
|
31
|
+
get '/complex_2_demo'
|
|
33
32
|
assert_equal 200, status
|
|
34
33
|
|
|
35
|
-
get
|
|
34
|
+
get '/complex_1_demo/old'
|
|
36
35
|
assert_equal 200, status
|
|
37
36
|
|
|
38
|
-
get
|
|
37
|
+
get '/complex_2_demo/old'
|
|
39
38
|
assert_equal 200, status
|
|
40
39
|
|
|
41
|
-
get
|
|
40
|
+
get '/complex_2_demo/var/destroy'
|
|
42
41
|
assert_equal '{}', body
|
|
43
42
|
|
|
44
43
|
new_phrase = "The magick number is: #{rand(2**255)}!"
|
|
45
44
|
buffer = File.read(Complex1Demo.app_file)
|
|
46
45
|
new_buffer = buffer.sub(/The magick number is: \d+!/, new_phrase)
|
|
47
|
-
new_buffer.sub!(/get\(:destroy\)/, 'get(:destroy, :
|
|
46
|
+
new_buffer.sub!(/get\(:destroy\)/, 'get(:destroy, with: :id)')
|
|
47
|
+
|
|
48
48
|
begin
|
|
49
|
-
File.open(Complex1Demo.app_file,
|
|
50
|
-
Time.stub(:now, Time.now + 2) { get
|
|
49
|
+
File.open(Complex1Demo.app_file, 'w') { |f| f.write(new_buffer) }
|
|
50
|
+
Time.stub(:now, Time.now + 2) { get '/complex_2_demo' }
|
|
51
51
|
assert_equal new_phrase, body
|
|
52
52
|
|
|
53
53
|
# Re-Check that we didn't forget any route
|
|
54
|
-
get
|
|
54
|
+
get '/complex_1_demo'
|
|
55
55
|
assert_equal "Given random #{LibDemo.give_me_a_random}", body
|
|
56
56
|
|
|
57
|
-
get
|
|
57
|
+
get '/complex_2_demo'
|
|
58
58
|
assert_equal 200, status
|
|
59
59
|
|
|
60
|
-
get
|
|
60
|
+
get '/complex_1_demo/old'
|
|
61
61
|
assert_equal 200, status
|
|
62
62
|
|
|
63
|
-
get
|
|
63
|
+
get '/complex_2_demo/old'
|
|
64
64
|
assert_equal 200, status
|
|
65
65
|
|
|
66
|
-
get
|
|
66
|
+
get '/complex_2_demo/var/destroy/variable'
|
|
67
67
|
assert_equal '{"id":"variable"}', body
|
|
68
68
|
ensure
|
|
69
69
|
# Now we need to prevent to commit a new changed file so we revert it
|
|
70
|
-
File.open(Complex1Demo.app_file,
|
|
70
|
+
File.open(Complex1Demo.app_file, 'w') { |f| f.write(buffer) }
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
73
|
end
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
|
+
require_relative 'fixtures/reloadable_apps/main/app'
|
|
3
3
|
|
|
4
|
-
describe
|
|
5
|
-
describe
|
|
4
|
+
describe 'ExternalReloader' do
|
|
5
|
+
describe 'for external app' do
|
|
6
6
|
before do
|
|
7
7
|
Padrino.clear!
|
|
8
|
-
Padrino.mount(
|
|
9
|
-
Padrino.mount(
|
|
8
|
+
Padrino.mount('ReloadableApp::External').to('/reloadable/external')
|
|
9
|
+
Padrino.mount('ReloadableApp::Main').to('/reloadable')
|
|
10
10
|
Padrino.load!
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
it
|
|
13
|
+
it 'should avoid reloading the file if its path is not started with Padrino.root' do
|
|
14
14
|
@app = Padrino.application
|
|
15
|
-
Padrino.stub(:root, File.expand_path(
|
|
16
|
-
get
|
|
15
|
+
Padrino.stub(:root, File.expand_path("#{__dir__}/fixtures/reloadable_apps/main")) do
|
|
16
|
+
get '/reloadable/external/base'
|
|
17
17
|
end
|
|
18
|
-
assert_equal
|
|
18
|
+
assert_equal 'Hello External App', body
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
describe "SimpleReloader" do
|
|
1
|
+
require_relative 'helper'
|
|
2
|
+
require_relative 'fixtures/apps/simple'
|
|
5
3
|
|
|
4
|
+
describe 'SimpleReloader' do
|
|
6
5
|
describe 'for simple reset functionality' do
|
|
7
|
-
|
|
8
6
|
it 'should reset routes' do
|
|
9
7
|
mock_app do
|
|
10
8
|
(1..10).each do |i|
|
|
11
9
|
get("/#{i}") { "Foo #{i}" }
|
|
12
10
|
end
|
|
13
11
|
end
|
|
12
|
+
|
|
14
13
|
(1..10).each do |i|
|
|
15
14
|
get "/#{i}"
|
|
16
15
|
assert_equal "Foo #{i}", body
|
|
17
16
|
end
|
|
17
|
+
|
|
18
18
|
@app.reset_routes!
|
|
19
19
|
(1..10).each do |i|
|
|
20
20
|
get "/#{i}"
|
|
@@ -25,72 +25,75 @@ describe "SimpleReloader" do
|
|
|
25
25
|
it 'should keep sinatra routes on development' do
|
|
26
26
|
mock_app do
|
|
27
27
|
set :environment, :development
|
|
28
|
-
get(
|
|
28
|
+
get('/') { 'ok' }
|
|
29
29
|
end
|
|
30
|
+
|
|
30
31
|
assert_equal :development, @app.environment
|
|
31
|
-
get
|
|
32
|
+
get '/'
|
|
32
33
|
assert_equal 200, status
|
|
33
|
-
get
|
|
34
|
+
get '/__sinatra__/404.png'
|
|
34
35
|
assert_equal 200, status
|
|
35
|
-
assert_match(/
|
|
36
|
+
assert_match(%r{image/png}, response['Content-Type'])
|
|
36
37
|
@app.reset_routes!
|
|
37
|
-
get
|
|
38
|
+
get '/'
|
|
38
39
|
assert_equal 404, status
|
|
39
|
-
get
|
|
40
|
+
get '/__sinatra__/404.png'
|
|
40
41
|
assert_equal 200, status
|
|
41
|
-
assert_match(/
|
|
42
|
+
assert_match(%r{image/png}, response['Content-Type'])
|
|
42
43
|
end
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
describe 'for simple reload functionality' do
|
|
46
47
|
before do
|
|
47
48
|
Padrino.clear!
|
|
48
|
-
Padrino.mount(
|
|
49
|
+
Padrino.mount('simple_demo').to('/')
|
|
49
50
|
Padrino.reload!
|
|
50
51
|
end
|
|
51
52
|
|
|
52
53
|
it 'should correctly instantiate SimpleDemo fixture' do
|
|
53
|
-
assert_equal [
|
|
54
|
+
assert_equal ['simple_demo'], Padrino.mounted_apps.map(&:name)
|
|
54
55
|
assert SimpleDemo.reload?
|
|
55
56
|
assert_match %r{fixtures/apps/simple.rb}, SimpleDemo.app_file
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
it 'should correctly reload SimpleDemo fixture' do
|
|
59
60
|
@app = SimpleDemo
|
|
60
|
-
get
|
|
61
|
+
get '/'
|
|
61
62
|
assert ok?
|
|
62
63
|
new_phrase = "The magick number is: #{rand(2**255)}!"
|
|
63
64
|
buffer = File.read(SimpleDemo.app_file)
|
|
64
65
|
new_buffer = buffer.sub(/The magick number is: \d+!/, new_phrase)
|
|
66
|
+
|
|
65
67
|
begin
|
|
66
|
-
File.open(SimpleDemo.app_file,
|
|
67
|
-
Time.stub(:now, Time.now + 2) { get
|
|
68
|
+
File.open(SimpleDemo.app_file, 'w') { |f| f.write(new_buffer) }
|
|
69
|
+
Time.stub(:now, Time.now + 2) { get '/' }
|
|
68
70
|
assert_equal new_phrase, body
|
|
69
71
|
ensure
|
|
70
|
-
File.open(SimpleDemo.app_file,
|
|
72
|
+
File.open(SimpleDemo.app_file, 'w') { |f| f.write(buffer) }
|
|
71
73
|
Padrino.reload!
|
|
72
74
|
end
|
|
73
75
|
end
|
|
74
76
|
|
|
75
77
|
it 'should correctly reset SimpleDemo fixture' do
|
|
76
78
|
@app = SimpleDemo
|
|
77
|
-
get
|
|
79
|
+
get '/'
|
|
78
80
|
@app.reload!
|
|
79
|
-
get
|
|
81
|
+
get '/rand'
|
|
80
82
|
assert ok?
|
|
81
83
|
last_body = body
|
|
82
84
|
assert_equal 1, @app.filters[:before].size
|
|
83
|
-
assert_equal 0, @app.errors.reject{ |key, _| [404, Sinatra::NotFound].include? key }.size
|
|
85
|
+
assert_equal 0, @app.errors.reject { |key, _| [404, Sinatra::NotFound].include? key }.size
|
|
84
86
|
assert_equal 2, @app.filters[:after].size # app + content-type + padrino-flash
|
|
85
87
|
assert_equal 0, @app.middleware.size
|
|
86
88
|
assert_equal 4, @app.routes.size # GET+HEAD of "/" + GET+HEAD of "/rand" = 4
|
|
87
89
|
assert_equal 4, @app.extensions.size # [Padrino::ApplicationSetup, Padrino::ParamsProtection, Padrino::Routing, Padrino::Flash]
|
|
88
90
|
assert_equal 0, @app.templates.size
|
|
91
|
+
|
|
89
92
|
@app.reload!
|
|
90
|
-
get
|
|
93
|
+
get '/rand'
|
|
91
94
|
refute_equal last_body, body
|
|
92
95
|
assert_equal 1, @app.filters[:before].size
|
|
93
|
-
assert_equal 0, @app.errors.reject{ |key, _| [404, Sinatra::NotFound].include? key }.size
|
|
96
|
+
assert_equal 0, @app.errors.reject { |key, _| [404, Sinatra::NotFound].include? key }.size
|
|
94
97
|
assert_equal 2, @app.filters[:after].size
|
|
95
98
|
assert_equal 0, @app.middleware.size
|
|
96
99
|
assert_equal 4, @app.routes.size # GET+HEAD of "/" = 2
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative 'helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
4
|
-
describe
|
|
3
|
+
describe 'Padrino::Reloader::Storage' do
|
|
4
|
+
describe '#classes' do
|
|
5
5
|
it 'should take an snapshot of the current loaded classes' do
|
|
6
6
|
snapshot = Padrino::Reloader::Storage.send(:object_classes)
|
|
7
7
|
assert_equal snapshot.include?(Padrino::Logger), true
|
|
@@ -9,25 +9,22 @@ describe "Padrino::Reloader::Storage" do
|
|
|
9
9
|
|
|
10
10
|
it 'should return a Set object' do
|
|
11
11
|
snapshot = Padrino::Reloader::Storage.send(:object_classes)
|
|
12
|
-
assert_equal snapshot.
|
|
12
|
+
assert_equal snapshot.is_a?(Set), true
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it 'should be able to process a the class name given a block' do
|
|
16
16
|
klasses = Padrino::Reloader::Storage.send(:object_classes) do |klass|
|
|
17
17
|
next unless klass.respond_to?(:name) # fix JRuby < 1.7.22
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
end
|
|
18
|
+
|
|
19
|
+
klass if klass.name =~ /^Padrino::/
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
assert_equal (klasses.size > 1), true
|
|
24
|
-
klasses.each
|
|
25
|
-
assert_match(/^Padrino::/, klass.to_s)
|
|
26
|
-
end
|
|
23
|
+
klasses.each { |klass| assert_match(/^Padrino::/, klass.to_s) }
|
|
27
24
|
end
|
|
28
25
|
end
|
|
29
26
|
|
|
30
|
-
describe
|
|
27
|
+
describe '#new_classes' do
|
|
31
28
|
before do
|
|
32
29
|
@snapshot = Padrino::Reloader::Storage.send(:object_classes)
|
|
33
30
|
end
|
|
@@ -46,7 +43,7 @@ describe "Padrino::Reloader::Storage" do
|
|
|
46
43
|
|
|
47
44
|
it 'should return a Set object' do
|
|
48
45
|
new_classes = Padrino::Reloader::Storage.send(:new_classes, @snapshot)
|
|
49
|
-
assert_equal new_classes.
|
|
46
|
+
assert_equal new_classes.is_a?(Set), true
|
|
50
47
|
end
|
|
51
48
|
end
|
|
52
49
|
end
|