Commit a8ea8d98a4f88a292289ddfedef4358033b68ec0
1 parent
398ba6f1
Exists in
master
and in
4 other branches
Update RefExtractor to handle atom feeds
Showing
3 changed files
with
12 additions
and
15 deletions
Show diff stats
app/controllers/tree_controller.rb
lib/ref_extractor.rb
| 1 | 1 | # Module providing an extract_ref method for controllers working with Git |
| 2 | 2 | # tree-ish + path params |
| 3 | 3 | module RefExtractor |
| 4 | - # Thrown when given an invalid path | |
| 4 | + # Raised when given an invalid path | |
| 5 | 5 | class InvalidPathError < StandardError; end |
| 6 | 6 | |
| 7 | 7 | # Given a string containing both a Git ref - such as a branch or tag - and a |
| ... | ... | @@ -81,6 +81,12 @@ module RefExtractor |
| 81 | 81 | # Automatically renders `not_found!` if a valid tree could not be resolved |
| 82 | 82 | # (e.g., when a user inserts an invalid path or ref). |
| 83 | 83 | def assign_ref_vars |
| 84 | + # Handle formats embedded in the id | |
| 85 | + if params[:id].ends_with?('.atom') | |
| 86 | + params[:id].gsub!(/\.atom$/, '') | |
| 87 | + request.format = :atom | |
| 88 | + end | |
| 89 | + | |
| 84 | 90 | @ref, @path = extract_ref(params[:id]) |
| 85 | 91 | |
| 86 | 92 | @id = File.join(@ref, @path) | ... | ... |
spec/routing/project_routing_spec.rb
| ... | ... | @@ -293,11 +293,7 @@ end |
| 293 | 293 | # patch_project_commit GET /:project_id/commits/:id/patch(.:format) commits#patch |
| 294 | 294 | # project_commits GET /:project_id/commits(.:format) commits#index |
| 295 | 295 | # POST /:project_id/commits(.:format) commits#create |
| 296 | -# new_project_commit GET /:project_id/commits/new(.:format) commits#new | |
| 297 | -# edit_project_commit GET /:project_id/commits/:id/edit(.:format) commits#edit | |
| 298 | 296 | # project_commit GET /:project_id/commits/:id(.:format) commits#show |
| 299 | -# PUT /:project_id/commits/:id(.:format) commits#update | |
| 300 | -# DELETE /:project_id/commits/:id(.:format) commits#destroy | |
| 301 | 297 | describe CommitsController, "routing" do |
| 302 | 298 | it "to #compare" do |
| 303 | 299 | get("/gitlabhq/commits/compare").should route_to('commits#compare', project_id: 'gitlabhq') |
| ... | ... | @@ -307,6 +303,10 @@ describe CommitsController, "routing" do |
| 307 | 303 | get("/gitlabhq/commits/1/patch").should route_to('commits#patch', project_id: 'gitlabhq', id: '1') |
| 308 | 304 | end |
| 309 | 305 | |
| 306 | + it "does something with atom feeds" do | |
| 307 | + get("/gitlabhq/commits/master.atom").should route_to('commits#show', project_id: 'gitlabhq', id: 'master.atom') | |
| 308 | + end | |
| 309 | + | |
| 310 | 310 | it_behaves_like "RESTful project resources" do |
| 311 | 311 | let(:actions) { [:index, :show] } |
| 312 | 312 | let(:controller) { 'commits' } |
| ... | ... | @@ -425,6 +425,7 @@ end |
| 425 | 425 | # /:project_id/commits/*path |
| 426 | 426 | # /gitlabhq/commits/master/app/contexts/base_context.rb |
| 427 | 427 | # /gitlabhq/commits/test/branch/name/app/contexts/base_context.rb |
| 428 | +# /gitlabhq/commits/master.atom | |
| 428 | 429 | # |
| 429 | 430 | # /:project_id/raw/*path |
| 430 | 431 | # /gitlabhq/raw/master/app/contexts/base_context.rb |
| ... | ... | @@ -436,13 +437,6 @@ end |
| 436 | 437 | describe "pending routing" do |
| 437 | 438 | before { pending } |
| 438 | 439 | |
| 439 | - describe "/:project_id/commit/:id" do | |
| 440 | - it "routes to a specific commit" do | |
| 441 | - get("/gitlabhq/commit/f4b1449").should route_to('commit#show', project_id: 'gitlabhq', id: 'f4b1449') | |
| 442 | - get("/gitlabhq/commit/f4b14494ef6abf3d144c28e4af0c20143383e062").should route_to('commit#show', project_id: 'gitlabhq', id: 'f4b14494ef6abf3d144c28e4af0c20143383e062') | |
| 443 | - end | |
| 444 | - end | |
| 445 | - | |
| 446 | 440 | describe "/:project_id/raw/:id" do |
| 447 | 441 | it "routes to a ref with a path" do |
| 448 | 442 | get("/gitlabhq/raw/master/app/models/project.rb").should route_to('raw#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb') | ... | ... |