rack-bug 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.gitignore +3 -0
  2. data/History.txt +0 -0
  3. data/MIT-LICENSE.txt +19 -0
  4. data/README.rdoc +29 -0
  5. data/Rakefile +36 -0
  6. data/VERSION +1 -0
  7. data/lib/rack/bug.rb +43 -0
  8. data/lib/rack/bug/options.rb +89 -0
  9. data/lib/rack/bug/panel.rb +50 -0
  10. data/lib/rack/bug/panel_app.rb +33 -0
  11. data/lib/rack/bug/panels/active_record_panel.rb +45 -0
  12. data/lib/rack/bug/panels/active_record_panel/activerecord_extensions.rb +18 -0
  13. data/lib/rack/bug/panels/cache_panel.rb +50 -0
  14. data/lib/rack/bug/panels/cache_panel/memcache_extension.rb +129 -0
  15. data/lib/rack/bug/panels/cache_panel/panel_app.rb +48 -0
  16. data/lib/rack/bug/panels/cache_panel/stats.rb +97 -0
  17. data/lib/rack/bug/panels/log_panel.rb +39 -0
  18. data/lib/rack/bug/panels/log_panel/rails_extension.rb +11 -0
  19. data/lib/rack/bug/panels/memory_panel.rb +27 -0
  20. data/lib/rack/bug/panels/rails_info_panel.rb +23 -0
  21. data/lib/rack/bug/panels/redis_panel.rb +44 -0
  22. data/lib/rack/bug/panels/redis_panel/redis_extension.rb +14 -0
  23. data/lib/rack/bug/panels/redis_panel/stats.rb +48 -0
  24. data/lib/rack/bug/panels/request_variables_panel.rb +25 -0
  25. data/lib/rack/bug/panels/sql_panel.rb +55 -0
  26. data/lib/rack/bug/panels/sql_panel/panel_app.rb +37 -0
  27. data/lib/rack/bug/panels/sql_panel/query.rb +73 -0
  28. data/lib/rack/bug/panels/sql_panel/sql_extension.rb +11 -0
  29. data/lib/rack/bug/panels/templates_panel.rb +44 -0
  30. data/lib/rack/bug/panels/templates_panel/actionview_extension.rb +12 -0
  31. data/lib/rack/bug/panels/templates_panel/rendering.rb +67 -0
  32. data/lib/rack/bug/panels/templates_panel/trace.rb +34 -0
  33. data/lib/rack/bug/panels/timer_panel.rb +40 -0
  34. data/lib/rack/bug/params_signature.rb +65 -0
  35. data/lib/rack/bug/public/__rack_bug__/bookmarklet.html +10 -0
  36. data/lib/rack/bug/public/__rack_bug__/bookmarklet.js +215 -0
  37. data/lib/rack/bug/public/__rack_bug__/bug.css +211 -0
  38. data/lib/rack/bug/public/__rack_bug__/bug.js +84 -0
  39. data/lib/rack/bug/public/__rack_bug__/jquery-1.3.2.js +4376 -0
  40. data/lib/rack/bug/public/__rack_bug__/jquery.tablesorter.min.js +1 -0
  41. data/lib/rack/bug/public/__rack_bug__/spinner.gif +0 -0
  42. data/lib/rack/bug/render.rb +66 -0
  43. data/lib/rack/bug/toolbar.rb +137 -0
  44. data/lib/rack/bug/views/error.html.erb +16 -0
  45. data/lib/rack/bug/views/panels/active_record.html.erb +17 -0
  46. data/lib/rack/bug/views/panels/cache.html.erb +93 -0
  47. data/lib/rack/bug/views/panels/execute_sql.html.erb +32 -0
  48. data/lib/rack/bug/views/panels/explain_sql.html.erb +32 -0
  49. data/lib/rack/bug/views/panels/log.html.erb +23 -0
  50. data/lib/rack/bug/views/panels/profile_sql.html.erb +32 -0
  51. data/lib/rack/bug/views/panels/rails_info.html.erb +19 -0
  52. data/lib/rack/bug/views/panels/redis.html.erb +32 -0
  53. data/lib/rack/bug/views/panels/request_variables.html.erb +107 -0
  54. data/lib/rack/bug/views/panels/sql.html.erb +43 -0
  55. data/lib/rack/bug/views/panels/templates.html.erb +7 -0
  56. data/lib/rack/bug/views/panels/timer.html.erb +19 -0
  57. data/lib/rack/bug/views/panels/view_cache.html.erb +19 -0
  58. data/lib/rack/bug/views/redirect.html.erb +16 -0
  59. data/lib/rack/bug/views/toolbar.html.erb +42 -0
  60. data/rack-bug.gemspec +126 -0
  61. data/spec/fixtures/config.ru +8 -0
  62. data/spec/fixtures/dummy_panel.rb +2 -0
  63. data/spec/fixtures/sample_app.rb +29 -0
  64. data/spec/rack/bug/panels/active_record_panel_spec.rb +30 -0
  65. data/spec/rack/bug/panels/cache_panel_spec.rb +159 -0
  66. data/spec/rack/bug/panels/log_panel_spec.rb +25 -0
  67. data/spec/rack/bug/panels/memory_panel_spec.rb +21 -0
  68. data/spec/rack/bug/panels/rails_info_panel_spec.rb +25 -0
  69. data/spec/rack/bug/panels/redis_panel_spec.rb +57 -0
  70. data/spec/rack/bug/panels/sql_panel_spec.rb +136 -0
  71. data/spec/rack/bug/panels/templates_panel_spec.rb +71 -0
  72. data/spec/rack/bug/panels/timer_panel_spec.rb +38 -0
  73. data/spec/rack/toolbar_spec.rb +100 -0
  74. data/spec/rcov.opts +1 -0
  75. data/spec/spec.opts +1 -0
  76. data/spec/spec_helper.rb +70 -0
  77. metadata +143 -0
@@ -0,0 +1,71 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ module Rack::Bug
4
+ describe TemplatesPanel do
5
+ before do
6
+ TemplatesPanel.reset
7
+ header "rack-bug.panel_classes", [TemplatesPanel]
8
+ end
9
+
10
+ describe "heading" do
11
+ it "displays the total rendering time" do
12
+ response = get "/"
13
+ response.should have_heading("Templates: 0.00ms")
14
+ end
15
+ end
16
+
17
+ describe "content" do
18
+ it "displays the template paths" do
19
+ TemplatesPanel.record("users/show") { }
20
+ response = get "/"
21
+ response.should contain("users/show")
22
+ end
23
+
24
+ it "displays the template children" do
25
+ TemplatesPanel.record("users/show") do
26
+ TemplatesPanel.record("users/toolbar") { }
27
+ end
28
+
29
+ response = get "/"
30
+ response.should have_selector("li", :content => "users/show") do |li|
31
+ li.should contain("users/toolbar")
32
+ end
33
+ end
34
+
35
+ context "for templates that rendered templates" do
36
+ it "displays the total time" do
37
+ TemplatesPanel.record("users/show") do
38
+ TemplatesPanel.record("users/toolbar") { }
39
+ end
40
+
41
+ response = get "/"
42
+ response.should have_selector("li", :content => "users/show") do |li|
43
+ li.should contain(TIME_MS_REGEXP)
44
+ end
45
+ end
46
+
47
+ it "displays the exclusive time" do
48
+ TemplatesPanel.record("users/show") do
49
+ TemplatesPanel.record("users/toolbar") { }
50
+ end
51
+
52
+ response = get "/"
53
+ response.should have_selector("li", :content => "users/show") do |li|
54
+ li.should contain(/\d\.\d{2} exclusive/)
55
+ end
56
+ end
57
+ end
58
+
59
+ context "for leaf templates" do
60
+ it "does not display the exclusive time" do
61
+ TemplatesPanel.record("users/show") { }
62
+
63
+ response = get "/"
64
+ response.should contain("users/show") do |li|
65
+ li.should_not contain("exclusive")
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ module Rack::Bug
4
+ describe TimerPanel do
5
+ before do
6
+ header "rack-bug.panel_classes", [TimerPanel]
7
+ end
8
+
9
+ describe "heading" do
10
+ it "displays the elapsed time" do
11
+ response = get "/"
12
+ response.should have_heading(TIME_MS_REGEXP)
13
+ end
14
+ end
15
+
16
+ describe "content" do
17
+ it "displays the user CPU time" do
18
+ response = get "/"
19
+ response.should have_row("#timer", "User CPU time", TIME_MS_REGEXP)
20
+ end
21
+
22
+ it "displays the system CPU time" do
23
+ response = get "/"
24
+ response.should have_row("#timer", "System CPU time", TIME_MS_REGEXP)
25
+ end
26
+
27
+ it "displays the total CPU time" do
28
+ response = get "/"
29
+ response.should have_row("#timer", "Total CPU time", TIME_MS_REGEXP)
30
+ end
31
+
32
+ it "displays the elapsed time" do
33
+ response = get "/"
34
+ response.should have_row("#timer", "Elapsed time", TIME_MS_REGEXP)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,100 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Rack::Bug do
4
+ it "inserts the Rack::Bug toolbar" do
5
+ response = get "/"
6
+ response.should have_selector("div#rack_bug")
7
+ end
8
+
9
+ it "updates the Content-Length" do
10
+ response = get "/"
11
+ response["Content-Length"].should == response.body.size.to_s
12
+ end
13
+
14
+ it "serves the Rack::Bug assets under /__rack_bug__/" do
15
+ response = get "/__rack_bug__/bug.css"
16
+ response.should be_ok
17
+ end
18
+
19
+ it "modifies HTML responses with a charset" do
20
+ response = get "/", :content_type => "application/xhtml+xml; charset=utf-8"
21
+ response.should have_selector("div#rack_bug")
22
+ end
23
+
24
+ it "does not modify XMLHttpRequest responses" do
25
+ response = get "/", {}, { :xhr => true }
26
+ response.should_not have_selector("div#rack_bug")
27
+ end
28
+
29
+ it "modifies XHTML responses" do
30
+ response = get "/", :content_type => "application/xhtml+xml"
31
+ response.should have_selector("div#rack_bug")
32
+ end
33
+
34
+ it "does not modify non-HTML responses" do
35
+ response = get "/", :content_type => "text/csv"
36
+ response.should_not have_selector("div#rack_bug")
37
+ end
38
+
39
+ it "does not modify redirects" do
40
+ response = get "/redirect"
41
+ response.body.should == ""
42
+ end
43
+
44
+ it "does not modify server errors" do
45
+ response = get "/error"
46
+ response.should_not have_selector("div#rack_bug")
47
+ end
48
+
49
+ context "configured to intercept redirects" do
50
+ it "inserts the Rack::Bug toolbar for redirects" do
51
+ response = get "/redirect", {}, "rack-bug.intercept_redirects" => true
52
+ response.should contain("Location: /")
53
+ end
54
+ end
55
+
56
+ context "configured with an IP address restriction" do
57
+ before do
58
+ header "rack-bug.ip_masks", [IPAddr.new("127.0.0.1/255.255.255.0")]
59
+ end
60
+
61
+ it "inserts the Rack::Bug toolbar when the IP matches" do
62
+ response = get "/", {}, "REMOTE_ADDR" => "127.0.0.2"
63
+ response.should have_selector("div#rack_bug")
64
+ end
65
+
66
+ it "is disabled when the IP doesn't match" do
67
+ response = get "/", {}, "REMOTE_ADDR" => "128.0.0.1"
68
+ response.should_not have_selector("div#rack_bug")
69
+ end
70
+
71
+ it "doesn't use any panels" do
72
+ DummyPanel.should_not_receive(:new)
73
+ header "rack-bug.panel_classes", [DummyPanel]
74
+ get "/", {}, "REMOTE_ADDR" => "128.0.0.1"
75
+ end
76
+ end
77
+
78
+ context "configured with a password" do
79
+ before do
80
+ header "rack-bug.password", "secret"
81
+ end
82
+
83
+ it "inserts the Rack::Bug toolbar when the password matches" do
84
+ sha = "545049d1c5e2a6e0dfefd37f9a9e0beb95241935"
85
+ response = get "/", {}, :cookie => ["rack_bug_enabled=1", "rack_bug_password=#{sha}"]
86
+ response.should have_selector("div#rack_bug")
87
+ end
88
+
89
+ it "is disabled when the password doesn't match" do
90
+ response = get "/"
91
+ response.should_not have_selector("div#rack_bug")
92
+ end
93
+
94
+ it "doesn't use any panels" do
95
+ DummyPanel.should_not_receive(:new)
96
+ header "rack-bug.panel_classes", [DummyPanel]
97
+ get "/"
98
+ end
99
+ end
100
+ end
@@ -0,0 +1 @@
1
+ -x gems,spec\/
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,70 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ require "webrat"
4
+ require "rack/test"
5
+
6
+ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__)) + '/lib'
7
+ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))
8
+
9
+ require "rack/bug"
10
+ require "spec/fixtures/sample_app"
11
+ require "spec/fixtures/dummy_panel"
12
+
13
+ module Rails
14
+ def self.version
15
+ ""
16
+ end
17
+
18
+ class Info
19
+ def self.properties
20
+ []
21
+ end
22
+ end
23
+ end
24
+
25
+ module ActiveRecord
26
+ class Base
27
+ end
28
+ end
29
+
30
+ Spec::Runner.configure do |config|
31
+ TIME_MS_REGEXP = /\d+\.\d{2}ms/
32
+
33
+ config.include Rack::Test::Methods
34
+ config.include Webrat::Matchers
35
+
36
+ config.before do
37
+ # This allows specs to record data outside the request
38
+ Rack::Bug.enable
39
+
40
+ # Set the cookie that triggers Rack::Bug under normal conditions
41
+ header :cookie, "rack_bug_enabled=1"
42
+ end
43
+
44
+ def app
45
+ Rack::Builder.new do
46
+ use Rack::Bug
47
+ run SampleApp.new
48
+ end
49
+ end
50
+
51
+ def have_row(container, key, value = nil)
52
+ simple_matcher("contain row") do |response|
53
+ if value
54
+ response.should have_selector("#{container} tr", :content => key) do |row|
55
+ row.should contain(value)
56
+ end
57
+ else
58
+ response.should have_selector("#{container} tr", :content => key)
59
+ end
60
+ end
61
+ end
62
+
63
+ def have_heading(text)
64
+ simple_matcher("have heading") do |response|
65
+ response.should have_selector("#rack_bug_toolbar li") do |heading|
66
+ heading.should contain(text)
67
+ end
68
+ end
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-bug
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Bryan Helmkamp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-06 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: bryan@brynary.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - MIT-LICENSE.txt
24
+ - README.rdoc
25
+ files:
26
+ - .gitignore
27
+ - History.txt
28
+ - MIT-LICENSE.txt
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/rack/bug.rb
33
+ - lib/rack/bug/options.rb
34
+ - lib/rack/bug/panel.rb
35
+ - lib/rack/bug/panel_app.rb
36
+ - lib/rack/bug/panels/active_record_panel.rb
37
+ - lib/rack/bug/panels/active_record_panel/activerecord_extensions.rb
38
+ - lib/rack/bug/panels/cache_panel.rb
39
+ - lib/rack/bug/panels/cache_panel/memcache_extension.rb
40
+ - lib/rack/bug/panels/cache_panel/panel_app.rb
41
+ - lib/rack/bug/panels/cache_panel/stats.rb
42
+ - lib/rack/bug/panels/log_panel.rb
43
+ - lib/rack/bug/panels/log_panel/rails_extension.rb
44
+ - lib/rack/bug/panels/memory_panel.rb
45
+ - lib/rack/bug/panels/rails_info_panel.rb
46
+ - lib/rack/bug/panels/redis_panel.rb
47
+ - lib/rack/bug/panels/redis_panel/redis_extension.rb
48
+ - lib/rack/bug/panels/redis_panel/stats.rb
49
+ - lib/rack/bug/panels/request_variables_panel.rb
50
+ - lib/rack/bug/panels/sql_panel.rb
51
+ - lib/rack/bug/panels/sql_panel/panel_app.rb
52
+ - lib/rack/bug/panels/sql_panel/query.rb
53
+ - lib/rack/bug/panels/sql_panel/sql_extension.rb
54
+ - lib/rack/bug/panels/templates_panel.rb
55
+ - lib/rack/bug/panels/templates_panel/actionview_extension.rb
56
+ - lib/rack/bug/panels/templates_panel/rendering.rb
57
+ - lib/rack/bug/panels/templates_panel/trace.rb
58
+ - lib/rack/bug/panels/timer_panel.rb
59
+ - lib/rack/bug/params_signature.rb
60
+ - lib/rack/bug/public/__rack_bug__/bookmarklet.html
61
+ - lib/rack/bug/public/__rack_bug__/bookmarklet.js
62
+ - lib/rack/bug/public/__rack_bug__/bug.css
63
+ - lib/rack/bug/public/__rack_bug__/bug.js
64
+ - lib/rack/bug/public/__rack_bug__/jquery-1.3.2.js
65
+ - lib/rack/bug/public/__rack_bug__/jquery.tablesorter.min.js
66
+ - lib/rack/bug/public/__rack_bug__/spinner.gif
67
+ - lib/rack/bug/render.rb
68
+ - lib/rack/bug/toolbar.rb
69
+ - lib/rack/bug/views/error.html.erb
70
+ - lib/rack/bug/views/panels/active_record.html.erb
71
+ - lib/rack/bug/views/panels/cache.html.erb
72
+ - lib/rack/bug/views/panels/execute_sql.html.erb
73
+ - lib/rack/bug/views/panels/explain_sql.html.erb
74
+ - lib/rack/bug/views/panels/log.html.erb
75
+ - lib/rack/bug/views/panels/profile_sql.html.erb
76
+ - lib/rack/bug/views/panels/rails_info.html.erb
77
+ - lib/rack/bug/views/panels/redis.html.erb
78
+ - lib/rack/bug/views/panels/request_variables.html.erb
79
+ - lib/rack/bug/views/panels/sql.html.erb
80
+ - lib/rack/bug/views/panels/templates.html.erb
81
+ - lib/rack/bug/views/panels/timer.html.erb
82
+ - lib/rack/bug/views/panels/view_cache.html.erb
83
+ - lib/rack/bug/views/redirect.html.erb
84
+ - lib/rack/bug/views/toolbar.html.erb
85
+ - rack-bug.gemspec
86
+ - spec/fixtures/config.ru
87
+ - spec/fixtures/dummy_panel.rb
88
+ - spec/fixtures/sample_app.rb
89
+ - spec/rack/bug/panels/active_record_panel_spec.rb
90
+ - spec/rack/bug/panels/cache_panel_spec.rb
91
+ - spec/rack/bug/panels/log_panel_spec.rb
92
+ - spec/rack/bug/panels/memory_panel_spec.rb
93
+ - spec/rack/bug/panels/rails_info_panel_spec.rb
94
+ - spec/rack/bug/panels/redis_panel_spec.rb
95
+ - spec/rack/bug/panels/sql_panel_spec.rb
96
+ - spec/rack/bug/panels/templates_panel_spec.rb
97
+ - spec/rack/bug/panels/timer_panel_spec.rb
98
+ - spec/rack/toolbar_spec.rb
99
+ - spec/rcov.opts
100
+ - spec/spec.opts
101
+ - spec/spec_helper.rb
102
+ has_rdoc: true
103
+ homepage: http://github.com/brynary/rack-bug
104
+ licenses: []
105
+
106
+ post_install_message:
107
+ rdoc_options:
108
+ - --charset=UTF-8
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: "0"
116
+ version:
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: "0"
122
+ version:
123
+ requirements: []
124
+
125
+ rubyforge_project:
126
+ rubygems_version: 1.3.5
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: Debugging toolbar for Rack applications implemented as middleware
130
+ test_files:
131
+ - spec/fixtures/dummy_panel.rb
132
+ - spec/fixtures/sample_app.rb
133
+ - spec/rack/bug/panels/active_record_panel_spec.rb
134
+ - spec/rack/bug/panels/cache_panel_spec.rb
135
+ - spec/rack/bug/panels/log_panel_spec.rb
136
+ - spec/rack/bug/panels/memory_panel_spec.rb
137
+ - spec/rack/bug/panels/rails_info_panel_spec.rb
138
+ - spec/rack/bug/panels/redis_panel_spec.rb
139
+ - spec/rack/bug/panels/sql_panel_spec.rb
140
+ - spec/rack/bug/panels/templates_panel_spec.rb
141
+ - spec/rack/bug/panels/timer_panel_spec.rb
142
+ - spec/rack/toolbar_spec.rb
143
+ - spec/spec_helper.rb