An apparently new test has identified a problem that I think I might have known I had, but had always ignored. Now I can’t ignore it because it now makes the tests fail. Here are my routes:
# frozen_string_literal: true
require_dependency "pfaffmanager_constraint"
Pfaffmanager::Engine.routes.draw do
get "/" => "pfaffmanager#index", :constraints => PfaffmanagerConstraint.new
get "/servers" => "servers#index", :constraints => PfaffmanagerConstraint.new
# get "#{root_path}/:username/messages/group/:group_name" => "user_actions#private_messages", constraints: { username: RouteFormat.username, group_name: RouteFormat.username }
get "/servers/group/:group_name" => "servers#index",
:constraints => PfaffmanagerConstraint.new
get "/find/:s" => "servers#index", :constraints => PfaffmanagerConstraint.new
get "/group/:group_name" => "servers#index",
:constraints => PfaffmanagerConstraint.new
get "/inventory/:group_name.json" => "servers#inventory",
:constraints => PfaffmanagerConstraint.new
get "/servers/:id" => "servers#show",
:constraints => PfaffmanagerConstraint.new
get "/servers/:id/edit" => "servers#edit",
:constraints => PfaffmanagerConstraint.new
put "/servers/:id" => "servers#update",
:constraints => PfaffmanagerConstraint.new
delete "/servers/:id" => "servers#delete",
:constraints => PfaffmanagerConstraint.new
put "/status/:id" => "servers#update_status",
:constraints => AdminConstraint.new
post "/api_key/:id" => "servers#set_api_key",
:constraints => PfaffmanagerConstraint.new
put "/update_server_status/:id" => "servers#update_server_status",
:constraints => PfaffmanagerConstraint.new
post "/upgrade/:id" => "servers#queue_upgrade",
:constraints => PfaffmanagerConstraint.new
put "/install/:id" => "servers#install",
:constraints => PfaffmanagerConstraint.new
get "/ssh_key/:id" => "serverkeys#get_pub_key"
get "/ssh-key/:hostname" => "serverkeys#get_pub_key_by_hostname",
:constraints => {
hostname: %r{[^/]+}
}
post "/servers" => "servers#create",
:constraints => PfaffmanagerConstraint.new
end
Discourse::Application.routes.append do
mount ::Pfaffmanager::Engine, at: "/pfaffmanager"
end
And it fails like this:
/home/pfaffman/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.0.7/lib/action_dispatch/routing/route_set.rb:588:in `add_route': Invalid route name, already in use: 'pfaffmana
ger' (ArgumentError)
You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restri
ct the routes created with `resources` as explained here:
https://guides.rubyonrails.org/routing.html#restricting-the-routes-created
raise ArgumentError, "Invalid route name, already in use: '#{name}' \n" \
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
from /home/pfaffman/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.0.7/lib/action_dispatch/routing/mapper.rb:1985:in `add_route'
from /home/pfaffman/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.0.7/lib/action_dispatch/routing/mapper.rb:1956:in `decomposed_match'