Browse Source

Outlaw underscores in URLs (#394)

* Outlaw underscores in URLs

* Use named vars

Co-authored-by: baarkerlounger <db@slothlife.xyz>
pull/395/head
Paul Robert Lloyd 3 years ago committed by GitHub
parent
commit
956aad0998
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      config/routes.rb
  2. 23
      spec/config/routes_spec.rb

3
config/routes.rb

@ -1,3 +1,4 @@
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
Rails.application.routes.draw do
devise_for :admin_users, {
path: :admin,
@ -28,12 +29,10 @@ Rails.application.routes.draw do
get "/health", to: ->(_) { [204, {}, [nil]] }
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
ActiveAdmin.routes(self)
root to: "start#index"
# Content pages
get "/accessibility-statement", to: "content#accessibility_statement"
get "/privacy-notice", to: "content#privacy_notice"

23
spec/config/routes_spec.rb

@ -0,0 +1,23 @@
require "rails_helper"
RSpec.describe "routes.rb" do
let(:all_routes) do
Rails.application.routes.routes.map { |r| r.path.spec.to_s if r.defaults[:controller] }.compact
end
let(:active_admin_routes_prefix) { "/admin" }
let(:rails_routes_prefix) { "/rails" }
let(:turbo_routes_pattern) { "_historical_location" }
let(:project_routes) do
all_routes.reject do |r|
r.starts_with?(active_admin_routes_prefix) || r.starts_with?(rails_routes_prefix) ||
r.include?(turbo_routes_pattern)
end
end
it "does not use underscores" do
routes_with_underscores = project_routes.select do |r|
r.split("/").any? { |component| !component.start_with?(":") && component.match("_") }
end
expect(routes_with_underscores).to be_empty
end
end
Loading…
Cancel
Save