Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Commit

Permalink
test that custom hook names are working
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed May 2, 2012
1 parent d078d80 commit 20dbca5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/service.rb
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion 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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }
2 changes: 2 additions & 0 deletions test/helper.rb
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions test/service_app_test.rb
Expand Up @@ -12,6 +12,8 @@ class << self
def receive_booya
self.class.tested << self
end

setup_for(Service::App)
end

def setup
Expand Down Expand Up @@ -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
Expand Down

1 comment on commit 20dbca5

@technoweenie
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremy Congrats, you're the first to actually try to use #hook_name on the Basecamp hooks. Too bad it didn't work :) The #inherited callback was firing before the custom hook_name was set, so Sinatra didn't even route the 'bcx' path. It should be working now.

Please sign in to comment.