1 changed files with 16 additions and 11 deletions
@ -1,18 +1,23 @@ |
|||||||
require "rails_helper" |
require "rails_helper" |
||||||
|
|
||||||
RSpec.describe "routes.rb" do |
RSpec.describe "routes.rb" do |
||||||
it "does not use underscores" do |
let(:all_routes) do |
||||||
paths = Rails.application.routes.routes.map { |r| r.path.spec.to_s if r.defaults[:controller] }.compact |
Rails.application.routes.routes.map { |r| r.path.spec.to_s if r.defaults[:controller] }.compact |
||||||
|
end |
||||||
# Allow underscores for ActiveAdmin, Rails and Turbo routes |
let(:active_admin_routes_prefix) { "/admin" } |
||||||
paths = paths.reject { |p| p.starts_with?("/admin") } |
let(:rails_routes_prefix) { "/rails" } |
||||||
paths = paths.reject { |p| p.starts_with?("/rails") } |
let(:turbo_routes_pattern) { "_historical_location" } |
||||||
paths = paths.reject { |p| p.include?("_historical_location") } |
let(:project_routes) do |
||||||
|
all_routes.reject do |r| |
||||||
paths.each do |path| |
r.starts_with?(active_admin_routes_prefix) || r.starts_with?(rails_routes_prefix) || |
||||||
has_underscores = path.split("/").any? { |component| !component.start_with?(":") && component.match("_") } |
r.include?(turbo_routes_pattern) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
expect(has_underscores).to be(false), "#{path} should not have underscores" |
it "does not use underscores" do |
||||||
|
routes_with_underscores = project_routes.select do |r| |
||||||
|
r.split("/").any? { |component| !component.start_with?(":") && component.match("_") } |
||||||
end |
end |
||||||
|
expect(routes_with_underscores).to be_empty |
||||||
end |
end |
||||||
end |
end |
||||||
|
Loading…
Reference in new issue