have :id in repos controller only match digits
This commit is contained in:
parent
f19bfa1ada
commit
b448410da5
|
@ -3,6 +3,8 @@ require 'travis/api/app'
|
||||||
class Travis::Api::App
|
class Travis::Api::App
|
||||||
class Endpoint
|
class Endpoint
|
||||||
class Repos < Endpoint
|
class Repos < Endpoint
|
||||||
|
set :pattern, capture: { id: /\d+/ }
|
||||||
|
|
||||||
# Endpoint for getting all repositories.
|
# Endpoint for getting all repositories.
|
||||||
#
|
#
|
||||||
# You can filter the repositories by adding parameters to the request. For example, you can get 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
|
||||||
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.
|
# Gets the repository with the given id.
|
||||||
#
|
#
|
||||||
# ### Response
|
# ### Response
|
||||||
|
@ -37,6 +31,13 @@ class Travis::Api::App
|
||||||
end
|
end
|
||||||
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
|
get '/:id/cc' do
|
||||||
respond_with service(:find_repo, params.merge(schema: 'cc'))
|
respond_with service(:find_repo, params.merge(schema: 'cc'))
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Travis::Api::App::Endpoint::Repos do
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user