Navigation Menu

Skip to content

Commit

Permalink
Add a /ping resource and a few CIJoe::Server tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarnette authored and defunkt committed Jan 21, 2010
1 parent 39b06eb commit 5d14c7e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.markdown
Expand Up @@ -83,6 +83,18 @@ Or do it the old fashion way:
etc.


Checkin' Status
---------------

Want to see how your build's doing without any of this fancy UI crap?
Ping Joe for the lowdown:

curl http://localhost:4567/ping

Joe will return `200 OK` if all is quiet on the Western Front. If
Joe's busy building or your last build failed, you'll get `412
PRECONDITION FAILED`.

Multiple Projects
-----------------

Expand Down
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -16,6 +16,7 @@ begin
gemspec.authors = ["Chris Wanstrath"]
gemspec.add_dependency 'choice'
gemspec.add_dependency 'sinatra'
gemspec.add_development_dependency 'rack-test'
gemspec.version = CIJoe::Version.to_s
end
rescue LoadError
Expand Down
10 changes: 10 additions & 0 deletions lib/cijoe/server.rb
Expand Up @@ -3,6 +3,8 @@

class CIJoe
class Server < Sinatra::Base
attr_reader :joe

dir = File.dirname(File.expand_path(__FILE__))

set :views, "#{dir}/views"
Expand All @@ -12,6 +14,14 @@ class Server < Sinatra::Base

before { @joe.restore }

get '/ping' do
if @joe.building? || !@joe.last_build || !@joe.last_build.worked?
halt 412, joe.last_build ? joe.last_build.sha : "building"
end

joe.last_build.sha
end

get '/?' do
erb(:template, {}, :joe => @joe)
end
Expand Down
3 changes: 3 additions & 0 deletions test/helper.rb
Expand Up @@ -5,5 +5,8 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'cijoe'

CIJoe::Server.set :project_path, "."
CIJoe::Server.set :environment, "test"

class Test::Unit::TestCase
end
50 changes: 50 additions & 0 deletions test/test_cijoe_server.rb
@@ -0,0 +1,50 @@
require "helper"
require "rack/test"
require "cijoe/server"

class TestCIJoeServer < Test::Unit::TestCase
include Rack::Test::Methods

class ::CIJoe
attr_writer :current_build, :last_build
end

attr_accessor :app

def setup
@app = CIJoe::Server.new
end

def test_ping
app.joe.last_build = build :worked
assert !app.joe.building?, "have a last build, but not a current"

get "/ping"
assert_equal 200, last_response.status
assert_equal app.joe.last_build.sha, last_response.body
end

def test_ping_building
app.joe.current_build = build :building
assert app.joe.building?, "buildin' a awsum project"

get "/ping"
assert_equal 412, last_response.status
assert_equal "building", last_response.body
end

def test_ping_failed
app.joe.last_build = build :failed

get "/ping"
assert_equal 412, last_response.status
assert_equal app.joe.last_build.sha, last_response.body
end

# Create a new, fake build. All we care about is status.

def build status
CIJoe::Build.new "user", "project", Time.now, Time.now,
"deadbeef", status, "output", 1337
end
end

0 comments on commit 5d14c7e

Please sign in to comment.