add extension that keeps track of route pattern
This commit is contained in:
parent
11230cbb44
commit
07c5f6b61f
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
12
lib/travis/api/app/extensions/expose_pattern.rb
Normal file
12
lib/travis/api/app/extensions/expose_pattern.rb
Normal 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
|
23
spec/unit/extensions/expose_pattern_spec.rb
Normal file
23
spec/unit/extensions/expose_pattern_spec.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user