diff --git a/Gemfile.lock b/Gemfile.lock index 1e6dbf5c..e6706c0a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,7 +36,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: b4c4ae9beb6ba8d813491273dc75fa582ee719b0 + revision: a5277a1f47a8615672607026239af49a217e2830 specs: travis-core (0.0.1) actionmailer (~> 3.2.19) @@ -84,6 +84,7 @@ PATH travis-api (0.0.1) backports (~> 2.5) memcachier + mustermann (~> 0.4) pg (~> 0.13.2) rack-contrib (~> 1.1) rack-ssl (~> 1.3, >= 1.3.3) @@ -214,6 +215,8 @@ GEM metaclass (~> 0.0.1) multi_json (1.10.1) multipart-post (2.0.0) + mustermann (0.4.0) + tool (~> 0.2) net-http-persistent (2.9.4) net-http-pipeline (1.0.1) pg (0.13.2) @@ -312,6 +315,7 @@ GEM tilt (1.4.1) timers (4.0.1) hitimes + tool (0.2.3) travis-config (0.1.0) hashr (~> 0.0) treetop (1.4.15) diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index d5f07bee..86b633f1 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -1,11 +1,13 @@ require 'travis/api/app' require 'sinatra/base' +require 'mustermann' class Travis::Api::App # Superclass for any endpoint and middleware. # Pulls in relevant helpers and extensions. class Base < Sinatra::Base register Extensions::SmartConstants + register Mustermann error NotImplementedError do content_type :txt diff --git a/lib/travis/api/app/endpoint/repos.rb b/lib/travis/api/app/endpoint/repos.rb index 1e52b7d0..f960c8dc 100644 --- a/lib/travis/api/app/endpoint/repos.rb +++ b/lib/travis/api/app/endpoint/repos.rb @@ -3,6 +3,8 @@ require 'travis/api/app' class Travis::Api::App class Endpoint class Repos < Endpoint + set :pattern, capture: { id: /\d+/ } + # Endpoint for getting all repositories. # # You can filter the repositories by adding parameters to the request. For example, you can get all repositories @@ -18,14 +20,6 @@ class Travis::Api::App end end - # Retrieves repositories for a given owner. - get '/:owner_name' do - pass if params[:owner_name] =~ /^\d+$/ # so we don't capture '/:id' - prefer_follower do - respond_with service(:find_repos, params) - end - end - # Gets the repository with the given id. # # ### Response @@ -37,6 +31,13 @@ class Travis::Api::App end end + # Retrieves repositories for a given owner. + get '/:owner_name' do + prefer_follower do + respond_with service(:find_repos, params) + end + end + get '/:id/cc' do respond_with service(:find_repo, params.merge(schema: 'cc')) end diff --git a/spec/unit/endpoint/repos_spec.rb b/spec/unit/endpoint/repos_spec.rb index bbfc9579..67dc5d89 100644 --- a/spec/unit/endpoint/repos_spec.rb +++ b/spec/unit/endpoint/repos_spec.rb @@ -1,5 +1,16 @@ require 'spec_helper' describe Travis::Api::App::Endpoint::Repos do - it 'has to be tested' + before do + described_class.get('/spec/match/:id') { "id" } + described_class.get('/spec/match/:name') { "name" } + end + + it 'matches id with digits' do + get('/repos/spec/match/123').body.should be == "id" + end + + it 'does not match id with non-digits' do + get('/repos/spec/match/f123').body.should be == "name" + end end diff --git a/travis-api.gemspec b/travis-api.gemspec index 6f8d3185..d98c31da 100644 --- a/travis-api.gemspec +++ b/travis-api.gemspec @@ -259,6 +259,7 @@ Gem::Specification.new do |s| s.add_dependency 'thin', '~> 1.4' s.add_dependency 'sinatra', '~> 1.3' s.add_dependency 'sinatra-contrib', '~> 1.3' + s.add_dependency 'mustermann', '~> 0.4' s.add_dependency 'redcarpet', '~> 2.1' s.add_dependency 'rack-ssl', '~> 1.3', '>= 1.3.3' s.add_dependency 'rack-contrib', '~> 1.1'