wested-rack-bug 0.2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/History.txt +0 -0
- data/MIT-LICENSE.txt +19 -0
- data/README.rdoc +29 -0
- data/Rakefile +20 -0
- data/Thorfile +109 -0
- data/VERSION +1 -0
- data/lib/rack/bug.rb +43 -0
- data/lib/rack/bug/options.rb +89 -0
- data/lib/rack/bug/panel.rb +50 -0
- data/lib/rack/bug/panel_app.rb +33 -0
- data/lib/rack/bug/panels/active_record_panel.rb +45 -0
- data/lib/rack/bug/panels/active_record_panel/activerecord_extensions.rb +18 -0
- data/lib/rack/bug/panels/cache_panel.rb +50 -0
- data/lib/rack/bug/panels/cache_panel/memcache_extension.rb +129 -0
- data/lib/rack/bug/panels/cache_panel/panel_app.rb +48 -0
- data/lib/rack/bug/panels/cache_panel/stats.rb +97 -0
- data/lib/rack/bug/panels/log_panel.rb +39 -0
- data/lib/rack/bug/panels/log_panel/rails_extension.rb +11 -0
- data/lib/rack/bug/panels/memory_panel.rb +27 -0
- data/lib/rack/bug/panels/rails_info_panel.rb +23 -0
- data/lib/rack/bug/panels/redis_panel.rb +44 -0
- data/lib/rack/bug/panels/redis_panel/redis_extension.rb +14 -0
- data/lib/rack/bug/panels/redis_panel/stats.rb +48 -0
- data/lib/rack/bug/panels/request_variables_panel.rb +25 -0
- data/lib/rack/bug/panels/sql_panel.rb +55 -0
- data/lib/rack/bug/panels/sql_panel/panel_app.rb +37 -0
- data/lib/rack/bug/panels/sql_panel/query.rb +73 -0
- data/lib/rack/bug/panels/sql_panel/sql_extension.rb +11 -0
- data/lib/rack/bug/panels/templates_panel.rb +44 -0
- data/lib/rack/bug/panels/templates_panel/actionview_extension.rb +12 -0
- data/lib/rack/bug/panels/templates_panel/rendering.rb +67 -0
- data/lib/rack/bug/panels/templates_panel/trace.rb +34 -0
- data/lib/rack/bug/panels/timer_panel.rb +40 -0
- data/lib/rack/bug/params_signature.rb +65 -0
- data/lib/rack/bug/public/__rack_bug__/bookmarklet.html +10 -0
- data/lib/rack/bug/public/__rack_bug__/bookmarklet.js +215 -0
- data/lib/rack/bug/public/__rack_bug__/bug.css +211 -0
- data/lib/rack/bug/public/__rack_bug__/bug.js +84 -0
- data/lib/rack/bug/public/__rack_bug__/jquery-1.3.2.js +4376 -0
- data/lib/rack/bug/public/__rack_bug__/jquery.tablesorter.min.js +1 -0
- data/lib/rack/bug/public/__rack_bug__/spinner.gif +0 -0
- data/lib/rack/bug/render.rb +66 -0
- data/lib/rack/bug/toolbar.rb +137 -0
- data/lib/rack/bug/views/error.html.erb +16 -0
- data/lib/rack/bug/views/panels/active_record.html.erb +17 -0
- data/lib/rack/bug/views/panels/cache.html.erb +93 -0
- data/lib/rack/bug/views/panels/execute_sql.html.erb +32 -0
- data/lib/rack/bug/views/panels/explain_sql.html.erb +32 -0
- data/lib/rack/bug/views/panels/log.html.erb +23 -0
- data/lib/rack/bug/views/panels/profile_sql.html.erb +32 -0
- data/lib/rack/bug/views/panels/rails_info.html.erb +19 -0
- data/lib/rack/bug/views/panels/redis.html.erb +32 -0
- data/lib/rack/bug/views/panels/request_variables.html.erb +107 -0
- data/lib/rack/bug/views/panels/sql.html.erb +43 -0
- data/lib/rack/bug/views/panels/templates.html.erb +7 -0
- data/lib/rack/bug/views/panels/timer.html.erb +19 -0
- data/lib/rack/bug/views/panels/view_cache.html.erb +19 -0
- data/lib/rack/bug/views/redirect.html.erb +16 -0
- data/lib/rack/bug/views/toolbar.html.erb +42 -0
- data/spec/fixtures/config.ru +8 -0
- data/spec/fixtures/dummy_panel.rb +2 -0
- data/spec/fixtures/sample_app.rb +29 -0
- data/spec/rack/bug/panels/active_record_panel_spec.rb +30 -0
- data/spec/rack/bug/panels/cache_panel_spec.rb +159 -0
- data/spec/rack/bug/panels/log_panel_spec.rb +25 -0
- data/spec/rack/bug/panels/memory_panel_spec.rb +21 -0
- data/spec/rack/bug/panels/rails_info_panel_spec.rb +25 -0
- data/spec/rack/bug/panels/redis_panel_spec.rb +57 -0
- data/spec/rack/bug/panels/sql_panel_spec.rb +136 -0
- data/spec/rack/bug/panels/templates_panel_spec.rb +71 -0
- data/spec/rack/bug/panels/timer_panel_spec.rb +38 -0
- data/spec/rack/toolbar_spec.rb +100 -0
- data/spec/rcov.opts +1 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +70 -0
- data/wested-rack-bug.gemspec +127 -0
- metadata +153 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
<h3>Rails Environment</h3>
|
2
|
+
<table>
|
3
|
+
<thead>
|
4
|
+
<tr>
|
5
|
+
<th>Variable</th>
|
6
|
+
<th>Value</th>
|
7
|
+
</tr>
|
8
|
+
</thead>
|
9
|
+
<tbody>
|
10
|
+
<% i = 1 %>
|
11
|
+
<% Rails::Info.properties.each do |key, val| %>
|
12
|
+
<tr class="<%= i % 2 == 0 ? "even" : "odd" %>">
|
13
|
+
<td><%=h key %></td>
|
14
|
+
<td class="code"><div><%=h val %></div></td>
|
15
|
+
</tr>
|
16
|
+
<% i += 1 %>
|
17
|
+
<% end %>
|
18
|
+
</tbody>
|
19
|
+
</table>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<h3>Redis Usage</h3>
|
2
|
+
<table id="redis_usage">
|
3
|
+
<tr>
|
4
|
+
<th>Total Calls</th>
|
5
|
+
<td><%= stats.calls %></td>
|
6
|
+
|
7
|
+
<th>Total Time</th>
|
8
|
+
<td><%= stats.display_time %></td>
|
9
|
+
</tr>
|
10
|
+
</table>
|
11
|
+
|
12
|
+
<% if stats.queries.any? %>
|
13
|
+
<h3>Breakdown</h3>
|
14
|
+
<table id="redis_breakdown">
|
15
|
+
<thead>
|
16
|
+
<tr>
|
17
|
+
<th>Time (ms)</th>
|
18
|
+
<th>Command</th>
|
19
|
+
</tr>
|
20
|
+
</thead>
|
21
|
+
<tbody>
|
22
|
+
<% i = 1 %>
|
23
|
+
<% stats.queries.each do |query| %>
|
24
|
+
<tr class="<%= i % 2 == 0 ? "even" : "odd" %>">
|
25
|
+
<td><%= query.display_time %></td>
|
26
|
+
<td><%= query.command %></td>
|
27
|
+
</tr>
|
28
|
+
<% i += 1 %>
|
29
|
+
<% end %>
|
30
|
+
</tbody>
|
31
|
+
</table>
|
32
|
+
<% end %>
|
@@ -0,0 +1,107 @@
|
|
1
|
+
<% if request.GET.any? %>
|
2
|
+
<h3>GET</h3>
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Variable</th>
|
7
|
+
<th>Value</th>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
<tbody>
|
11
|
+
<% i = 1 %>
|
12
|
+
<% request.GET.sort_by { |k, v| k.to_s }.each do |key, val| %>
|
13
|
+
<tr class="<%= i % 2 == 0 ? "even" : "odd" %>">
|
14
|
+
<td><%=h key %></td>
|
15
|
+
<td class="code"><div><%=h val %></div></td>
|
16
|
+
</tr>
|
17
|
+
<% i += 1 %>
|
18
|
+
<% end %>
|
19
|
+
</tbody>
|
20
|
+
</table>
|
21
|
+
<% end %>
|
22
|
+
|
23
|
+
<% if request.POST.any? %>
|
24
|
+
<h3>POST</h3>
|
25
|
+
<table>
|
26
|
+
<thead>
|
27
|
+
<tr>
|
28
|
+
<th>Variable</th>
|
29
|
+
<th>Value</th>
|
30
|
+
</tr>
|
31
|
+
</thead>
|
32
|
+
<tbody>
|
33
|
+
<% i = 1 %>
|
34
|
+
<% request.POST.sort_by { |k, v| k.to_s }.each do |key, val| %>
|
35
|
+
<tr class="<%= i % 2 == 0 ? "even" : "odd" %>">
|
36
|
+
<td><%=h key %></td>
|
37
|
+
<td class="code"><div><%=h val %></div></td>
|
38
|
+
</tr>
|
39
|
+
<% i += 1 %>
|
40
|
+
<% end %>
|
41
|
+
</tbody>
|
42
|
+
</table>
|
43
|
+
<% end %>
|
44
|
+
|
45
|
+
<% if request.env["rack.session"] && request.env["rack.session"].any? %>
|
46
|
+
<h3>Session</h3>
|
47
|
+
<table>
|
48
|
+
<thead>
|
49
|
+
<tr>
|
50
|
+
<th>Variable</th>
|
51
|
+
<th>Value</th>
|
52
|
+
</tr>
|
53
|
+
</thead>
|
54
|
+
<tbody>
|
55
|
+
<% i = 1 %>
|
56
|
+
<% request.env["rack.session"].sort_by { |k, v| k.to_s }.each do |key, val| %>
|
57
|
+
<tr class="<%= i % 2 == 0 ? "even" : "odd" %>">
|
58
|
+
<td><%=h key %></td>
|
59
|
+
<td class="code"><div><%=h val %></div></td>
|
60
|
+
</tr>
|
61
|
+
<% i += 1 %>
|
62
|
+
<% end %>
|
63
|
+
</tbody>
|
64
|
+
</table>
|
65
|
+
<% end %>
|
66
|
+
|
67
|
+
<% if request.env["rack.request.cookie_hash"] && request.env["rack.request.cookie_hash"].any? %>
|
68
|
+
<h3>Cookies</h3>
|
69
|
+
<table>
|
70
|
+
<thead>
|
71
|
+
<tr>
|
72
|
+
<th>Variable</th>
|
73
|
+
<th>Value</th>
|
74
|
+
</tr>
|
75
|
+
</thead>
|
76
|
+
<tbody>
|
77
|
+
<% i = 1 %>
|
78
|
+
<% request.env["rack.request.cookie_hash"].sort_by { |k, v| k.to_s }.each do |key, val| %>
|
79
|
+
<tr class="<%= i % 2 == 0 ? "even" : "odd" %>">
|
80
|
+
<td><%=h key %></td>
|
81
|
+
<td class="code"><div><%=h val %></div></td>
|
82
|
+
</tr>
|
83
|
+
<% i += 1 %>
|
84
|
+
<% end %>
|
85
|
+
</tbody>
|
86
|
+
</table>
|
87
|
+
<% end %>
|
88
|
+
|
89
|
+
<h3>Rack ENV</h3>
|
90
|
+
<table>
|
91
|
+
<thead>
|
92
|
+
<tr>
|
93
|
+
<th>Variable</th>
|
94
|
+
<th>Value</th>
|
95
|
+
</tr>
|
96
|
+
</thead>
|
97
|
+
<tbody>
|
98
|
+
<% i = 1 %>
|
99
|
+
<% env.sort_by { |k, v| k.to_s }.each do |key, val| %>
|
100
|
+
<tr class="<%= i % 2 == 0 ? "even" : "odd" %>">
|
101
|
+
<td><%=h key %></td>
|
102
|
+
<td class="code"><div><%=h val %></div></td>
|
103
|
+
</tr>
|
104
|
+
<% i += 1 %>
|
105
|
+
<% end %>
|
106
|
+
</tbody>
|
107
|
+
</table>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<h3>SQL Queries</h3>
|
2
|
+
<table class="sortable">
|
3
|
+
<thead>
|
4
|
+
<tr>
|
5
|
+
<th class="time">Time (ms)</th>
|
6
|
+
<th class="query">Query</th>
|
7
|
+
<th class="backtrace"></th>
|
8
|
+
<th class="actions"></th>
|
9
|
+
</tr>
|
10
|
+
</thead>
|
11
|
+
<tbody>
|
12
|
+
<% i = 1 %>
|
13
|
+
<% queries.each do |query| %>
|
14
|
+
<tr class="<%= i % 2 == 0 ? "even" : "odd" %>">
|
15
|
+
<td><%= query.human_time %></td>
|
16
|
+
<td class="syntax"><%= query.sql %></td>
|
17
|
+
<td>
|
18
|
+
<% if query.has_backtrace? %>
|
19
|
+
<a href="#" class="reveal_backtrace">Show Backtrace</a>
|
20
|
+
<% end %>
|
21
|
+
</td>
|
22
|
+
<td>
|
23
|
+
<% if query.inspectable? %>
|
24
|
+
<a href="/__rack_bug__/execute_sql?<%= signed_params("query" => query.sql, "time" => query.time) %>" class="remote_call">SELECT</a> |
|
25
|
+
<a href="/__rack_bug__/explain_sql?<%= signed_params("query" => query.sql, "time" => query.time) %>" class="remote_call">EXPLAIN</a> |
|
26
|
+
<a href="/__rack_bug__/profile_sql?<%= signed_params("query" => query.sql, "time" => query.time) %>" class="remote_call">Profile</a>
|
27
|
+
<% end %>
|
28
|
+
</td>
|
29
|
+
</tr>
|
30
|
+
<tr style="display:none">
|
31
|
+
<td></td>
|
32
|
+
<td colspan="3">
|
33
|
+
<ul>
|
34
|
+
<% query.filtered_backtrace.each do |line| %>
|
35
|
+
<li><%=h line %></li>
|
36
|
+
<% end %>
|
37
|
+
</ul>
|
38
|
+
</td>
|
39
|
+
</tr>
|
40
|
+
<% i += 1 %>
|
41
|
+
<% end %>
|
42
|
+
</tbody>
|
43
|
+
</table>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<h3>Resource Usage</h3>
|
2
|
+
<table class="sortable">
|
3
|
+
<thead>
|
4
|
+
<tr>
|
5
|
+
<th>Key</th>
|
6
|
+
<th>Value</th>
|
7
|
+
</tr>
|
8
|
+
</thead>
|
9
|
+
<tbody>
|
10
|
+
<% i = 1 %>
|
11
|
+
<% measurements.each do |key, val| %>
|
12
|
+
<tr class="<%= i % 2 == 0 ? "even" : "odd" %>">
|
13
|
+
<td><%=h key %></td>
|
14
|
+
<td><%=h val %></td>
|
15
|
+
</tr>
|
16
|
+
<% i += 1 %>
|
17
|
+
<% end %>
|
18
|
+
</tbody>
|
19
|
+
</table>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<a class="back" href="">« Back</a>
|
2
|
+
|
3
|
+
<h3>Cache Read</h3>
|
4
|
+
|
5
|
+
<dl>
|
6
|
+
<dt>Key</dt>
|
7
|
+
<dd><pre><%=h key %></pre></dd>
|
8
|
+
|
9
|
+
<dt>Time</dt>
|
10
|
+
<dd><%=h "%.2f" % (0.0 * 1_000) %>ms</dd>
|
11
|
+
</dl>
|
12
|
+
|
13
|
+
<p>
|
14
|
+
<% if value.is_a?(String )%>
|
15
|
+
<%=h value %>
|
16
|
+
<% else %>
|
17
|
+
<%=h value.inspect %>
|
18
|
+
<% end %>
|
19
|
+
</p>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
</head>
|
4
|
+
<body>
|
5
|
+
<h1>Redirect</h1>
|
6
|
+
|
7
|
+
<p>Location: <a href="<%= redirect_to %>"><%= redirect_to %></a></p>
|
8
|
+
|
9
|
+
<p class="notice">
|
10
|
+
Rack::Bug has intercepted a redirect to the above URL for debug viewing
|
11
|
+
purposes. You can click the above link to continue with the redirect as
|
12
|
+
normal. If you'd like to disable this feature, set the Rack::Bug
|
13
|
+
<code>internal_redirects</code> option to <code>false</code>.
|
14
|
+
</p>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<script type="text/javascript" charset="utf-8">
|
2
|
+
if (typeof jQuery == 'undefined') {
|
3
|
+
var jquery_url = '/__rack_bug__/jquery-1.3.2.js';
|
4
|
+
document.write(unescape('%3Cscript src="' + jquery_url + '" type="text/javascript"%3E%3C/script%3E'));
|
5
|
+
}
|
6
|
+
</script>
|
7
|
+
<script type="text/javascript" src="/__rack_bug__/jquery.tablesorter.min.js"></script>
|
8
|
+
<script type="text/javascript" src="/__rack_bug__/bug.js"></script>
|
9
|
+
<style type="text/css" media="screen">
|
10
|
+
@import url(/__rack_bug__/bug.css);
|
11
|
+
</style>
|
12
|
+
|
13
|
+
<div id="rack_bug" class="rb_top">
|
14
|
+
<div id="rack_bug_toolbar">
|
15
|
+
<ul class="panels">
|
16
|
+
<li id="rb_debug_button">Rack::Bug</li>
|
17
|
+
|
18
|
+
<% panels.each do |panel| %>
|
19
|
+
<li>
|
20
|
+
<% if panel.has_content? %>
|
21
|
+
<a href="#" class="<%= panel.name %>">
|
22
|
+
<%= panel.heading %>
|
23
|
+
</a>
|
24
|
+
<% else %>
|
25
|
+
<%= panel.heading %>
|
26
|
+
<% end %>
|
27
|
+
</li>
|
28
|
+
<% end %>
|
29
|
+
</ul>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
<% panels.each do |panel| %>
|
33
|
+
<% if panel.has_content? %>
|
34
|
+
<div class="panel_content" id="<%= panel.name %>">
|
35
|
+
<a href="" class="rack_bug_close">Close</a>
|
36
|
+
<%= panel.content %>
|
37
|
+
</div>
|
38
|
+
<% end %>
|
39
|
+
<% end %>
|
40
|
+
|
41
|
+
<div id="rack_bug_debug_window" class="panel_content"></div>
|
42
|
+
</div>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "sinatra/base"
|
2
|
+
|
3
|
+
class SampleApp < Sinatra::Default
|
4
|
+
|
5
|
+
get "/redirect" do
|
6
|
+
redirect "/"
|
7
|
+
end
|
8
|
+
|
9
|
+
get "/error" do
|
10
|
+
raise "Error!"
|
11
|
+
end
|
12
|
+
|
13
|
+
get "/" do
|
14
|
+
if params[:content_type]
|
15
|
+
headers["Content-Type"] = params[:content_type]
|
16
|
+
end
|
17
|
+
|
18
|
+
<<-HTML
|
19
|
+
<html>
|
20
|
+
<head>
|
21
|
+
</head>
|
22
|
+
<body>
|
23
|
+
<p>Hello</p>
|
24
|
+
</body>
|
25
|
+
</html>
|
26
|
+
HTML
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
+
|
3
|
+
module Rack::Bug
|
4
|
+
describe ActiveRecordPanel do
|
5
|
+
before do
|
6
|
+
ActiveRecordPanel.reset
|
7
|
+
header "rack-bug.panel_classes", [ActiveRecordPanel]
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "heading" do
|
11
|
+
it "displays the total number of instantiated AR objects" do
|
12
|
+
ActiveRecordPanel.record("User")
|
13
|
+
ActiveRecordPanel.record("Group")
|
14
|
+
response = get "/"
|
15
|
+
response.should have_heading("2 AR Objects")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "content" do
|
20
|
+
it "displays the count of instantiated objects for each class" do
|
21
|
+
ActiveRecordPanel.record("User")
|
22
|
+
ActiveRecordPanel.record("User")
|
23
|
+
ActiveRecordPanel.record("Group")
|
24
|
+
response = get "/"
|
25
|
+
response.should have_row("#active_record", "User", "2")
|
26
|
+
response.should have_row("#active_record", "Group", "1")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
+
|
3
|
+
module Rack::Bug
|
4
|
+
describe CachePanel do
|
5
|
+
before do
|
6
|
+
CachePanel.reset
|
7
|
+
header "rack-bug.panel_classes", [CachePanel]
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "heading" do
|
11
|
+
it "displays the total memcache time" do
|
12
|
+
response = get "/"
|
13
|
+
response.should have_heading("Cache: 0.00ms")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "content" do
|
18
|
+
describe "usage table" do
|
19
|
+
it "displays the total number of memcache calls" do
|
20
|
+
CachePanel.record(:get, "user:1") { }
|
21
|
+
response = get "/"
|
22
|
+
|
23
|
+
# This causes a bus error:
|
24
|
+
# response.should have_selector("th:content('Total Calls') + td", :content => "1")
|
25
|
+
|
26
|
+
response.should have_row("#cache_usage", "Total Calls", "1")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "displays the total memcache time" do
|
30
|
+
response = get "/"
|
31
|
+
response.should have_row("#cache_usage", "Total Time", "0.00ms")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "dispays the number of memcache hits" do
|
35
|
+
CachePanel.record(:get, "user:1") { }
|
36
|
+
response = get "/"
|
37
|
+
response.should have_row("#cache_usage", "Hits", "0")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "displays the number of memcache misses" do
|
41
|
+
CachePanel.record(:get, "user:1") { }
|
42
|
+
response = get "/"
|
43
|
+
response.should have_row("#cache_usage", "Misses", "1")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "displays the number of memcache gets" do
|
47
|
+
CachePanel.record(:get, "user:1") { }
|
48
|
+
response = get "/"
|
49
|
+
response.should have_row("#cache_usage", "gets", "1")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "displays the number of memcache sets" do
|
53
|
+
CachePanel.record(:set, "user:1") { }
|
54
|
+
response = get "/"
|
55
|
+
response.should have_row("#cache_usage", "sets", "1")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "displays the number of memcache deletes" do
|
59
|
+
CachePanel.record(:delete, "user:1") { }
|
60
|
+
response = get "/"
|
61
|
+
response.should have_row("#cache_usage", "deletes", "1")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "displays the number of memcache get_multis" do
|
65
|
+
CachePanel.record(:get_multi, "user:1", "user:2") { }
|
66
|
+
response = get "/"
|
67
|
+
response.should have_row("#cache_usage", "get_multis", "1")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "breakdown" do
|
72
|
+
it "displays each memcache operation" do
|
73
|
+
CachePanel.record(:get, "user:1") { }
|
74
|
+
response = get "/"
|
75
|
+
response.should have_row("#cache_breakdown", "get")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "displays the time for each memcache call" do
|
79
|
+
CachePanel.record(:get, "user:1") { }
|
80
|
+
response = get "/"
|
81
|
+
response.should have_row("#cache_breakdown", "user:1", TIME_MS_REGEXP)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "displays the keys for each memcache call" do
|
85
|
+
CachePanel.record(:get, "user:1") { }
|
86
|
+
response = get "/"
|
87
|
+
response.should have_row("#cache_breakdown", "user:1", "get")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "expire_all" do
|
93
|
+
before do
|
94
|
+
header "rack-bug.secret_key", 'abc'
|
95
|
+
end
|
96
|
+
|
97
|
+
it "expires the cache keys" do
|
98
|
+
Rails.stub!(:cache => mock("cache"))
|
99
|
+
Rails.cache.should_receive(:delete).with("user:1")
|
100
|
+
Rails.cache.should_receive(:delete).with("user:2")
|
101
|
+
Rails.cache.should_receive(:delete).with("user:3")
|
102
|
+
Rails.cache.should_receive(:delete).with("user:4")
|
103
|
+
|
104
|
+
get "/__rack_bug__/delete_cache_list",
|
105
|
+
:keys_1 => "user:1", :keys_2 => "user:2", :keys_3 => "user:3", :keys_4 => "user:4",
|
106
|
+
:hash => "c367b76e0199c308862a3afd8fba32b8715e7976"
|
107
|
+
end
|
108
|
+
|
109
|
+
it "returns OK" do
|
110
|
+
Rails.stub!(:cache => mock("cache", :delete => nil))
|
111
|
+
response = get "/__rack_bug__/delete_cache_list",
|
112
|
+
:keys_1 => "user:1", :keys_2 => "user:2", :keys_3 => "user:3", :keys_4 => "user:4",
|
113
|
+
:hash => "c367b76e0199c308862a3afd8fba32b8715e7976"
|
114
|
+
response.should contain("OK")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "expire" do
|
119
|
+
before do
|
120
|
+
header "rack-bug.secret_key", 'abc'
|
121
|
+
end
|
122
|
+
|
123
|
+
it "expires the cache key" do
|
124
|
+
Rails.stub!(:cache => mock("cache"))
|
125
|
+
Rails.cache.should_receive(:delete).with("user:1")
|
126
|
+
get "/__rack_bug__/delete_cache", :key => "user:1",
|
127
|
+
:hash => "f87215442d312d8e42cf51e6b66fc3eb3d59ac74"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "returns OK" do
|
131
|
+
Rails.stub!(:cache => mock("cache", :delete => nil))
|
132
|
+
response = get "/__rack_bug__/delete_cache", :key => "user:1",
|
133
|
+
:hash => "f87215442d312d8e42cf51e6b66fc3eb3d59ac74"
|
134
|
+
response.should contain("OK")
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "view_cache" do
|
139
|
+
before do
|
140
|
+
header "rack-bug.secret_key", 'abc'
|
141
|
+
end
|
142
|
+
|
143
|
+
it "renders the cache key" do
|
144
|
+
Rails.stub!(:cache => mock("cache", :read => "cache body"))
|
145
|
+
response = get "/__rack_bug__/view_cache", :key => "user:1",
|
146
|
+
:hash => "f87215442d312d8e42cf51e6b66fc3eb3d59ac74"
|
147
|
+
response.should contain("cache body")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "renders non-String cache values properly" do
|
151
|
+
Rails.stub!(:cache => mock("cache", :read => [1, 2]))
|
152
|
+
response = get "/__rack_bug__/view_cache", :key => "user:1",
|
153
|
+
:hash => "f87215442d312d8e42cf51e6b66fc3eb3d59ac74"
|
154
|
+
response.should contain("[1, 2]")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
end
|