summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-10-26 16:06:51 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-11-07 19:52:09 +0100
commit414c4e3fd83a6a3cae623dcc8135d6ef09a30562 (patch)
treed084e53e0cc2bcfe994987511a8759068d002db2
parent3a8cf27674341e345bcbb823506f350849178ed7 (diff)
downloadgitlab-ce-414c4e3fd83a6a3cae623dcc8135d6ef09a30562.tar.gz
Add helper methods to redirect legacy paths
-rw-r--r--changelogs/unreleased/bvl-free-paths.yml5
-rw-r--r--lib/gitlab/routing.rb9
-rw-r--r--spec/support/legacy_path_redirect_shared_examples.rb13
3 files changed, 27 insertions, 0 deletions
diff --git a/changelogs/unreleased/bvl-free-paths.yml b/changelogs/unreleased/bvl-free-paths.yml
new file mode 100644
index 00000000000..f15459cc788
--- /dev/null
+++ b/changelogs/unreleased/bvl-free-paths.yml
@@ -0,0 +1,5 @@
+---
+title: Free up some reserved group names
+merge_request: 15052
+author:
+type: other
diff --git a/lib/gitlab/routing.rb b/lib/gitlab/routing.rb
index e57890f1143..abfd413b7ea 100644
--- a/lib/gitlab/routing.rb
+++ b/lib/gitlab/routing.rb
@@ -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
diff --git a/spec/support/legacy_path_redirect_shared_examples.rb b/spec/support/legacy_path_redirect_shared_examples.rb
new file mode 100644
index 00000000000..f300bdd48b1
--- /dev/null
+++ b/spec/support/legacy_path_redirect_shared_examples.rb
@@ -0,0 +1,13 @@
+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