allow for custom min_username_length

change constant in user to be global range and not default
This commit is contained in:
Stephen Birarda
2014-02-28 10:54:21 -08:00
parent b4688fc4c5
commit 4a2dab9c5e
4 changed files with 43 additions and 4 deletions

View File

@ -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