Browse Source

Outlaw underscores in URLs

pull/394/head
Paul Robert Lloyd 3 years ago
parent
commit
25d497cc4b
  1. 3
      config/routes.rb
  2. 18
      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 Rails.application.routes.draw do
devise_for :admin_users, { devise_for :admin_users, {
path: :admin, path: :admin,
@ -28,12 +29,10 @@ Rails.application.routes.draw do
get "/health", to: ->(_) { [204, {}, [nil]] } get "/health", to: ->(_) { [204, {}, [nil]] }
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
ActiveAdmin.routes(self) ActiveAdmin.routes(self)
root to: "start#index" root to: "start#index"
# Content pages
get "/accessibility-statement", to: "content#accessibility_statement" get "/accessibility-statement", to: "content#accessibility_statement"
get "/privacy-notice", to: "content#privacy_notice" get "/privacy-notice", to: "content#privacy_notice"

18
spec/config/routes_spec.rb

@ -0,0 +1,18 @@
require "rails_helper"
RSpec.describe "routes.rb" do
it "does not use underscores" do
paths = Rails.application.routes.routes.map { |r| r.path.spec.to_s if r.defaults[:controller] }.compact
# Allow underscores for ActiveAdmin, Rails and Turbo routes
paths = paths.reject { |p| p.starts_with?("/admin") }
paths = paths.reject { |p| p.starts_with?("/rails") }
paths = paths.reject { |p| p.include?("_historical_location") }
paths.each do |path|
has_underscores = path.split("/").any? { |component| !component.start_with?(":") && component.match("_") }
expect(has_underscores).to be(false), "#{path} should not have underscores"
end
end
end
Loading…
Cancel
Save