Merge branch 'fix-protected-branches-routing' into 'master'
Fix protected branches routing
### Summary
On the master branch, if you attempt to access the protected branches in the project settings with an empty repo, you get `NoMethodError - undefined method "project_url"`.
### Steps to reproduce
1. Check out GitLab master and run.
2. Create a new project.
3. Go to Settings.
4. Click on "Protected branches"
### Expected behavior
The controller is supposed to redirect back to the projects page since there are no branches.
### Observed behavior
Internal Error 500
### Relevant logs
```
NoMethodError - undefined method `project_url' for #<Projects::ProtectedBranchesController:0x007fd920054af0>:
app/controllers/application_controller.rb:157:in `method_missing'
actionpack (4.1.9) lib/action_dispatch/routing/polymorphic_routes.rb:142:in `polymorphic_url'
actionpack (4.1.9) lib/action_dispatch/routing/url_for.rb:161:in `url_for'
actionpack (4.1.9) lib/action_controller/metal/redirecting.rb:91:in `_compute_redirect_to_location'
turbolinks (2.0.0) lib/turbolinks.rb:15:in `_compute_redirect_to_location_with_xhr_referer'
actionpack (4.1.9) lib/action_controller/metal/redirecting.rb:71:in `redirect_to
```
### Fix
I added a unit test for the empty project case and replicated the issue. I added the URL router helpers that appear to be necessary after 42387b733b.
See merge request !359
This commit is contained in:
commit
c530ca00b0
|
|
@ -28,4 +28,20 @@ module GitlabRoutingHelper
|
|||
def merge_request_path(entity, *args)
|
||||
namespace_project_merge_request_path(entity.project.namespace, entity.project, entity, *args)
|
||||
end
|
||||
|
||||
def project_url(project, *args)
|
||||
namespace_project_url(project.namespace, project, *args)
|
||||
end
|
||||
|
||||
def edit_project_url(project, *args)
|
||||
edit_namespace_project_url(project.namespace, project, *args)
|
||||
end
|
||||
|
||||
def issue_url(entity, *args)
|
||||
namespace_project_issue_url(entity.project.namespace, entity.project, entity, *args)
|
||||
end
|
||||
|
||||
def merge_request_url(entity, *args)
|
||||
namespace_project_merge_request_url(entity.project.namespace, entity.project, entity, *args)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
require('spec_helper')
|
||||
|
||||
describe Projects::ProtectedBranchesController do
|
||||
describe "GET #index" do
|
||||
let(:project) { create(:project_empty_repo, :public) }
|
||||
it "redirect empty repo to projects page" do
|
||||
get(:index, namespace_id: project.namespace.to_param, project_id: project.to_param)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue