From 20dbca533f2b7b15574a26cfd3467a9dd539b436 Mon Sep 17 00:00:00 2001 From: rick Date: Wed, 2 May 2012 09:17:28 -0600 Subject: [PATCH] test that custom hook names are working --- lib/service.rb | 5 ++++- lib/service/app.rb | 11 ++++++++++- test/helper.rb | 2 ++ test/service_app_test.rb | 9 +++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/service.rb b/lib/service.rb index 01dc9d3e3..a36722389 100644 --- a/lib/service.rb +++ b/lib/service.rb @@ -344,9 +344,12 @@ def objectify(hash) # Returns nothing. def inherited(svc) Service.services << svc - Service::App.service(svc) super end + + def setup_for(app) + app.service(self) + end end # Determine #root from this file's location diff --git a/lib/service/app.rb b/lib/service/app.rb index 6bdac1708..2e9544789 100644 --- a/lib/service/app.rb +++ b/lib/service/app.rb @@ -1,3 +1,5 @@ +Dir["#{File.dirname(__FILE__)}/../../services/**/*.rb"].each { |service| load service } + # The Sinatra App that handles incoming events. class Service::App < Sinatra::Base JSON_TYPE = "application/vnd.github-services+json" @@ -10,6 +12,10 @@ class Service::App < Sinatra::Base # # Returns nothing. def self.service(svc_class) + get "/#{svc_class.hook_name}" do + svc_class.title + end + post "/#{svc_class.hook_name}/:event" do boom = nil time = Time.now.to_f @@ -52,6 +58,10 @@ def self.service(svc_class) end end + Service.services.each do |svc| + svc.setup_for(self) + end + get "/" do "ok" end @@ -123,4 +133,3 @@ def report_exception(service_class, service_data, exception, options = {}) end end -Dir["#{File.dirname(__FILE__)}/../../services/**/*.rb"].each { |service| load service } diff --git a/test/helper.rb b/test/helper.rb index b5a760e19..eeb3e3e7b 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -2,6 +2,8 @@ require File.expand_path('../../config/load', __FILE__) class Service::TestCase < Test::Unit::TestCase + ALL_SERVICES = Service.services.dup + def test_default end diff --git a/test/service_app_test.rb b/test/service_app_test.rb index 5f6451734..79e0227a3 100644 --- a/test/service_app_test.rb +++ b/test/service_app_test.rb @@ -12,6 +12,8 @@ class << self def receive_booya self.class.tested << self end + + setup_for(Service::App) end def setup @@ -57,6 +59,13 @@ def test_nagios_check assert_equal 'ok', last_response.body end + def test_service_hook_names + Service::TestCase::ALL_SERVICES.each do |svc| + get "/#{svc.hook_name}" + assert_equal svc.title, last_response.body + end + end + def app Service::App end