Commit 414c4e3f authored by Bob Van Landuyt's avatar Bob Van Landuyt

Add helper methods to redirect legacy paths

parent 3a8cf276
---
title: Free up some reserved group names
merge_request: 15052
author:
type: other
......@@ -40,5 +40,14 @@ module Gitlab
def self.url_helpers
@url_helpers ||= Gitlab::Application.routes.url_helpers
end
def self.redirect_legacy_paths(router, *paths)
paths.each do |path|
router.match "/#{path}(/*rest)",
via: [:get, :post, :patch, :delete],
to: router.redirect { |_params, request| request.fullpath.gsub(%r{/#{path}/*}, "/-/#{path}/") },
as: "legacy_#{path}_redirect"
end
end
end
end
shared_examples 'redirecting a legacy path' do |source, target|
include RSpec::Rails::RequestExampleGroup
it "redirects #{source} to #{target} when the resource does not exist" do
expect(get(source)).to redirect_to(target)
end
it "does not redirect #{source} to #{target} when the resource exists" do
resource
expect(get(source)).not_to redirect_to(target)
end
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