rack-perftools_profiler 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module PerftoolsProfiler
3
+ VERSION = "0.5.1"
4
+ end
5
+ end
@@ -1,76 +1,33 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rack/perftools_profiler/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{rack-perftools_profiler}
8
- s.version = "0.5.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Ben Brinckerhoff"]
12
- s.date = %q{2011-07-25}
6
+ s.name = "rack-perftools_profiler"
7
+ s.version = Rack::PerftoolsProfiler::VERSION
8
+ s.authors = ["Ben Brinckerhoff"]
9
+ s.email = ["ben@bbrinck.com"]
10
+ s.homepage = "http://github.com/bhb/rack-perftools_profiler"
11
+ s.summary = %q{Middleware for profiling Rack-compatible apps using perftools.rb}
13
12
  s.description = %q{Middleware for profiling Rack-compatible apps using perftools.rb}
14
- s.email = %q{ben@bbrinck.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "lib/rack/perftools_profiler.rb",
26
- "lib/rack/perftools_profiler/action.rb",
27
- "lib/rack/perftools_profiler/call_app_directly.rb",
28
- "lib/rack/perftools_profiler/profile_data_action.rb",
29
- "lib/rack/perftools_profiler/profile_once.rb",
30
- "lib/rack/perftools_profiler/profiler.rb",
31
- "lib/rack/perftools_profiler/profiler_middleware.rb",
32
- "lib/rack/perftools_profiler/return_data.rb",
33
- "lib/rack/perftools_profiler/return_password_error.rb",
34
- "lib/rack/perftools_profiler/start_profiling.rb",
35
- "lib/rack/perftools_profiler/stop_profiling.rb",
36
- "lib/rack/perftools_profiler/utils.rb",
37
- "rack-perftools_profiler-0.4.1.gem",
38
- "rack-perftools_profiler.gemspec",
39
- "test/multiple_request_profiling_test.rb",
40
- "test/rack-perftools-profiler_test.rb",
41
- "test/single_request_profiling_test.rb",
42
- "test/test_helper.rb"
43
- ]
44
- s.homepage = %q{http://github.com/bhb/rack-perftools_profiler}
13
+
14
+ s.rubyforge_project = "rack-perftools_profiler"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
45
19
  s.require_paths = ["lib"]
46
- s.rubygems_version = %q{1.6.2}
47
- s.summary = %q{Middleware for profiling Rack-compatible apps using perftools.rb}
48
20
 
49
- if s.respond_to? :specification_version then
50
- s.specification_version = 3
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
51
24
 
52
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
- s.add_runtime_dependency(%q<perftools.rb>, ["~> 0.5.6"])
54
- s.add_runtime_dependency(%q<rack>, ["~> 1.0"])
55
- s.add_runtime_dependency(%q<open4>, ["~> 1.0"])
56
- s.add_development_dependency(%q<rack>, ["~> 1.1"])
57
- s.add_development_dependency(%q<shoulda>, ["~> 2.10"])
58
- s.add_development_dependency(%q<mocha>, ["~> 0.9"])
59
- else
60
- s.add_dependency(%q<perftools.rb>, ["~> 0.5.6"])
61
- s.add_dependency(%q<rack>, ["~> 1.0"])
62
- s.add_dependency(%q<open4>, ["~> 1.0"])
63
- s.add_dependency(%q<rack>, ["~> 1.1"])
64
- s.add_dependency(%q<shoulda>, ["~> 2.10"])
65
- s.add_dependency(%q<mocha>, ["~> 0.9"])
66
- end
67
- else
68
- s.add_dependency(%q<perftools.rb>, ["~> 0.5.6"])
69
- s.add_dependency(%q<rack>, ["~> 1.0"])
70
- s.add_dependency(%q<open4>, ["~> 1.0"])
71
- s.add_dependency(%q<rack>, ["~> 1.1"])
72
- s.add_dependency(%q<shoulda>, ["~> 2.10"])
73
- s.add_dependency(%q<mocha>, ["~> 0.9"])
74
- end
75
- end
25
+ s.add_dependency 'perftools.rb', '~> 0.5.6'
26
+ s.add_dependency 'rack', '~> 1.0'
27
+ s.add_dependency('open4', '~> 1.0')
28
+ s.add_development_dependency 'rack', '~> 1.1'
29
+ s.add_development_dependency 'shoulda', '~> 2.10'
30
+ s.add_development_dependency 'mocha', '~> 0.9'
31
+ s.add_development_dependency 'rake', '~> 0.9.2'
76
32
 
33
+ end
@@ -8,14 +8,14 @@ class MultipleRequestProfilingTest < Test::Unit::TestCase
8
8
  @start_env = Rack::MockRequest.env_for('/__start__')
9
9
  @stop_env = Rack::MockRequest.env_for('/__stop__')
10
10
  @data_env = Rack::MockRequest.env_for('/__data__')
11
- @root_request_env = Rack::MockRequest.env_for("/")
11
+ @root_request_env = Rack::MockRequest.env_for("/")
12
12
  end
13
13
 
14
14
  def profile(profiled_app, options = {})
15
15
  start = options.fetch(:start) { @start_env }
16
16
  stop = options.fetch(:stop) { @stop_env }
17
17
  data = options.fetch(:data) { @data_env }
18
-
18
+
19
19
  profiled_app.call(start) if start != :none
20
20
  if block_given?
21
21
  yield profiled_app
@@ -116,7 +116,8 @@ class MultipleRequestProfilingTest < Test::Unit::TestCase
116
116
  should "allow 'printer' param to override :default_printer option'" do
117
117
  profiled_app = Rack::PerftoolsProfiler.new(@app, :default_printer => 'pdf')
118
118
  custom_data_env = Rack::MockRequest.env_for('__data__', :params => 'printer=gif')
119
- _, headers, _ = profile(profiled_app, :data => custom_data_env)
119
+ status, headers, body = profile(profiled_app, :data => custom_data_env)
120
+ assert_ok status, body
120
121
  assert_equal 'image/gif', headers['Content-Type']
121
122
  end
122
123
 
@@ -154,7 +155,7 @@ class MultipleRequestProfilingTest < Test::Unit::TestCase
154
155
  end
155
156
 
156
157
  context "when in bundler mode" do
157
-
158
+
158
159
  should "call pprof.rb using 'bundle' command if bundler is set" do
159
160
  status = stub_everything(:exitstatus => 0)
160
161
  profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true)
@@ -173,7 +174,7 @@ class MultipleRequestProfilingTest < Test::Unit::TestCase
173
174
  Dir.expects(:chdir).with('.').returns(["","",0])
174
175
  profile(profiled_app)
175
176
  end
176
-
177
+
177
178
  end
178
179
 
179
180
  context "when the nodefraction parameter is specified" do
@@ -239,11 +240,11 @@ class MultipleRequestProfilingTest < Test::Unit::TestCase
239
240
  profiled_app = Rack::PerftoolsProfiler.new(app, :mode => :cputime)
240
241
  modified_start_env = Rack::MockRequest.env_for('/__start__', :params => 'mode=objects')
241
242
  profile(profiled_app, :start => modified_start_env, :data => :none)
242
-
243
+
243
244
  assert_equal '1', objects
244
245
 
245
246
  profile(profiled_app, :data => :none)
246
-
247
+
247
248
  assert_nil objects
248
249
  end
249
250
 
@@ -256,7 +257,7 @@ class MultipleRequestProfilingTest < Test::Unit::TestCase
256
257
  status, _, body = profiled_app.call(modified_start_env)
257
258
 
258
259
  assert_equal 400, status
259
- assert_match(/Cannot change mode to '#{mode}'.\nPer-request mode changes are only available for the following modes: 'methods', 'objects'/,
260
+ assert_match(/Cannot change mode to '#{mode}'.\nPer-request mode changes are only available for the following modes: 'methods', 'objects'/,
260
261
  RackResponseBody.new(body).to_s)
261
262
  end
262
263
 
@@ -269,7 +270,7 @@ class MultipleRequestProfilingTest < Test::Unit::TestCase
269
270
  status, _, body = profiled_app.call(modified_start_env)
270
271
 
271
272
  assert_equal 400, status
272
- assert_match(/Cannot change mode to '#{mode}'.\nPer-request mode changes are only available for the following modes: 'methods', 'objects'/,
273
+ assert_match(/Cannot change mode to '#{mode}'.\nPer-request mode changes are only available for the following modes: 'methods', 'objects'/,
273
274
  RackResponseBody.new(body).to_s)
274
275
  end
275
276
 
@@ -282,12 +283,12 @@ class MultipleRequestProfilingTest < Test::Unit::TestCase
282
283
  status, _, body = profiled_app.call(modified_start_env)
283
284
 
284
285
  assert_equal 400, status
285
- assert_match(/Cannot change mode to '#{mode}'.\nPer-request mode changes are only available for the following modes: 'methods', 'objects'/,
286
+ assert_match(/Cannot change mode to '#{mode}'.\nPer-request mode changes are only available for the following modes: 'methods', 'objects'/,
286
287
  RackResponseBody.new(body).to_s)
287
288
  end
288
289
 
289
290
  end
290
-
291
+
291
292
  end
292
293
 
293
294
  context 'when profiling is enabled' do
@@ -311,8 +312,8 @@ class MultipleRequestProfilingTest < Test::Unit::TestCase
311
312
  profiled_app = Rack::PerftoolsProfiler.new(app, :default_printer => 'text')
312
313
  profiled_app.call(@start_env)
313
314
  profiled_app.call(env)
314
- # I used to clone the environment to avoid conflicts, but this seems to break
315
- # Devise/Warden.
315
+ # I used to clone the environment to avoid conflicts, but this seems to break
316
+ # Devise/Warden.
316
317
  # assert_equal env, old_env
317
318
  end
318
319
 
@@ -327,8 +328,8 @@ class MultipleRequestProfilingTest < Test::Unit::TestCase
327
328
  profiled_app = Rack::PerftoolsProfiler.new(app, :default_printer => 'text')
328
329
  profiled_app.call(@start_env)
329
330
  profiled_app.call(env)
330
- # I used to clone the environment to avoid conflicts, but this seems to break
331
- # Devise/Warden.
331
+ # I used to clone the environment to avoid conflicts, but this seems to break
332
+ # Devise/Warden.
332
333
  # assert_equal env, old_env
333
334
  end
334
335
 
@@ -353,7 +354,7 @@ class MultipleRequestProfilingTest < Test::Unit::TestCase
353
354
  end
354
355
 
355
356
  end
356
-
357
+
357
358
  should 'keeps data from multiple calls' do
358
359
  profiled_app = Rack::PerftoolsProfiler.with_profiling_off(TestApp.new, :default_printer => 'text', :mode => 'walltime')
359
360
  status, headers, body = profile(profiled_app) do |app|
@@ -364,4 +365,103 @@ class MultipleRequestProfilingTest < Test::Unit::TestCase
364
365
  assert_match(/method2/, RackResponseBody.new(body).to_s)
365
366
  end
366
367
 
368
+ context "when a profile password is required" do
369
+
370
+ should "call app directly on normal calls if password not provided" do
371
+ profiled_app = Rack::PerftoolsProfiler.with_profiling_off(@app, :password => 'secret')
372
+ profiled_app.call(@start_env)
373
+ status, headers, body = profiled_app.call(@root_request_env)
374
+ assert_equal 200, status
375
+ assert_equal 'text/plain', headers['Content-Type']
376
+ assert_equal 'Oh hai der', RackResponseBody.new(body).to_s
377
+ end
378
+
379
+ should "call __start__ if password is provided" do
380
+ profiled_app = Rack::PerftoolsProfiler.new(@app, :password => "secret")
381
+ actual_password = "secret"
382
+ start_env = Rack::MockRequest.env_for('/__start__', :params => "profile=#{actual_password}")
383
+ status, _, body = profiled_app.call(start_env)
384
+ assert_equal 200, status
385
+ assert_match(/Profiling is now enabled/, RackResponseBody.new(body).to_s)
386
+ end
387
+
388
+ should "call __stop__ if password is provided" do
389
+ profiled_app = Rack::PerftoolsProfiler.new(@app, :password => "secret")
390
+ actual_password = "secret"
391
+ stop_env = Rack::MockRequest.env_for('/__stop__', :params => "profile=#{actual_password}")
392
+ status, _, body = profiled_app.call(stop_env)
393
+ assert_equal 200, status
394
+ assert_match(/Profiling is now disabled/, RackResponseBody.new(body).to_s)
395
+ end
396
+
397
+ should "call __data__ if password is provided" do
398
+ profiled_app = Rack::PerftoolsProfiler.new(@app, :password => "secret")
399
+ actual_password = "secret"
400
+ start_env = Rack::MockRequest.env_for('/__start__', :params => "profile=#{actual_password}")
401
+ stop_env = Rack::MockRequest.env_for('/__stop__', :params => "profile=#{actual_password}")
402
+ data_env = Rack::MockRequest.env_for('/__data__', :params => "profile=#{actual_password}")
403
+ profiled_app.call(start_env)
404
+ profiled_app.call(@root_request_env)
405
+ profiled_app.call(stop_env)
406
+ status, _, body = profiled_app.call(data_env)
407
+ assert_equal 200, status
408
+ assert_match(/Total: \d+ samples/, RackResponseBody.new(body).to_s)
409
+ end
410
+
411
+ should "error on __start__ if password does not match" do
412
+ profiled_app = Rack::PerftoolsProfiler.new(@app, :password => "secret")
413
+ actual_password = "foobar"
414
+ start_env = Rack::MockRequest.env_for('/__start__', :params => "profile=#{actual_password}")
415
+ status, _, body = profiled_app.call(start_env)
416
+ assert_equal 401, status
417
+ assert_match(/Profiling is password-protected/, RackResponseBody.new(body).to_s)
418
+ end
419
+
420
+ should "error on __stop__ if password does not match" do
421
+ profiled_app = Rack::PerftoolsProfiler.new(@app, :password => "secret")
422
+ actual_password = "foobar"
423
+ stop_env = Rack::MockRequest.env_for('/__stop__', :params => "profile={actual_password}")
424
+ status, _, body = profiled_app.call(stop_env)
425
+ assert_equal 401, status
426
+ assert_match(/Profiling is password-protected/, RackResponseBody.new(body).to_s)
427
+ end
428
+
429
+ should "error on __data__ if password does not match" do
430
+ profiled_app = Rack::PerftoolsProfiler.new(@app, :password => "secret")
431
+ actual_password = "foobar"
432
+ data_env = Rack::MockRequest.env_for('/__data__', :params => "profile={actual_password}")
433
+ status, _, body = profiled_app.call(data_env)
434
+ assert_equal 401, status
435
+ assert_match(/Profiling is password-protected/, RackResponseBody.new(body).to_s)
436
+ end
437
+
438
+ should "error on __start__ if password is missing" do
439
+ profiled_app = Rack::PerftoolsProfiler.new(@app, :password => "secret")
440
+ actual_password = "foobar"
441
+ start_env = Rack::MockRequest.env_for('/__start__')
442
+ status, _, body = profiled_app.call(start_env)
443
+ assert_equal 401, status
444
+ assert_match(/Profiling is password-protected/, RackResponseBody.new(body).to_s)
445
+ end
446
+
447
+ should "error on __stop__ if password is missing" do
448
+ profiled_app = Rack::PerftoolsProfiler.new(@app, :password => "secret")
449
+ actual_password = "foobar"
450
+ stop_env = Rack::MockRequest.env_for('/__stop__')
451
+ status, _, body = profiled_app.call(stop_env)
452
+ assert_equal 401, status
453
+ assert_match(/Profiling is password-protected/, RackResponseBody.new(body).to_s)
454
+ end
455
+
456
+ should "error on __data__ if password is missing" do
457
+ profiled_app = Rack::PerftoolsProfiler.new(@app, :password => "secret")
458
+ actual_password = "foobar"
459
+ data_env = Rack::MockRequest.env_for('/__data__')
460
+ status, _, body = profiled_app.call(data_env)
461
+ assert_equal 401, status
462
+ assert_match(/Profiling is password-protected/, RackResponseBody.new(body).to_s)
463
+ end
464
+
465
+ end
466
+
367
467
  end
@@ -6,7 +6,7 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
6
6
  def setup
7
7
  @app = lambda { |env| ITERATIONS.times {1+2+3+4+5}; [200, {'Content-Type' => 'text/plain'}, ['Oh hai der']] }
8
8
  @slow_app = lambda { |env| ITERATIONS.times {1+2+3+4+5}; [200, {'Content-Type' => 'text/plain'}, ['slow app']] }
9
- @root_request_env = Rack::MockRequest.env_for("/")
9
+ @root_request_env = Rack::MockRequest.env_for("/")
10
10
  @profiled_request_env = Rack::MockRequest.env_for("/", :params => "profile=true")
11
11
  @profiled_request_env_with_times = Rack::MockRequest.env_for("/", :params => "profile=true&times=2")
12
12
  end
@@ -75,7 +75,8 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
75
75
 
76
76
  should "allow 'printer' param override :default_printer option'" do
77
77
  env = Rack::MockRequest.env_for('/', :params => 'profile=true&printer=gif')
78
- _, headers, _ = Rack::PerftoolsProfiler.new(@app, :default_printer => 'pdf').call(env)
78
+ status, headers, body = Rack::PerftoolsProfiler.new(@app, :default_printer => 'pdf').call(env)
79
+ assert_ok status, body
79
80
  assert_equal 'image/gif', headers['Content-Type']
80
81
  end
81
82
 
@@ -101,7 +102,7 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
101
102
  end
102
103
 
103
104
  context "when in bundler mode" do
104
-
105
+
105
106
  should "call pprof.rb using 'bundle' command if bundler is set" do
106
107
  status = stub_everything(:exitstatus => 0)
107
108
  profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true)
@@ -120,7 +121,7 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
120
121
  Dir.expects(:chdir).with('.').returns(["","",0])
121
122
  profiled_app.call(@profiled_request_env)
122
123
  end
123
-
124
+
124
125
  end
125
126
 
126
127
  context "when the nodecount parameter is specified" do
@@ -178,7 +179,7 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
178
179
  objects = ENV['CPUPROFILE_OBJECTS']
179
180
  [200, {}, ["hi"]]
180
181
  end
181
-
182
+
182
183
  request = Rack::MockRequest.env_for("/", :params => 'profile=true&mode=objects')
183
184
  rack_profiler = Rack::PerftoolsProfiler.new(app, :mode => :cputime)
184
185
  rack_profiler.call(request)
@@ -192,7 +193,7 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
192
193
  request = Rack::MockRequest.env_for("/", :params => "profile=true&mode=#{mode}")
193
194
  status, _, body = profiled_app.call(request)
194
195
  assert_equal 400, status
195
- assert_match(/Cannot change mode to '#{mode}'.\nPer-request mode changes are only available for the following modes: 'methods', 'objects'/,
196
+ assert_match(/Cannot change mode to '#{mode}'.\nPer-request mode changes are only available for the following modes: 'methods', 'objects'/,
196
197
  RackResponseBody.new(body).to_s)
197
198
  end
198
199
 
@@ -202,8 +203,8 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
202
203
  request = Rack::MockRequest.env_for("/", :params => "profile=true&mode=#{mode}")
203
204
  status, _, body = profiled_app.call(request)
204
205
  assert_equal 400, status
205
- assert_match(/Cannot change mode to '#{mode}'.\nPer-request mode changes are only available for the following modes: 'methods', 'objects'/,
206
- RackResponseBody.new(body).to_s)
206
+ assert_match(/Cannot change mode to '#{mode}'.\nPer-request mode changes are only available for the following modes: 'methods', 'objects'/,
207
+ RackResponseBody.new(body).to_s)
207
208
  end
208
209
 
209
210
  should "return error message if mode is 'cputime'" do
@@ -212,8 +213,8 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
212
213
  request = Rack::MockRequest.env_for("/", :params => "profile=true&mode=#{mode}")
213
214
  status, _, body = profiled_app.call(request)
214
215
  assert_equal 400, status
215
- assert_match(/Cannot change mode to '#{mode}'.\nPer-request mode changes are only available for the following modes: 'methods', 'objects'/,
216
- RackResponseBody.new(body).to_s)
216
+ assert_match(/Cannot change mode to '#{mode}'.\nPer-request mode changes are only available for the following modes: 'methods', 'objects'/,
217
+ RackResponseBody.new(body).to_s)
217
218
  end
218
219
 
219
220
  end
@@ -231,7 +232,7 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
231
232
  _, headers, _ = Rack::PerftoolsProfiler.new(@app, :default_printer => 'text').call(@profiled_request_env)
232
233
  assert_equal "text/plain", headers['Content-Type']
233
234
  end
234
-
235
+
235
236
  should 'have Content-Length' do
236
237
  _, headers, _ = Rack::PerftoolsProfiler.new(@slow_app, :default_printer => 'text').call(@profiled_request_env)
237
238
  assert (headers.fetch('Content-Length').to_i > 500)
@@ -242,26 +243,30 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
242
243
  context 'when using the gif printer' do
243
244
 
244
245
  should 'gif printer has Content-Type image/gif' do
245
- _, headers, _ = Rack::PerftoolsProfiler.new(@app, :default_printer => 'gif').call(@profiled_request_env)
246
+ status, headers, body = Rack::PerftoolsProfiler.new(@app, :default_printer => 'gif').call(@profiled_request_env)
247
+ assert_ok status, body
246
248
  assert_equal "image/gif", headers['Content-Type']
247
249
  end
248
250
 
249
251
  should 'gif printer has Content-Length' do
250
- _, headers, _ = Rack::PerftoolsProfiler.new(@slow_app, :default_printer => 'gif').call(@profiled_request_env)
252
+ status, headers, body = Rack::PerftoolsProfiler.new(@slow_app, :default_printer => 'gif').call(@profiled_request_env)
253
+ assert_ok status, body
251
254
  assert headers.fetch('Content-Length').to_i > 25_000
252
255
  end
253
256
 
254
257
  should 'pdf printer has Content-Type application/pdf' do
255
- _, headers, _ = Rack::PerftoolsProfiler.new(@app, :default_printer => 'pdf').call(@profiled_request_env)
258
+ status, headers, body = Rack::PerftoolsProfiler.new(@app, :default_printer => 'pdf').call(@profiled_request_env)
259
+ assert_ok status, body
256
260
  assert_equal "application/pdf", headers['Content-Type']
257
261
  end
258
262
 
259
263
  end
260
-
264
+
261
265
  context 'when using the raw printer' do
262
266
 
263
267
  should 'have default filename' do
264
- _, headers, _ = Rack::PerftoolsProfiler.new(@app, :default_printer => 'raw').call(@profiled_request_env)
268
+ status, headers, body = Rack::PerftoolsProfiler.new(@app, :default_printer => 'raw').call(@profiled_request_env)
269
+ assert_ok status, body
265
270
  assert_equal %q{attachment; filename="profile_data.raw"}, headers['Content-Disposition']
266
271
  end
267
272
 
@@ -282,8 +287,8 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
282
287
  app = @app.clone
283
288
  app.expects(:call).with(expected_env)
284
289
  Rack::PerftoolsProfiler.new(app, :default_printer => 'gif').call(env)
285
- # I used to clone the environment to avoid conflicts, but this seems to break
286
- # Devise/Warden.
290
+ # I used to clone the environment to avoid conflicts, but this seems to break
291
+ # Devise/Warden.
287
292
  # assert_equal env, old_env
288
293
  end
289
294
 
@@ -291,8 +296,8 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
291
296
 
292
297
  should "not return profiling data" do
293
298
  app = @app.clone
294
- env = Rack::MockRequest.env_for('/',
295
- :method => 'post',
299
+ env = Rack::MockRequest.env_for('/',
300
+ :method => 'post',
296
301
  :params => {'profile' => 'true'})
297
302
  status, headers, body = Rack::PerftoolsProfiler.new(app, :default_printer => 'gif').call(env)
298
303
  assert_equal 200, status
@@ -301,12 +306,12 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
301
306
  end
302
307
 
303
308
  should "call underlying app unchanged POST data" do
304
- env = Rack::MockRequest.env_for('/',
309
+ env = Rack::MockRequest.env_for('/',
305
310
  :method => 'post',
306
311
  :params => 'profile=true&times=1&param=value&printer=gif&focus=foo&ignore=bar')
307
312
  app = lambda do |env|
308
313
  request = Rack::Request.new(env)
309
- expected =
314
+ expected =
310
315
  {
311
316
  'profile' => 'true',
312
317
  'times' => '1',
@@ -318,13 +323,25 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
318
323
  assert_equal expected, request.POST
319
324
  [200, {}, ["hi"]]
320
325
  end
321
-
326
+
322
327
  Rack::PerftoolsProfiler.new(app, :default_printer => 'gif').call(env)
323
328
  end
324
329
 
325
330
  end
326
331
 
327
332
  context "when a profile password is required" do
333
+ should "call the app directly when 'profile' is not a request parameter" do
334
+ env = Rack::MockRequest.env_for('/', :params => {})
335
+ app = lambda do |env|
336
+ request = Rack::Request.new(env)
337
+ assert_equal( {}, request.GET)
338
+ [200, {}, ["HI"]]
339
+ end
340
+ status, headers, body = Rack::PerftoolsProfiler.new(app, :default_printer => 'pdf', :password => "secret_password").call(env)
341
+ assert_equal 200, status
342
+ assert_equal ["HI"], body
343
+ end
344
+
328
345
  should "error if password does not match" do
329
346
  app = @app.clone
330
347
  env = Rack::MockRequest.env_for('/', :params => {'profile' => 'true'})
@@ -336,7 +353,8 @@ class SingleRequestProfilingTest < Test::Unit::TestCase
336
353
 
337
354
  should "profile if the parameter matches" do
338
355
  env = Rack::MockRequest.env_for('/', :params => 'profile=secret_password&printer=gif')
339
- _, headers, _ = Rack::PerftoolsProfiler.new(@app, :default_printer => 'pdf', :password => 'secret_password').call(env)
356
+ status, headers, body = Rack::PerftoolsProfiler.new(@app, :default_printer => 'pdf', :password => 'secret_password').call(env)
357
+ assert_ok status, body
340
358
  assert_equal 'image/gif', headers['Content-Type']
341
359
  end
342
360
  end