Commit 6cb626ef516a230b2af4e15145488d4c57cd048c

Authored by Robert Speicher
1 parent 8fe63dab

Add Compare#index and Compare#create actions

Create just redirects to our specially-formatted #show action
app/controllers/compare_controller.rb
... ... @@ -8,6 +8,9 @@ class CompareController < ApplicationController
8 8 before_filter :authorize_code_access!
9 9 before_filter :require_non_empty_project
10 10  
  11 + def index
  12 + end
  13 +
11 14 def show
12 15 result = Commit.compare(project, params[:from], params[:to])
13 16  
... ... @@ -19,4 +22,8 @@ class CompareController < ApplicationController
19 22  
20 23 @commits = CommitDecorator.decorate(@commits)
21 24 end
  25 +
  26 + def create
  27 + redirect_to project_compare_path(@project, params[:from], params[:to])
  28 + end
22 29 end
... ...
config/routes.rb
... ... @@ -162,7 +162,7 @@ Gitlab::Application.routes.draw do
162 162 # XXX: WIP
163 163 resources :commit, only: [:show], constraints: {id: /[[:alnum:]]{6,40}/}
164 164 resources :commits, only: [:show], constraints: {id: /.+/}
165   - resources :compare, only: [:index]
  165 + resources :compare, only: [:index, :create]
166 166 resources :blame, only: [:show], constraints: {id: /.+/}
167 167 resources :blob, only: [:show], constraints: {id: /.+/}
168 168 resources :tree, only: [:show], constraints: {id: /.+/}
... ...
spec/routing/project_routing_spec.rb
... ... @@ -399,12 +399,17 @@ describe TreeController, "routing" do
399 399 end
400 400  
401 401 # project_compare_index GET /:project_id/compare(.:format) compare#index {:id=>/[^\/]+/, :project_id=>/[^\/]+/}
  402 +# POST /:project_id/compare(.:format) compare#create {:id=>/[^\/]+/, :project_id=>/[^\/]+/}
402 403 # project_compare /:project_id/compare/:from...:to(.:format) compare#show {:from=>/.+/, :to=>/.+/, :id=>/[^\/]+/, :project_id=>/[^\/]+/}
403 404 describe CompareController, "routing" do
404 405 it "to #index" do
405 406 get("/gitlabhq/compare").should route_to('compare#index', project_id: 'gitlabhq')
406 407 end
407 408  
  409 + it "to #compare" do
  410 + post("/gitlabhq/compare").should route_to('compare#create', project_id: 'gitlabhq')
  411 + end
  412 +
408 413 it "to #show" do
409 414 get("/gitlabhq/compare/master...stable").should route_to('compare#show', project_id: 'gitlabhq', from: 'master', to: 'stable')
410 415 get("/gitlabhq/compare/issue/1234...stable").should route_to('compare#show', project_id: 'gitlabhq', from: 'issue/1234', to: 'stable')
... ...