aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2014-09-17 17:09:25 +0100
committerGareth Rees <gareth@mysociety.org>2014-09-25 12:57:55 +0100
commit2fdfd7b62e603b5f4d2ff5925a49b2d5ed83bf3b (patch)
tree2e8d8272beee078367caa4b7d7d8cfa326a3dc2f
parentdcd75661164ec372f35fdc7be498e004f8a0b768 (diff)
Add an action to run the checks
-rw-r--r--app/controllers/health_checks_controller.rb16
-rw-r--r--app/helpers/health_checks_helper.rb8
-rw-r--r--app/views/health_checks/index.html.erb12
-rw-r--r--config/routes.rb2
-rw-r--r--spec/controllers/health_checks_controller_spec.rb30
-rw-r--r--spec/helpers/health_checks_helper_spec.rb15
6 files changed, 83 insertions, 0 deletions
diff --git a/app/controllers/health_checks_controller.rb b/app/controllers/health_checks_controller.rb
new file mode 100644
index 000000000..473a1aacc
--- /dev/null
+++ b/app/controllers/health_checks_controller.rb
@@ -0,0 +1,16 @@
+class HealthChecksController < ApplicationController
+
+ def index
+ @health_checks = HealthChecks.all
+
+ respond_to do |format|
+ if HealthChecks.ok?
+ format.html { render :action => :index, :layout => false }
+ else
+ format.html { render :action => :index, :layout => false , :status => 500 }
+ end
+ end
+
+ end
+
+end
diff --git a/app/helpers/health_checks_helper.rb b/app/helpers/health_checks_helper.rb
new file mode 100644
index 000000000..f5769a9ba
--- /dev/null
+++ b/app/helpers/health_checks_helper.rb
@@ -0,0 +1,8 @@
+module HealthChecksHelper
+
+ def check_status(check)
+ style = check.ok? ? {} : "color: red"
+ content_tag(:b, check.message, :style => style)
+ end
+
+end
diff --git a/app/views/health_checks/index.html.erb b/app/views/health_checks/index.html.erb
new file mode 100644
index 000000000..67b1050a9
--- /dev/null
+++ b/app/views/health_checks/index.html.erb
@@ -0,0 +1,12 @@
+<h1>Health Checks</h1>
+
+<div class="checks">
+ <% @health_checks.each do |check| %>
+ <div class="check">
+ <ul>
+ <li>Message: <%= check_status(check) %></li>
+ <li>OK? <%= check.ok? %></li>
+ </ul>
+ </div>
+ <% end %>
+</div>
diff --git a/config/routes.rb b/config/routes.rb
index 9f426fabf..a146c9031 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -61,6 +61,8 @@ Alaveteli::Application.routes.draw do
match '/request/:url_title/download' => 'request#download_entire_request', :as => :download_entire_request
####
+ resources :health_checks, :only => [:index]
+
resources :request, :only => [] do
resource :report, :only => [:new, :create]
end
diff --git a/spec/controllers/health_checks_controller_spec.rb b/spec/controllers/health_checks_controller_spec.rb
new file mode 100644
index 000000000..f7ad6d6a4
--- /dev/null
+++ b/spec/controllers/health_checks_controller_spec.rb
@@ -0,0 +1,30 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe HealthChecksController do
+
+ describe :index do
+
+ describe :index do
+
+ it 'returns a 200 if all health checks pass' do
+ HealthChecks.stub(:ok? => true)
+ get :index
+ expect(response.status).to eq(200)
+ end
+
+ it 'returns a 500 if the health check fails' do
+ HealthChecks.stub(:ok? => false)
+ get :index
+ expect(response.status).to eq(500)
+ end
+
+ it 'does not render a layout' do
+ get :index
+ expect(response).to render_template(:layout => false)
+ end
+
+ end
+
+ end
+
+end
diff --git a/spec/helpers/health_checks_helper_spec.rb b/spec/helpers/health_checks_helper_spec.rb
new file mode 100644
index 000000000..7d4083da5
--- /dev/null
+++ b/spec/helpers/health_checks_helper_spec.rb
@@ -0,0 +1,15 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe HealthChecksHelper do
+ include HealthChecksHelper
+
+ describe :check_status do
+
+ it 'warns that the check is failing' do
+ check = double(:message => 'Failed', :ok? => false)
+ expect(check_status(check)).to include('red')
+ end
+
+ end
+
+end