summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKia Mei Somabes <kssomabes@up.edu.ph>2018-07-24 08:04:16 +0800
committerKia Mei Somabes <kssomabes@up.edu.ph>2018-07-24 08:04:16 +0800
commitc03bc268be7769ceeb9d1738d6b887a7c866e2a0 (patch)
tree5919a9b21cb6d56e84002619c6329d9b57d96427
parent3b4734ce714f2e112241453dd04f0273a9d362ec (diff)
downloadgitlab-ce-c03bc268be7769ceeb9d1738d6b887a7c866e2a0.tar.gz
Transfer to commits_controller, add test, and update changelog
-rw-r--r--app/controllers/application_controller.rb4
-rw-r--r--app/controllers/projects/commits_controller.rb10
-rw-r--r--changelogs/unreleased/31576-redirect-commits-to-root-if-no-ref.yml2
-rw-r--r--config/routes/repository.rb2
-rw-r--r--spec/controllers/projects/commits_controller_spec.rb14
5 files changed, 23 insertions, 9 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index e802437df94..21cc6dfdd16 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -63,10 +63,6 @@ class ApplicationController < ActionController::Base
render_503
end
- def redirect_commits_root
- redirect_to controller: 'commits', action: 'show', id: @repository.root_ref
- end
-
def redirect_back_or_default(default: root_path, options: {})
redirect_to request.referer.present? ? :back : default, options
end
diff --git a/app/controllers/projects/commits_controller.rb b/app/controllers/projects/commits_controller.rb
index 9e495061f4e..36faea8056e 100644
--- a/app/controllers/projects/commits_controller.rb
+++ b/app/controllers/projects/commits_controller.rb
@@ -4,13 +4,17 @@ class Projects::CommitsController < Projects::ApplicationController
include ExtractsPath
include RendersCommits
- before_action :whitelist_query_limiting
+ before_action :whitelist_query_limiting, except: :commits_root
before_action :require_non_empty_project
- before_action :assign_ref_vars
+ before_action :assign_ref_vars, except: :commits_root
before_action :authorize_download_code!
- before_action :set_commits
+ before_action :set_commits, except: :commits_root
before_action :set_request_format, only: :show
+ def commits_root
+ redirect_to project_commits_path(@project, @project.default_branch)
+ end
+
def show
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
.find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref)
diff --git a/changelogs/unreleased/31576-redirect-commits-to-root-if-no-ref.yml b/changelogs/unreleased/31576-redirect-commits-to-root-if-no-ref.yml
index d117e9ad3d7..21d9d25d342 100644
--- a/changelogs/unreleased/31576-redirect-commits-to-root-if-no-ref.yml
+++ b/changelogs/unreleased/31576-redirect-commits-to-root-if-no-ref.yml
@@ -1,5 +1,5 @@
---
title: Redirect commits to root if no ref is provided (31576)
-merge_request:
+merge_request: 20738
author: Kia Mei Somabes
type: added
diff --git a/config/routes/repository.rb b/config/routes/repository.rb
index 87101a69bba..d439cb9acbd 100644
--- a/config/routes/repository.rb
+++ b/config/routes/repository.rb
@@ -83,7 +83,7 @@ scope format: false do
get '/raw/*id', to: 'raw#show', as: :raw
get '/blame/*id', to: 'blame#show', as: :blame
- get '/commits/', to: 'application#redirect_commits_root', as: :commits_root
+ get '/commits', to: 'commits#commits_root', as: :commits_root
get '/commits/*id/signatures', to: 'commits#signatures', as: :signatures
get '/commits/*id', to: 'commits#show', as: :commits
diff --git a/spec/controllers/projects/commits_controller_spec.rb b/spec/controllers/projects/commits_controller_spec.rb
index 55ed276f96b..2e0457378f0 100644
--- a/spec/controllers/projects/commits_controller_spec.rb
+++ b/spec/controllers/projects/commits_controller_spec.rb
@@ -9,6 +9,20 @@ describe Projects::CommitsController do
project.add_master(user)
end
+ describe "GET commits_root" do
+ context "no ref is provided" do
+ before do
+ get(:commits_root,
+ namespace_id: project.namespace,
+ project_id: project)
+ end
+
+ it 'should redirect to the default branch of the project' do
+ expect(response).to redirect_to project_commits_path(project)
+ end
+ end
+ end
+
describe "GET show" do
render_views