add extension that keeps track of route pattern

This commit is contained in:
Konstantin Haase 2013-01-23 15:22:06 +01:00
parent 11230cbb44
commit 07c5f6b61f
4 changed files with 37 additions and 2 deletions

View File

@ -66,7 +66,7 @@ GIT
GIT
remote: git://github.com/travis-ci/travis-core.git
revision: aecd4e464e4c18d0e77e1e44deac75e4f1054efe
revision: 259e48ffc68a67eff32848334025ef17ab58a3b3
specs:
travis-core (0.0.1)
actionmailer (~> 3.2.11)

View File

@ -27,7 +27,7 @@ class Travis::Api::App
disable :protection, :logging, :setup
enable :raise_errors
# disable :dump_errors
register :subclass_tracker
register :subclass_tracker, :expose_pattern
helpers :respond_with, :mime_types
end

View File

@ -0,0 +1,12 @@
require 'travis/api/app'
class Travis::Api::App
module Extensions
module ExposePattern
def route(verb, path, *)
condition { headers('X-Endpoint' => settings.name.to_s, 'X-Pattern' => path.to_s) }
super
end
end
end
end

View File

@ -0,0 +1,23 @@
require 'spec_helper'
class Foo < Sinatra::Base
register Travis::Api::App::Extensions::ExposePattern
get '/:id' do
"ok"
end
end
describe Travis::Api::App::Extensions::ExposePattern do
before { set_app(Foo) }
example "it exposes the pattern" do
get('/foo').should be_ok
headers['X-Pattern'].should be == '/:id'
end
example "it exposes the app class" do
get('/foo').should be_ok
headers['X-Endpoint'].should be == 'Foo'
end
end