Commit a8ea8d98a4f88a292289ddfedef4358033b68ec0

Authored by Robert Speicher
1 parent 398ba6f1

Update RefExtractor to handle atom feeds

app/controllers/tree_controller.rb
1 # Controller for viewing a repository's file structure 1 # Controller for viewing a repository's file structure
2 class TreeController < ApplicationController 2 class TreeController < ApplicationController
3 - # Thrown when given an invalid path  
4 - class InvalidPathError < StandardError; end  
5 -  
6 include RefExtractor 3 include RefExtractor
7 4
8 layout "project" 5 layout "project"
lib/ref_extractor.rb
1 # Module providing an extract_ref method for controllers working with Git 1 # Module providing an extract_ref method for controllers working with Git
2 # tree-ish + path params 2 # tree-ish + path params
3 module RefExtractor 3 module RefExtractor
4 - # Thrown when given an invalid path 4 + # Raised when given an invalid path
5 class InvalidPathError < StandardError; end 5 class InvalidPathError < StandardError; end
6 6
7 # Given a string containing both a Git ref - such as a branch or tag - and a 7 # Given a string containing both a Git ref - such as a branch or tag - and a
@@ -81,6 +81,12 @@ module RefExtractor @@ -81,6 +81,12 @@ module RefExtractor
81 # Automatically renders `not_found!` if a valid tree could not be resolved 81 # Automatically renders `not_found!` if a valid tree could not be resolved
82 # (e.g., when a user inserts an invalid path or ref). 82 # (e.g., when a user inserts an invalid path or ref).
83 def assign_ref_vars 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 @ref, @path = extract_ref(params[:id]) 90 @ref, @path = extract_ref(params[:id])
85 91
86 @id = File.join(@ref, @path) 92 @id = File.join(@ref, @path)
spec/routing/project_routing_spec.rb
@@ -293,11 +293,7 @@ end @@ -293,11 +293,7 @@ end
293 # patch_project_commit GET /:project_id/commits/:id/patch(.:format) commits#patch 293 # patch_project_commit GET /:project_id/commits/:id/patch(.:format) commits#patch
294 # project_commits GET /:project_id/commits(.:format) commits#index 294 # project_commits GET /:project_id/commits(.:format) commits#index
295 # POST /:project_id/commits(.:format) commits#create 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 # project_commit GET /:project_id/commits/:id(.:format) commits#show 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 describe CommitsController, "routing" do 297 describe CommitsController, "routing" do
302 it "to #compare" do 298 it "to #compare" do
303 get("/gitlabhq/commits/compare").should route_to('commits#compare', project_id: 'gitlabhq') 299 get("/gitlabhq/commits/compare").should route_to('commits#compare', project_id: 'gitlabhq')
@@ -307,6 +303,10 @@ describe CommitsController, &quot;routing&quot; do @@ -307,6 +303,10 @@ describe CommitsController, &quot;routing&quot; do
307 get("/gitlabhq/commits/1/patch").should route_to('commits#patch', project_id: 'gitlabhq', id: '1') 303 get("/gitlabhq/commits/1/patch").should route_to('commits#patch', project_id: 'gitlabhq', id: '1')
308 end 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 it_behaves_like "RESTful project resources" do 310 it_behaves_like "RESTful project resources" do
311 let(:actions) { [:index, :show] } 311 let(:actions) { [:index, :show] }
312 let(:controller) { 'commits' } 312 let(:controller) { 'commits' }
@@ -425,6 +425,7 @@ end @@ -425,6 +425,7 @@ end
425 # /:project_id/commits/*path 425 # /:project_id/commits/*path
426 # /gitlabhq/commits/master/app/contexts/base_context.rb 426 # /gitlabhq/commits/master/app/contexts/base_context.rb
427 # /gitlabhq/commits/test/branch/name/app/contexts/base_context.rb 427 # /gitlabhq/commits/test/branch/name/app/contexts/base_context.rb
  428 +# /gitlabhq/commits/master.atom
428 # 429 #
429 # /:project_id/raw/*path 430 # /:project_id/raw/*path
430 # /gitlabhq/raw/master/app/contexts/base_context.rb 431 # /gitlabhq/raw/master/app/contexts/base_context.rb
@@ -436,13 +437,6 @@ end @@ -436,13 +437,6 @@ end
436 describe "pending routing" do 437 describe "pending routing" do
437 before { pending } 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 describe "/:project_id/raw/:id" do 440 describe "/:project_id/raw/:id" do
447 it "routes to a ref with a path" do 441 it "routes to a ref with a path" do
448 get("/gitlabhq/raw/master/app/models/project.rb").should route_to('raw#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb') 442 get("/gitlabhq/raw/master/app/models/project.rb").should route_to('raw#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')