diff options
author | Timothy Andrew <mail@timothyandrew.net> | 2017-02-03 18:25:50 +0530 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2017-02-24 16:50:19 +0530 |
commit | ca16c3734b7b89f71bdc9e1c18152aa1599c4f89 (patch) | |
tree | c00010e64f210675c3a6c777f080aae51455934b /app/models/namespace.rb | |
parent | ff19bbd3b40621ae94632b9aa68fd12645b6ed41 (diff) | |
download | gitlab-ce-ca16c3734b7b89f71bdc9e1c18152aa1599c4f89.tar.gz |
Extract code from `Namespace#clean_path` for ghost user generation.
1. Create a `Uniquify` class, which generalizes the process of generating unique
strings, by accepting a function that defines what "uniqueness" means in a
given context.
2. WIP: Make sure tests for `Namespace` pass, add more if necessary.
3. WIP: Add tests for `Uniquify`
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r-- | app/models/namespace.rb | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb index bd0336c984a..8cc3c1473e2 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -98,14 +98,8 @@ class Namespace < ActiveRecord::Base # Work around that by setting their username to "blank", followed by a counter. path = "blank" if path.blank? - counter = 0 - base = path - while Namespace.find_by_path_or_name(path) - counter += 1 - path = "#{base}#{counter}" - end - - path + uniquify = Uniquify.new + uniquify.string(path, -> (s) { Namespace.find_by_path_or_name(s) }) end end |