It looks like we can have some routes in routes.rb that we no loger use. Example in CI (possibly deprecated marked with leading 'x')L
ci_ci_api_api /ci/api Ci::API::APIci_lint POST /ci/lint(.:format) ci/lints#create GET /ci/lint(.:format) ci/lints#showstatus_ci_project GET /ci/projects/:id/status(.:format) ci/projects#badgex integration_ci_project GET /ci/projects/:id/integration(.:format) ci/projects#integrationci_projects GET /ci/projects(.:format) ci/projects#indexx POST /ci/projects(.:format) ci/projects#createx new_ci_project GET /ci/projects/new(.:format) ci/projects#newx edit_ci_project GET /ci/projects/:id/edit(.:format) ci/projects#editci_project GET /ci/projects/:id(.:format) ci/projects#showx PATCH /ci/projects/:id(.:format) ci/projects#updatex PUT /ci/projects/:id(.:format) ci/projects#updatex DELETE /ci/projects/:id(.:format) ci/projects#destroyci_root GET /ci(.:format) ci/projects#index`
It is possible that we have deprecated routes in other parts of GitLab than CI.
Designs
An error occurred while loading designs. Please try again.
Child items
0
Show closed items
GraphQL error: Variable $iid of type ID! was provided invalid value
No child items are currently open.
Linked items
0
Link issues together to show that they're related or that one is blocking others.
Learn more.
Alternatively one can use a traceroute gem to list the unused routes. To avoid new dependencies for the project that can be translated to the following script:
#!/usr/bin/env rubyrequire_relative'./config/environment.rb'classTraceroutedefinitialize(app)@app=appenddefload_everything!@app.eager_load!::Rails::InfoControllerrescueNameError::Rails::WelcomeControllerrescueNameError::Rails::MailersControllerrescueNameError@app.reload_routes!Rails::Engine.subclasses.each(&:eager_load!)enddefdefined_action_methodsActionController::Base.descendants.mapdo|controller|controller.action_methods.reject{|a|(a=~/\A(_conditional)?_callback_/)||(a=='_layout_from_proc')}.mapdo|action|"#{controller.controller_path}##{action}"endend.flatten.reject{|r|r.start_with?'rails/'}enddefrouted_actionsroutes.mapdo|r|ifr.requirements[:controller].blank?&&r.requirements[:action].blank?&&(r.path=='/:controller(/:action(/:id(.:format)))')%Q["#{r.path}" This is a legacy wild controller route that's not recommended for RESTful applications.]else"#{r.requirements[:controller]}##{r.requirements[:action]}"endend.reject{|r|r.start_with?'rails/'}endprivatedefroutesroutes=@app.routes.routes.reject{|r|r.name.nil?&&r.requirements.blank?}routes.reject!{|r|r.app.is_a?(ActionDispatch::Routing::Mapper::Constraints)&&r.app.app.respond_to?(:call)}routes.reject!{|r|r.app.is_a?(ActionDispatch::Routing::Redirect)}if@app.config.respond_to?(:assets)exclusion_regexp=%r{^#{@app.config.assets.prefix}}routes.reject!do|route|path=(defined?(ActionDispatch::Journey::Route)||defined?(Journey::Route))?route.path.spec.to_s:route.pathpath=~exclusion_regexpendendroutesendendtraceroute=Traceroute.newRails.applicationtraceroute.load_everything!defined_action_methods=traceroute.defined_action_methodsrouted_actions=traceroute.routed_actionsunused_routes=routed_actions-defined_action_methodsputs"Unused routes (#{unused_routes.count}):"unused_routes.each{|route|puts" #{route}"}unlessunused_routes.empty?||ENV['FAIL_ON_ERROR'].blank?fail"Unused routes detected."end
It's a bit more fancy but in our case giving the same results as snipped by Grzegorz.
Good catch, this one slipped through, probably because it was time to sleep.
I could improve the script to also check for Rails' default template (because Rails does not need method definition). And of course manual check (or Capybara?) is needed.