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