diagnostics 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/.gitignore +4 -4
  2. data/.specification +0 -0
  3. data/Gemfile.lock +39 -0
  4. data/LICENSE +20 -0
  5. data/README.md +7 -0
  6. data/app/controllers/diagnostics_application_controller.rb +12 -0
  7. data/app/controllers/diagnostics_controller.rb +6 -0
  8. data/app/controllers/statuses_controller.rb +20 -0
  9. data/app/views/diagnostics/_check.html.erb +1 -0
  10. data/app/views/diagnostics/index.html.erb +22 -0
  11. data/app/views/layouts/diagnostics.html.erb +114 -0
  12. data/app/views/statuses/show.html.erb +15 -0
  13. data/config/routes.rb +6 -0
  14. data/diagnostics.gemspec +2 -2
  15. data/features/diagnostic_checks.feature +167 -0
  16. data/features/step_definitions/aruba.rb +5 -0
  17. data/features/support/env.rb +2 -0
  18. data/lib/diagnostics/check.rb +66 -0
  19. data/lib/diagnostics/data/attribute.rb +15 -0
  20. data/lib/diagnostics/data/elements.rb +40 -0
  21. data/lib/diagnostics/data/list.rb +15 -0
  22. data/lib/diagnostics/data/table.rb +47 -0
  23. data/lib/diagnostics/data/text.rb +15 -0
  24. data/lib/diagnostics/data_group.rb +37 -0
  25. data/lib/diagnostics/methods.rb +46 -0
  26. data/lib/diagnostics/version.rb +1 -1
  27. data/rails/init.rb +1 -0
  28. data/spec/diagnostics/check_spec.rb +78 -0
  29. data/spec/diagnostics/data/attribute_spec.rb +22 -0
  30. data/spec/diagnostics/data/list_spec.rb +22 -0
  31. data/spec/diagnostics/data/table_spec.rb +63 -0
  32. data/spec/diagnostics/data/text_spec.rb +22 -0
  33. data/spec/diagnostics/data_group_spec.rb +177 -0
  34. data/spec/diagnostics/methods_spec.rb +128 -0
  35. data/spec/diagnostics_spec.rb +11 -0
  36. data/spec/spec_helper.rb +13 -0
  37. data/spec_rails/rails2/Gemfile +13 -0
  38. data/spec_rails/rails2/Gemfile.lock +91 -0
  39. data/spec_rails/rails2/Rakefile +13 -0
  40. data/spec_rails/rails2/app_root/README +243 -0
  41. data/spec_rails/rails2/app_root/Rakefile +10 -0
  42. data/spec_rails/rails2/app_root/app/controllers/application_controller.rb +10 -0
  43. data/spec_rails/rails2/app_root/app/helpers/application_helper.rb +3 -0
  44. data/spec_rails/rails2/app_root/config/boot.rb +114 -0
  45. data/spec_rails/rails2/app_root/config/database.yml +25 -0
  46. data/spec_rails/rails2/app_root/config/environment.rb +45 -0
  47. data/spec_rails/rails2/app_root/config/environments/cucumber.rb +29 -0
  48. data/spec_rails/rails2/app_root/config/environments/development.rb +17 -0
  49. data/spec_rails/rails2/app_root/config/environments/production.rb +28 -0
  50. data/spec_rails/rails2/app_root/config/environments/test.rb +28 -0
  51. data/spec_rails/rails2/app_root/config/initializers/backtrace_silencers.rb +7 -0
  52. data/spec_rails/rails2/app_root/config/initializers/cookie_verification_secret.rb +7 -0
  53. data/spec_rails/rails2/app_root/config/initializers/inflections.rb +10 -0
  54. data/spec_rails/rails2/app_root/config/initializers/load_diagnostics.rb +2 -0
  55. data/spec_rails/rails2/app_root/config/initializers/mime_types.rb +5 -0
  56. data/spec_rails/rails2/app_root/config/initializers/new_rails_defaults.rb +21 -0
  57. data/spec_rails/rails2/app_root/config/initializers/session_store.rb +15 -0
  58. data/spec_rails/rails2/app_root/config/locales/en.yml +5 -0
  59. data/spec_rails/rails2/app_root/config/routes.rb +43 -0
  60. data/spec_rails/rails2/app_root/db/seeds.rb +7 -0
  61. data/spec_rails/rails2/app_root/doc/README_FOR_APP +2 -0
  62. data/spec_rails/rails2/app_root/lib/diagnostics/mysql_check.rb +18 -0
  63. data/spec_rails/rails2/app_root/lib/diagnostics/server_check.rb +4 -0
  64. data/spec_rails/rails2/app_root/lib/tasks/cucumber.rake +53 -0
  65. data/spec_rails/rails2/app_root/public/404.html +30 -0
  66. data/spec_rails/rails2/app_root/public/422.html +30 -0
  67. data/spec_rails/rails2/app_root/public/500.html +30 -0
  68. data/spec_rails/rails2/app_root/public/favicon.ico +0 -0
  69. data/spec_rails/rails2/app_root/public/images/rails.png +0 -0
  70. data/spec_rails/rails2/app_root/public/index.html +275 -0
  71. data/spec_rails/rails2/app_root/public/javascripts/application.js +2 -0
  72. data/spec_rails/rails2/app_root/public/javascripts/controls.js +963 -0
  73. data/spec_rails/rails2/app_root/public/javascripts/dragdrop.js +973 -0
  74. data/spec_rails/rails2/app_root/public/javascripts/effects.js +1128 -0
  75. data/spec_rails/rails2/app_root/public/javascripts/prototype.js +4320 -0
  76. data/spec_rails/rails2/app_root/public/robots.txt +5 -0
  77. data/spec_rails/rails2/app_root/script/about +4 -0
  78. data/spec_rails/rails2/app_root/script/console +3 -0
  79. data/spec_rails/rails2/app_root/script/cucumber +10 -0
  80. data/spec_rails/rails2/app_root/script/dbconsole +3 -0
  81. data/spec_rails/rails2/app_root/script/destroy +3 -0
  82. data/spec_rails/rails2/app_root/script/generate +3 -0
  83. data/spec_rails/rails2/app_root/script/performance/benchmarker +3 -0
  84. data/spec_rails/rails2/app_root/script/performance/profiler +3 -0
  85. data/spec_rails/rails2/app_root/script/plugin +3 -0
  86. data/spec_rails/rails2/app_root/script/runner +3 -0
  87. data/spec_rails/rails2/app_root/script/server +3 -0
  88. data/spec_rails/rails2/app_root/test/performance/browsing_test.rb +9 -0
  89. data/spec_rails/rails2/app_root/test/test_helper.rb +38 -0
  90. data/spec_rails/rails2/controllers/diagnostics_controller_spec.rb +12 -0
  91. data/spec_rails/rails2/controllers/statuses_controller_spec.rb +34 -0
  92. data/spec_rails/rails2/features/diagnostics_page.feature +34 -0
  93. data/spec_rails/rails2/features/status_page.feature +43 -0
  94. data/spec_rails/rails2/features/step_definitions/diagnostic_steps.rb +39 -0
  95. data/spec_rails/rails2/features/step_definitions/web_steps.rb +219 -0
  96. data/spec_rails/rails2/features/support/env.rb +61 -0
  97. data/spec_rails/rails2/features/support/hooks.rb +3 -0
  98. data/spec_rails/rails2/features/support/paths.rb +36 -0
  99. data/spec_rails/rails2/spec.opts +1 -0
  100. data/spec_rails/rails2/spec_helper.rb +4 -0
  101. data/spec_rails/rails3/Gemfile +0 -0
  102. metadata +119 -7
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
- pkg/*
2
- *.gem
1
+ .DS_Store
3
2
  .bundle
4
3
  .rvmrc
5
- .DS_Store
6
- tmp
4
+ *.gem
5
+ tmp
6
+ *.log
data/.specification ADDED
File without changes
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ diagnostics (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ aruba (0.2.2)
10
+ builder (2.1.2)
11
+ cucumber (0.8.3)
12
+ builder (~> 2.1.2)
13
+ diff-lcs (~> 1.1.2)
14
+ gherkin (~> 2.0.2)
15
+ json_pure (~> 1.4.3)
16
+ term-ansicolor (~> 1.0.4)
17
+ diff-lcs (1.1.2)
18
+ gherkin (2.0.2)
19
+ trollop (~> 1.16.2)
20
+ json_pure (1.4.6)
21
+ rspec (2.4.0)
22
+ rspec-core (~> 2.4.0)
23
+ rspec-expectations (~> 2.4.0)
24
+ rspec-mocks (~> 2.4.0)
25
+ rspec-core (2.4.0)
26
+ rspec-expectations (2.4.0)
27
+ diff-lcs (~> 1.1.2)
28
+ rspec-mocks (2.4.0)
29
+ term-ansicolor (1.0.5)
30
+ trollop (1.16.2)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ aruba (= 0.2.2)
37
+ cucumber (= 0.8.3)
38
+ diagnostics!
39
+ rspec (= 2.4.0)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Justin Ko
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # diagnostics
2
+
3
+ A Rails Engine that let's you make diagnostic checks.
4
+
5
+ ## Copyright
6
+
7
+ Copyright (c) 2011 Justin Ko. See LICENSE for details.
@@ -0,0 +1,12 @@
1
+ class DiagnosticsApplicationController < ActionController::Base
2
+ layout 'diagnostics'
3
+
4
+ before_filter :find_diagnostic_checks
5
+
6
+ private
7
+
8
+ def find_diagnostic_checks
9
+ @checks = diagnostic_checks
10
+ end
11
+
12
+ end
@@ -0,0 +1,6 @@
1
+ class DiagnosticsController < DiagnosticsApplicationController
2
+
3
+ def index
4
+ end
5
+
6
+ end
@@ -0,0 +1,20 @@
1
+ class StatusesController < DiagnosticsApplicationController
2
+
3
+ def show
4
+ respond_to do |format|
5
+ format.html {}
6
+ format.text { render text_response }
7
+ end
8
+ end
9
+
10
+ private
11
+
12
+ def text_response
13
+ if diagnostic_status == :passed
14
+ { :text => 'PASS', :status => 200 }
15
+ else
16
+ { :text => 'FAIL', :status => 500 }
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1 @@
1
+ <%= content_tag :div, check.name, :class => "diagnostic-check #{check.status}" %>
@@ -0,0 +1,22 @@
1
+ <% @title = 'Diagnostics' %>
2
+
3
+ <div id="one-column">
4
+ <fieldset>
5
+ <legend>System Checks</legend>
6
+ <table>
7
+ <% @checks.each do |check| %>
8
+ <tr>
9
+ <td class="name">
10
+ <%= render :partial => 'check', :locals => {:check => check} %>
11
+ </td>
12
+ <td class="diagnostic-data">
13
+ <%= check.data.attributes(:html).join('<br />') %>
14
+ <%= check.data.lists(:html).join('<br />') %>
15
+ <%= check.data.texts(:html) %>
16
+ <%= check.data.tables(:html) %>
17
+ </td>
18
+ </tr>
19
+ <% end %>
20
+ </table>
21
+ </fieldset>
22
+ </div>
@@ -0,0 +1,114 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <title><%= @title %></title>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
7
+ <meta http-equiv="refresh" content="30">
8
+ <style>
9
+ body {
10
+ text-align: center;
11
+ margin: 0;
12
+ padding: 0;
13
+ font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
14
+ font-size: 75%;
15
+ }
16
+ table {
17
+ margin-right: auto;
18
+ margin-left: auto;
19
+ border-collapse: collapse;
20
+ }
21
+ thead, tfoot {
22
+ background-color: #ddd;
23
+ }
24
+ td, th {
25
+ padding: 0.5em;
26
+ border: 1px solid #999;
27
+ }
28
+ form, form div {
29
+ display: inline;
30
+ }
31
+ h1 {
32
+ font-size: 30px;
33
+ padding: 20px 0 25px;
34
+ }
35
+ #content {
36
+ width: 900px;
37
+ margin: 0 auto;
38
+ }
39
+ #left {
40
+ width: 450px;
41
+ float: left;
42
+ text-align: left;
43
+ }
44
+ #right {
45
+ width: 450px;
46
+ float: right;
47
+ text-align: left;
48
+ }
49
+ #one-column {
50
+ text-align: left;
51
+ }
52
+ #one-column table {
53
+ width: 100%;
54
+ }
55
+ #one-column table td {
56
+ vertical-align: top;
57
+ }
58
+ #one-column table td div {
59
+ margin: 0;
60
+ }
61
+ #one-column table td.name {
62
+ width: 300px;
63
+ }
64
+ #refresh {
65
+ padding: 20px 0 0 0;
66
+ text-align: right;
67
+ width: 900px;
68
+ margin: 0 auto;
69
+ }
70
+ #system-status {
71
+ background: #eee;
72
+ }
73
+ #system-status.passed {
74
+ background: green;
75
+ }
76
+ #system-status.warning {
77
+ background: orange;
78
+ }
79
+ #system-status.failed {
80
+ background: red;
81
+ }
82
+ #system-status.none {
83
+ background: #ccc;
84
+ }
85
+ #system-status h1 {
86
+ color: #fff;
87
+ }
88
+ .diagnostic-check {
89
+ color: #fff;
90
+ margin-bottom: 10px;
91
+ padding: 15px 20px;
92
+ font-size: 16px;
93
+ font-weight: bold;
94
+ }
95
+ .diagnostic-check.passed {
96
+ background: green;
97
+ }
98
+ .diagnostic-check.warning {
99
+ background: orange;
100
+ }
101
+ .diagnostic-check.failed {
102
+ background: red;
103
+ }
104
+ .diagnostic-check.none {
105
+ background: #ccc;
106
+ }
107
+ </style>
108
+ </head>
109
+ <body>
110
+ <div id="refresh">This page will refresh every 30 seconds</div>
111
+ <%= content_tag :div, content_tag(:h1, diagnostic_message), :id => 'system-status', :class => diagnostic_status %>
112
+ <div id="content"><%= yield %></div>
113
+ </body>
114
+ </html>
@@ -0,0 +1,15 @@
1
+ <% @title = 'Status' %>
2
+
3
+ <div id="left">
4
+ <fieldset>
5
+ <legend>Tuesday, January 1 2010 10:00 MST</legend>
6
+ Everything has gone to hell! Run for the hills!
7
+ </fieldset>
8
+ </div>
9
+
10
+ <div id="right">
11
+ <fieldset>
12
+ <legend>System Checks</legend>
13
+ <%= render :partial => 'diagnostics/check', :collection => @checks %>
14
+ </fieldset>
15
+ </div>
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ map.resources :diagnostics
4
+ map.resource :status, :only => :show
5
+
6
+ end
data/diagnostics.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Justin Ko"]
10
10
  s.email = ["jko170@gmail.com"]
11
- s.homepage = ""
11
+ s.homepage = "http://github.com/justinko/diagnostics"
12
12
  s.summary = "diagnostics-#{Diagnostics::VERSION}"
13
13
  s.description = "A Rails Engine that let's you make diagnostic checks."
14
14
 
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
20
+ s.require_path = 'lib'
21
21
 
22
22
  s.add_development_dependency 'rspec', '2.4.0'
23
23
  s.add_development_dependency 'cucumber', '0.8.3'
@@ -0,0 +1,167 @@
1
+ Feature: Diagnostic checks
2
+
3
+ Checks allow you to determine if a "diagnostic check" has
4
+ passed, gave a warning, or failed.
5
+
6
+ They can also contain metadata info such as attributes,
7
+ lists, texts, and tables.
8
+
9
+ Scenario: Status methods on a check
10
+ Given a file named "status_methods.rb" with:
11
+ """
12
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
13
+ require 'diagnostics'
14
+
15
+ check = diagnostic_check :system do |c|
16
+ c.passed { true }
17
+ c.warning { false }
18
+ c.failed { false }
19
+ end
20
+
21
+ puts check.passed?
22
+ puts check.warning?
23
+ puts check.failed?
24
+ puts check.status.inspect
25
+ """
26
+ When I run "ruby status_methods.rb"
27
+ Then the output should contain exactly:
28
+ """
29
+ true
30
+ false
31
+ false
32
+ :passed
33
+
34
+ """
35
+
36
+ Scenario: Attributes on a check
37
+ Given a file named "attributes.rb" with:
38
+ """
39
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
40
+ require 'diagnostics'
41
+
42
+ check = diagnostic_check :system do |c|
43
+ c.data do |d|
44
+ d['Master'] = 'Up'
45
+ d['Slave'] = 'Down'
46
+ end
47
+ end
48
+
49
+ puts check.data.attributes(:plain)
50
+ puts
51
+ puts check.data.attributes(:html)
52
+ puts
53
+ check.data.attributes.map do |attribute|
54
+ puts "#{attribute.name}---#{attribute.value}"
55
+ end
56
+ """
57
+ When I run "ruby attributes.rb"
58
+ Then the output should contain exactly:
59
+ """
60
+ Master: Up
61
+ Slave: Down
62
+
63
+ <strong>Master:</strong> Up
64
+ <strong>Slave:</strong> Down
65
+
66
+ Master---Up
67
+ Slave---Down
68
+
69
+ """
70
+
71
+ Scenario: Lists on a check
72
+ Given a file named "lists.rb" with:
73
+ """
74
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
75
+ require 'diagnostics'
76
+
77
+ check = diagnostic_check :system do |c|
78
+ c.data do |d|
79
+ d << ['a', 'b', 'c']
80
+ d << [1, 2, 3]
81
+ end
82
+ end
83
+
84
+ puts check.data.lists(:plain)
85
+ puts
86
+ puts check.data.lists(:html)
87
+ """
88
+ When I run "ruby lists.rb"
89
+ Then the output should contain exactly:
90
+ """
91
+ a
92
+ b
93
+ c
94
+ 1
95
+ 2
96
+ 3
97
+
98
+ a<br />b<br />c
99
+ 1<br />2<br />3
100
+
101
+ """
102
+
103
+ Scenario: Texts on a check
104
+ Given a file named "texts.rb" with:
105
+ """
106
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
107
+ require 'diagnostics'
108
+
109
+ check = diagnostic_check :system do |c|
110
+ c.data do |d|
111
+ d << 'a'
112
+ d << 'b'
113
+ end
114
+ end
115
+
116
+ puts check.data.texts(:plain)
117
+ puts
118
+ puts check.data.texts(:html)
119
+ """
120
+ When I run "ruby texts.rb"
121
+ Then the output should contain exactly:
122
+ """
123
+ a
124
+ b
125
+
126
+ <p>a</p>
127
+ <p>b</p>
128
+
129
+ """
130
+
131
+ Scenario: Tables on a check
132
+ Given a file named "tables.rb" with:
133
+ """
134
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
135
+ require 'diagnostics'
136
+
137
+ check = diagnostic_check :system do |c|
138
+ c.data do |d|
139
+ d << { 'heading1' => [1,2,3],
140
+ 'heading2' => [4,5,6] }
141
+ end
142
+ end
143
+
144
+ print check.data.tables(:html)
145
+ """
146
+ When I run "ruby tables.rb"
147
+ Then the output should contain the table:
148
+ """
149
+ <table>
150
+ <tr>
151
+ <th>heading1</th>
152
+ <th>heading2</th>
153
+ </tr>
154
+ <tr>
155
+ <td>1</td>
156
+ <td>4</td>
157
+ </tr>
158
+ <tr>
159
+ <td>2</td>
160
+ <td>5</td>
161
+ </tr>
162
+ <tr>
163
+ <td>3</td>
164
+ <td>6</td>
165
+ </tr>
166
+ </table>
167
+ """