diff options
author | Stan Hu <stanhu@gmail.com> | 2016-04-05 22:16:15 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2016-04-05 22:16:15 +0000 |
commit | 779b9eac57cf45d77e4d62aa1b96e06928daa794 (patch) | |
tree | 5dbbf70b9f362db1aa8125b767d13241eb31fdd4 | |
parent | 74313988aca5de1e65940d311f0f87e9da1b93c2 (diff) | |
parent | 934f1e9097485bbaebbe2759e995c77bb4391c5d (diff) | |
download | gitlab-ce-779b9eac57cf45d77e4d62aa1b96e06928daa794.tar.gz |
Merge branch 'fix-project-path-rename' into 'master'
Fix Error 500 after renaming a project path
Renaming the path of a project would result in an Error 500 due to `@repository` being memoized with the old path. An Error 500 would result:
```
Started GET "/testing2/test1" for 127.0.0.1 at 2016-04-04 12:42:30 +0000
Processing by ProjectsController#show as HTML
Parameters: {"namespace_id"=>"testing2", "id"=>"test1"}
Completed 200 OK in 637ms (Views: 194.2ms | ActiveRecord: 111.8ms)
Started GET "/testing2/test1/edit" for 127.0.0.1 at 2016-04-04 12:42:33 +0000
Processing by ProjectsController#edit as HTML
Parameters: {"namespace_id"=>"testing2", "id"=>"test1"}
Completed 200 OK in 594ms (Views: 183.8ms | ActiveRecord: 87.4ms)
Started PATCH "/testing2/test1" for 127.0.0.1 at 2016-04-04 12:42:41 +0000
Processing by ProjectsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"[FILTERED]", "project"=>{"nam
e"=>"test123", "path"=>"test123"}, "namespace_id"=>"testing2", "id"=>"test1"}
Completed 500 Internal Server Error in 1852ms (ActiveRecord: 124.0ms)
ActionView::Template::Error (no repository for such path):
2: %legend
3: Builds:
4:
5: - unless @repository.gitlab_ci_yml
6: .form-group
7: .col-sm-offset-2.col-sm-10
8: %p Builds need to be configured before you can begin using Contin
uous Integration.
app/models/repository.rb:59:in `block in empty?'
lib/repository_cache.rb:19:in `fetch'
app/models/repository.rb:59:in `empty?'
app/models/repository.rb:471:in `gitlab_ci_yml'
app/views/projects/_builds_settings.html.haml:5:in `_app_views_projects__build
s_settings_html_haml__782034335636359229_73397600'
app/views/projects/edit.html.haml:87:in `block in _app_views_projects_edit_htm
l_haml___2388082585934859365_47390860'
app/views/projects/edit.html.haml:8:in `_app_views_projects_edit_html_haml___2
388082585934859365_47390860'
app/controllers/projects_controller.rb:54:in `block (2 levels) in update'
app/controllers/projects_controller.rb:43:in `update'
lib/gitlab/middleware/go.rb:16:in `call'
```
Closes #14885
See merge request !3528
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 3 | ||||
-rw-r--r-- | spec/controllers/projects_controller_spec.rb | 22 |
3 files changed, 27 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG index 63f80ce08ff..8db9a9b0d1e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,11 +3,12 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.7.0 (unreleased) - All images in discussions and wikis now link to their source files !3464 (Connor Shea). - Improved Markdown rendering performance !3389 (Yorick Peterse) - - Don't attempt to look up an avatar in repo if repo directory does not exist (Stan hu) + - Don't attempt to look up an avatar in repo if repo directory does not exist (Stan Hu) - Preserve time notes/comments have been updated at when moving issue - Make HTTP(s) label consistent on clone bar (Stan Hu) - Expose label description in API (Mariusz Jachimowicz) - Allow back dating on issues when created through the API + - Fix Error 500 after renaming a project path (Stan Hu) - Fix avatar stretching by providing a cropping feature - Add endpoints to archive or unarchive a project !3372 - Add links to CI setup documentation from project settings and builds pages diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 8c3a74c8236..3cc37e59855 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -40,6 +40,9 @@ class ProjectsController < Projects::ApplicationController def update status = ::Projects::UpdateService.new(@project, current_user, project_params).execute + # Refresh the repo in case anything changed + @repository = project.repository + respond_to do |format| if status flash[:notice] = "Project '#{@project.name}' was successfully updated." diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 1893e946f5c..069cd917e5a 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -83,6 +83,28 @@ describe ProjectsController do end end + describe "#update" do + render_views + + let(:admin) { create(:admin) } + + it "sets the repository to the right path after a rename" do + new_path = 'renamed_path' + project_params = { path: new_path } + controller.instance_variable_set(:@project, project) + sign_in(admin) + + put :update, + namespace_id: project.namespace.to_param, + id: project.id, + project: project_params + + expect(project.repository.path).to include(new_path) + expect(assigns(:repository).path).to eq(project.repository.path) + expect(response.status).to eq(200) + end + end + describe "#destroy" do let(:admin) { create(:admin) } |