Fix the build.

This commit is contained in:
Guo Xiang Tan 2016-01-27 16:04:11 +08:00
parent 1bb485fca5
commit 0916007d01
2 changed files with 10 additions and 3 deletions

View File

@ -1,4 +1,5 @@
module UserNameSuggester module UserNameSuggester
GENERIC_NAMES = ['i', 'me', 'info', 'support', 'admin', 'webmaster', 'hello', 'mail', 'office', 'contact', 'team']
def self.suggest(name, allow_username = nil) def self.suggest(name, allow_username = nil)
return unless name.present? return unless name.present?
@ -11,7 +12,7 @@ module UserNameSuggester
# When 'walter@white.com' take 'walter' # When 'walter@white.com' take 'walter'
name = Regexp.last_match[1] name = Regexp.last_match[1]
# When 'me@eviltrout.com' take 'eviltrout' # When 'me@eviltrout.com' take 'eviltrout'
name = Regexp.last_match[2] if ['i', 'me', 'info', 'support', 'admin', 'webmaster', 'hello', 'mail', 'office', 'contact', 'team'].include?(name) name = Regexp.last_match[2] if GENERIC_NAMES.include?(name)
end end
name name
end end

View File

@ -50,11 +50,17 @@ describe UserNameSuggester do
end end
it "doesn't suggest reserved usernames" do it "doesn't suggest reserved usernames" do
SiteSetting.reserved_usernames = 'admin|steve|steve1' SiteSetting.reserved_usernames = 'myadmin|steve|steve1'
expect(UserNameSuggester.suggest("admin@hissite.com")).to eq('admin1') expect(UserNameSuggester.suggest("myadmin@hissite.com")).to eq('myadmin1')
expect(UserNameSuggester.suggest("steve")).to eq('steve2') expect(UserNameSuggester.suggest("steve")).to eq('steve2')
end end
it "doesn't suggest generic usernames" do
UserNameSuggester::GENERIC_NAMES.each do |name|
expect(UserNameSuggester.suggest("#{name}@apple.org")).to eq('apple')
end
end
it "removes leading character if it is not alphanumeric" do it "removes leading character if it is not alphanumeric" do
expect(UserNameSuggester.suggest(".myname")).to eq('myname') expect(UserNameSuggester.suggest(".myname")).to eq('myname')
end end