mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 01:55:46 +08:00
allow for custom min_username_length
change constant in user to be global range and not default
This commit is contained in:
@ -174,7 +174,35 @@ describe User do
|
||||
myself.reload.username.should == 'HanSolo'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'allow custom minimum username length from site settings' do
|
||||
before do
|
||||
@custom_min = User::GLOBAL_USERNAME_LENGTH_RANGE.begin - 1
|
||||
SiteSetting.stubs("min_username_length").returns(@custom_min)
|
||||
end
|
||||
|
||||
it 'should allow a shorter username than default' do
|
||||
result = user.change_username('a' * @custom_min)
|
||||
result.should_not be_false
|
||||
end
|
||||
|
||||
it 'should not allow a shorter username than limit' do
|
||||
result = user.change_username('a' * (@custom_min - 1))
|
||||
result.should be_false
|
||||
end
|
||||
|
||||
it 'should not allow a longer username than limit' do
|
||||
result = user.change_username('a' * (User::GLOBAL_USERNAME_LENGTH_RANGE.end + 1))
|
||||
result.should be_false
|
||||
end
|
||||
|
||||
it 'should use default length for validation if enforce_global_nicknames is true' do
|
||||
SiteSetting.stubs('enforce_global_nicknames').returns(true)
|
||||
|
||||
User::username_length.begin.should == User::GLOBAL_USERNAME_LENGTH_RANGE.begin
|
||||
User::username_length.end.should == User::GLOBAL_USERNAME_LENGTH_RANGE.end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'delete posts' do
|
||||
@ -422,7 +450,7 @@ describe User do
|
||||
end
|
||||
|
||||
describe 'username format' do
|
||||
it "should always be 3 chars or longer" do
|
||||
it "should be #{SiteSetting.min_username_length} chars or longer" do
|
||||
@user = Fabricate.build(:user)
|
||||
@user.username = 'ss'
|
||||
@user.save.should == false
|
||||
|
Reference in New Issue
Block a user