From 7f07b770eea2cb5b87deca5cbf0dfcb8bf23c6b8 Mon Sep 17 00:00:00 2001 From: manojmj Date: Wed, 1 Jul 2020 12:26:21 +0530 Subject: [PATCH] Create associated routes when a new bot user is created This change creates the associated routes when a new bot user is created --- app/models/concerns/routable.rb | 9 ++++----- changelogs/unreleased/fix-routes-for-internal-users.yml | 5 +++++ spec/models/user_spec.rb | 6 ++++++ 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 changelogs/unreleased/fix-routes-for-internal-users.yml diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb index 129d0fbb2c059c..c70ce9bebccc16 100644 --- a/app/models/concerns/routable.rb +++ b/app/models/concerns/routable.rb @@ -17,11 +17,8 @@ module Routable after_validation :set_path_errors - before_validation do - if full_path_changed? || full_name_changed? - prepare_route - end - end + before_validation :prepare_route + before_save :prepare_route # in case validation is skipped end class_methods do @@ -118,6 +115,8 @@ def build_full_name end def prepare_route + return unless full_path_changed? || full_name_changed? + route || build_route(source: self) route.path = build_full_path route.name = build_full_name diff --git a/changelogs/unreleased/fix-routes-for-internal-users.yml b/changelogs/unreleased/fix-routes-for-internal-users.yml new file mode 100644 index 00000000000000..5f96dd7f227b4f --- /dev/null +++ b/changelogs/unreleased/fix-routes-for-internal-users.yml @@ -0,0 +1,5 @@ +--- +title: Create associated routes when a new bot user is created +merge_request: 35711 +author: +type: fixed diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 01a908a34d7fb3..c071275539675f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -4766,6 +4766,12 @@ def access_levels(groups) end.to change { User.where(user_type: bot_type).count }.by(1) end + it 'creates a route for the namespace of the created user' do + bot_user = described_class.public_send(bot_type) + + expect(bot_user.namespace.route).to be_present + end + it 'does not create a new user if it already exists' do described_class.public_send(bot_type) -- GitLab