Commit 50976c6f authored by Lin Jen-Shin's avatar Lin Jen-Shin

Allow CE do nothing if route doesn't exist

parent f4d06fad
......@@ -338,13 +338,14 @@ When we add `draw :admin` in `config/routes.rb`, the application will try to
load the file located in `config/routes/admin.rb`, and also try to load the
file located in `ee/config/routes/admin.rb`.
It should at least load one file, at most two files. If it cannot find any
files, an error will be raised.
In EE, it should at least load one file, at most two files. If it cannot find
any files, an error will be raised. In CE, since we don't know if there will
be an EE route, it will not raise any errors even if it cannot find anything.
This means if we want to extend a particular CE route file, just add the same
file located in `ee/config/routes`. If we want to add an EE only route, we
could still use `draw :ee_only` and add `ee/config/routes/ee_only.rb` without
adding `config/routes/ee_only.rb`.
could still put `draw :ee_only` in both CE and EE, and add
`ee/config/routes/ee_only.rb` in EE, similar to `render_if_exists`.
### Code in `app/controllers/`
......
# frozen_string_literal: true
namespace :oauth do
scope path: 'geo', controller: :geo_auth, as: :geo do
get 'auth'
......
# frozen_string_literal: true
module EE
module Gitlab
module Patch
module DrawRoute
extend ::Gitlab::Utils::Override
override :draw_ee
def draw_ee(routes_name)
draw_route(route_path("ee/config/routes/#{routes_name}.rb"))
end
end
end
end
end
......@@ -39,4 +39,9 @@ describe Gitlab::Patch::DrawRoute do
.with(File.read(subject.route_path('ee/config/routes/admin.rb')))
.once
end
it 'raises an error when nothing is drawn' do
expect { subject.draw(:non_existing) }
.to raise_error(described_class::RoutesNotFound)
end
end
......@@ -5,6 +5,8 @@
module Gitlab
module Patch
module DrawRoute
prepend EE::Gitlab::Patch::DrawRoute
RoutesNotFound = Class.new(StandardError)
def draw(routes_name)
......@@ -16,8 +18,8 @@ module Gitlab
draw_route(route_path("config/routes/#{routes_name}.rb"))
end
def draw_ee(routes_name)
draw_route(route_path("ee/config/routes/#{routes_name}.rb"))
def draw_ee(_)
true
end
def route_path(routes_name)
......
......@@ -8,3 +8,4 @@ require_relative 'support/rspec'
require 'active_support/all'
ActiveSupport::Dependencies.autoload_paths << 'lib'
ActiveSupport::Dependencies.autoload_paths << 'ee/lib'
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