summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuilherme Vieira <guilherme@flipstudio.net>2017-10-01 11:54:12 -0300
committerWinnie Hellmann <winnie@gitlab.com>2017-10-21 23:32:05 +0300
commitd3ecf95d0c762946707c6aaec2e97396c6a014e3 (patch)
tree7486c84af1378cc8b1bbd1e3eb7afd04ba715977
parent85fbb47ba4287730236bdf96abd3ddfea6c08616 (diff)
downloadgitlab-ce-d3ecf95d0c762946707c6aaec2e97396c6a014e3.tar.gz
Renders 404 in commits controller if no commits are found
-rw-r--r--app/controllers/projects/commits_controller.rb2
-rw-r--r--changelogs/unreleased/not-found-in-commits.yml5
-rw-r--r--features/steps/shared/paths.rb2
-rw-r--r--spec/controllers/projects/commits_controller_spec.rb31
4 files changed, 37 insertions, 3 deletions
diff --git a/app/controllers/projects/commits_controller.rb b/app/controllers/projects/commits_controller.rb
index 4a841bf2073..d48284a4429 100644
--- a/app/controllers/projects/commits_controller.rb
+++ b/app/controllers/projects/commits_controller.rb
@@ -48,6 +48,8 @@ class Projects::CommitsController < Projects::ApplicationController
private
def set_commits
+ render_404 unless request.format == :atom || @repository.blob_at(@commit.id, @path) || @repository.tree(@commit.id, @path).entries.present?
+
@limit, @offset = (params[:limit] || 40).to_i, (params[:offset] || 0).to_i
search = params[:search]
diff --git a/changelogs/unreleased/not-found-in-commits.yml b/changelogs/unreleased/not-found-in-commits.yml
new file mode 100644
index 00000000000..d5f9ff15a36
--- /dev/null
+++ b/changelogs/unreleased/not-found-in-commits.yml
@@ -0,0 +1,5 @@
+---
+title: Renders 404 in commits controller if no commits are found for a given path
+merge_request: 14610
+author: Guilherme Vieira
+type: fixed
diff --git a/features/steps/shared/paths.rb b/features/steps/shared/paths.rb
index dc0e3ac59a5..bff0d58aaf4 100644
--- a/features/steps/shared/paths.rb
+++ b/features/steps/shared/paths.rb
@@ -222,7 +222,7 @@ module SharedPaths
end
step "I visit my project's commits page for a specific path" do
- visit project_commits_path(@project, root_ref + "/app/models/project.rb", { limit: 5 })
+ visit project_commits_path(@project, root_ref + "/files/ruby/regex.rb", { limit: 5 })
end
step 'I visit my project\'s commits stats page' do
diff --git a/spec/controllers/projects/commits_controller_spec.rb b/spec/controllers/projects/commits_controller_spec.rb
index e26731fb691..c459d732507 100644
--- a/spec/controllers/projects/commits_controller_spec.rb
+++ b/spec/controllers/projects/commits_controller_spec.rb
@@ -10,9 +10,36 @@ describe Projects::CommitsController do
end
describe "GET show" do
- context "when the ref name ends in .atom" do
- render_views
+ render_views
+
+ context 'with file path' do
+ before do
+ get(:show,
+ namespace_id: project.namespace,
+ project_id: project,
+ id: id)
+ end
+
+ context "valid branch, valid file" do
+ let(:id) { 'master/README.md' }
+
+ it { is_expected.to respond_with(:success) }
+ end
+
+ context "valid branch, invalid file" do
+ let(:id) { 'master/invalid-path.rb' }
+ it { is_expected.to respond_with(:not_found) }
+ end
+
+ context "invalid branch, valid file" do
+ let(:id) { 'invalid-branch/README.md' }
+
+ it { is_expected.to respond_with(:not_found) }
+ end
+ end
+
+ context "when the ref name ends in .atom" do
context "when the ref does not exist with the suffix" do
it "renders as atom" do
get(:show,