diff --git a/Gemfile.lock b/Gemfile.lock index 7f2c8c6b..e0bba5fe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index 172e3342..4f61f6a6 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -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 diff --git a/lib/travis/api/app/extensions/expose_pattern.rb b/lib/travis/api/app/extensions/expose_pattern.rb new file mode 100644 index 00000000..7ed0cc3e --- /dev/null +++ b/lib/travis/api/app/extensions/expose_pattern.rb @@ -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 diff --git a/spec/unit/extensions/expose_pattern_spec.rb b/spec/unit/extensions/expose_pattern_spec.rb new file mode 100644 index 00000000..1952665d --- /dev/null +++ b/spec/unit/extensions/expose_pattern_spec.rb @@ -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 \ No newline at end of file