Skip to content
This repository has been archived by the owner on Dec 22, 2017. It is now read-only.

Add support for json output for statuses #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'
gem 'rails_12factor'
gem 'jbuilder'

gem 'rake'
gem 'mocha', :require => false
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ GEM
execjs (2.2.1)
hike (1.2.3)
i18n (0.6.11)
jbuilder (2.0.6)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (3.1.1)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
Expand Down Expand Up @@ -109,6 +112,7 @@ PLATFORMS

DEPENDENCIES
coffee-rails
jbuilder
jquery-rails
json
mocha
Expand Down
13 changes: 13 additions & 0 deletions app/views/status/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
json.status @status

json.services @pings do |ping|
json.name ping.service
json.status ping.state
json.description ping.description

if !ping.unknown?
json.last_seen ping.last_seen.iso8601
else
json.last_seen "unknown"
end
end
43 changes: 43 additions & 0 deletions test/integration/status_json_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'test_helper'

class StatusJsonTest < ActionDispatch::IntegrationTest
def json_response
JSON.parse(response.body)
end

test "Status API: GET / when all services are up" do
Ping.create! status: "up", service: "Application", description: "This service is up", last_seen: Time.new(2014, 3, 14, 1, 59, 26).utc
Ping.create! status: "up", service: "Core API", description: "This service is up", last_seen: Time.new(2014, 2, 7, 1, 8, 28).utc

get "/", {}, {"Accept" => "application/json"}

service = json_response["services"].find { |s| s["name"] == "Core API" }

assert_match "up", json_response["status"]
assert_match "up", json_response["services"][0]["status"]
assert_match "This service is up", json_response["services"][0]["descrption"]
assert_match "2014-03-14T08:59:26Z", json_response["services"][0]["last_seen"]
end

test "Status API: GET / when some of the services are down" do
Ping.create! status: "down", service: "Application", last_seen: Time.new(2014, 3, 14, 1, 59, 26).utc
Ping.create! status: "up", service: "Core API", last_seen: Time.new(2014, 2, 7, 1, 8, 28).utc

get "/", {}, {"Accept" => "application/json"}

assert_match "partial", json_response["status"]
assert_match "down", json_response["services"][0]["status"]
assert_match "up", json_response["services"][1]["status"]
end

test "Status API: GET / when all of the services are down" do
Ping.create! status: "down", service: "Application", last_seen: Time.new(2014, 3, 14, 1, 59, 26).utc
Ping.create! status: "down", service: "Core API", last_seen: Time.new(2014, 2, 7, 1, 8, 28).utc

get "/", {}, {"Accept" => "application/json"}

assert_match "down", json_response["status"]
assert_match "down", json_response["services"][0]["status"]
assert_match "down", json_response["services"][1]["status"]
end
end