Browse Source

Use named vars

pull/394/head
baarkerlounger 3 years ago
parent
commit
d92ff60fbb
  1. 27
      spec/config/routes_spec.rb

27
spec/config/routes_spec.rb

@ -1,18 +1,23 @@
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("_") }
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
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
expect(routes_with_underscores).to be_empty
end
end

Loading…
Cancel
Save