diff --git a/app/models/namespace.rb b/app/models/namespace.rb index a0d79d7e5c0..e1de114375e 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -59,6 +59,7 @@ class Namespace < ActiveRecord::Base end def clean_path(path) + path = path.dup path.gsub!(/@.*\z/, "") path.gsub!(/\.git\z/, "") path.gsub!(/\A-+/, "") diff --git a/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb b/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb index 7ce53c2a0d6..dc38b0eceb7 100644 --- a/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb +++ b/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb @@ -3,21 +3,21 @@ class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration class Namespace < ActiveRecord::Base class << self - def by_path(path) - where('lower(path) = :value', value: path.downcase).first + def find_by_path_or_name(path) + find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase) end def clean_path(path) path = path.dup path.gsub!(/@.*\z/, "") path.gsub!(/\.git\z/, "") - path.gsub!(/\A-/, "") - path.gsub!(/.\z/, "") + path.gsub!(/\A-+/, "") + path.gsub!(/\.+\z/, "") path.gsub!(/[^a-zA-Z0-9_\-\.]/, "") counter = 0 base = path - while Namespace.by_path(path).present? + while Namespace.find_by_path_or_name(path) counter += 1 path = "#{base}#{counter}" end