diff options
| author | mo khan <mo@mokhan.ca> | 2017-01-28 10:10:29 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2017-01-28 10:10:29 -0700 |
| commit | 2b6ac01422b4eac7f527d516ee78843e7dd0bb87 (patch) | |
| tree | 81acedf4dc5317fd25d08a7d6096c469e4773afa | |
| parent | 4e2aa5516e07ae2f40d2064cde5b3a692307b564 (diff) | |
add return 404 when in maintenance mode.
| -rw-r--r-- | app/controllers/bloodpressure/health_controller.rb | 11 | ||||
| -rw-r--r-- | test/controllers/bloodpressure/health_controller_test.rb | 16 |
2 files changed, 27 insertions, 0 deletions
diff --git a/app/controllers/bloodpressure/health_controller.rb b/app/controllers/bloodpressure/health_controller.rb index 6c531ba..abb59f5 100644 --- a/app/controllers/bloodpressure/health_controller.rb +++ b/app/controllers/bloodpressure/health_controller.rb @@ -4,6 +4,17 @@ module Bloodpressure class HealthController < ApplicationController def show @hostname = Socket.gethostname + render status: http_status + end + + private + + def http_status + File.readable?(maintenance_file) ? :not_found : :ok + end + + def maintenance_file + Rails.root.join('tmp', 'maintenance') end end end diff --git a/test/controllers/bloodpressure/health_controller_test.rb b/test/controllers/bloodpressure/health_controller_test.rb index 2da55ae..83980a5 100644 --- a/test/controllers/bloodpressure/health_controller_test.rb +++ b/test/controllers/bloodpressure/health_controller_test.rb @@ -4,10 +4,26 @@ module Bloodpressure class HealthControllerTest < ActionDispatch::IntegrationTest include Engine.routes.url_helpers + setup do + @maintenance_file = Rails.root.join('tmp', 'maintenance') + end + + teardown do + File.unlink(@maintenance_file) if File.readable?(@maintenance_file) + end + test "returns the hostname" do get health_url assert_response :success assert_select "h1", Socket.gethostname end + + test "returns 404, when in maintenance mode" do + FileUtils.touch(@maintenance_file) + + get health_url + assert_response :not_found + assert_select "h1", Socket.gethostname + end end end |
