2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 09:10:25 +08:00

Username validation in signup and username change forms

This commit is contained in:
Neil Lalonde 2013-02-07 18:23:41 -05:00
parent c524e769d0
commit 79dfccf717
8 changed files with 95 additions and 32 deletions

View file

@ -483,6 +483,24 @@ describe UsersController do
end
it_should_behave_like 'when username is unavailable locally'
end
context 'has invalid characters' do
before do
xhr :get, :check_username, username: 'bad username'
end
it 'should return success' do
response.should be_success
end
it 'should not return an available key' do
::JSON.parse(response.body)['available'].should be_nil
end
it 'should return an error message' do
::JSON.parse(response.body)['errors'].should_not be_empty
end
end
end
context 'when call_mothership is enabled' do

View file

@ -394,6 +394,20 @@ describe User do
end
end
context '.username_valid?' do
it 'returns true when username is both valid and available' do
User.username_valid?('Available').should be_true
end
it 'returns true when the username is valid but not available' do
User.username_valid?(Fabricate(:user).username).should be_true
end
it 'returns false when the username is not valid' do
User.username_valid?('not valid.name').should be_false
end
end
describe '.suggest_username' do
it 'corrects weird characters' do
User.suggest_username("Darth%^Vadar").should == "Darth_Vadar"