Commit 9a631d31 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '19928-nomethoderror-undefined-method-id-for-nil-nilclass' into 'master'

Don't blow up in tree view on empty repo

## What does this MR do?

Stop the empty repo page blowing up with a 500 error when a user's default view is tree view.

## Are there points in the code the reviewer needs to double check?

Don't think so.

## Why was this MR needed?

https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4997 made sure that the `tree` filter was only called if the user's default project view is tree, but left out the empty repo check. When users visit an empty repo with the tree view as default, they now get a 500.

## What are the relevant issue numbers?

Closes #19928.

## Screenshots (if relevant)

## Does this MR meet the acceptance criteria?

- ~~[CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added~~ (bug introduced in same release)
- ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~
- ~~API support added~~
- Tests
  - ~~Added for this feature/bug~~
  - [ ] All builds are passing
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)


See merge request !5317
parent dfbc30ee
......@@ -5,7 +5,7 @@ class ProjectsController < Projects::ApplicationController
before_action :project, except: [:new, :create]
before_action :repository, except: [:new, :create]
before_action :assign_ref_vars, only: [:show], if: :repo_exists?
before_action :tree, only: [:show], if: :project_view_files?
before_action :tree, only: [:show], if: [:repo_exists?, :project_view_files?]
# Authorize
before_action :authorize_admin_project!, only: [:edit, :update, :housekeeping, :download_export, :export, :remove_export, :generate_new_export]
......
......@@ -43,6 +43,26 @@ describe ProjectsController do
end
end
context "project with empty repo" do
let(:empty_project) { create(:project_empty_repo, :public) }
before { sign_in(user) }
User.project_views.keys.each do |project_view|
context "with #{project_view} view set" do
before do
user.update_attributes(project_view: project_view)
get :show, namespace_id: empty_project.namespace.path, id: empty_project.path
end
it "renders the empty project view" do
expect(response).to render_template('empty')
end
end
end
end
context "rendering default project view" do
render_views
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment