Commit 45e8fb07 authored by Rajendra Kadam's avatar Rajendra Kadam Committed by Peter Leitzen

Fix leaky constant issue in path regex spec

parent 3be73a7e
......@@ -361,7 +361,6 @@ RSpec/LeakyConstantDeclaration:
- 'spec/lib/gitlab/git/diff_collection_spec.rb'
- 'spec/lib/gitlab/import_export/import_test_coverage_spec.rb'
- 'spec/lib/gitlab/import_export/project/relation_factory_spec.rb'
- 'spec/lib/gitlab/path_regex_spec.rb'
- 'spec/lib/gitlab/quick_actions/dsl_spec.rb'
- 'spec/lib/marginalia_spec.rb'
- 'spec/mailers/notify_spec.rb'
......
---
title: Fix leaky constant issue in path regex spec
merge_request: 32115
author: Rajendra Kadam
type: fixed
......@@ -3,6 +3,11 @@
require 'spec_helper'
describe Gitlab::PathRegex do
let(:starting_with_namespace) { %r{^/\*namespace_id/:(project_)?id} }
let(:non_param_parts) { %r{[^:*][a-z\-_/]*} }
let(:any_other_path_part) { %r{[a-z\-_/:]*} }
let(:wildcard_segment) { /\*/ }
# Pass in a full path to remove the format segment:
# `/ci/lint(.:format)` -> `/ci/lint`
def without_format(path)
......@@ -14,7 +19,7 @@ describe Gitlab::PathRegex do
# `/*namespace_id/:project_id/builds/artifacts/*ref_name_and_path`
# -> 'builds/artifacts'
def path_before_wildcard(path)
path = path.gsub(STARTING_WITH_NAMESPACE, "")
path = path.gsub(starting_with_namespace, "")
path_segments = path.split('/').reject(&:empty?)
wildcard_index = path_segments.index { |segment| parameter?(segment) }
......@@ -121,13 +126,9 @@ describe Gitlab::PathRegex do
# - Followed by one or more path-parts not starting with `:` or `*`
# - Followed by a path-part that includes a wildcard parameter `*`
# At the time of writing these routes match: http://rubular.com/r/Rv2pDE5Dvw
STARTING_WITH_NAMESPACE = %r{^/\*namespace_id/:(project_)?id}.freeze
NON_PARAM_PARTS = %r{[^:*][a-z\-_/]*}.freeze
ANY_OTHER_PATH_PART = %r{[a-z\-_/:]*}.freeze
WILDCARD_SEGMENT = /\*/.freeze
let(:namespaced_wildcard_routes) do
routes_without_format.select do |p|
p =~ %r{#{STARTING_WITH_NAMESPACE}/#{NON_PARAM_PARTS}/#{ANY_OTHER_PATH_PART}#{WILDCARD_SEGMENT}}
p =~ %r{#{starting_with_namespace}/#{non_param_parts}/#{any_other_path_part}#{wildcard_segment}}
end
end
......@@ -145,16 +146,14 @@ describe Gitlab::PathRegex do
end.uniq
end
STARTING_WITH_GROUP = %r{^/groups/\*(group_)?id/}.freeze
let(:starting_with_group) { %r{^/groups/\*(group_)?id/} }
let(:group_routes) do
routes_without_format.select do |path|
path =~ STARTING_WITH_GROUP
end
routes_without_format.grep(starting_with_group)
end
let(:paths_after_group_id) do
group_routes.map do |route|
route.gsub(STARTING_WITH_GROUP, '').split('/').first
route.gsub(starting_with_group, '').split('/').first
end.uniq
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment