mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Extract the validation of Username format in own class to avoid
complexity in user model object
This commit is contained in:
committed by
Neil Lalonde
parent
3ccfa645a8
commit
84191802df
@@ -193,7 +193,6 @@ describe User do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'new' do
|
||||
|
||||
subject { Fabricate.build(:user) }
|
||||
@@ -394,20 +393,6 @@ 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"
|
||||
|
||||
17
spec/models/username_validator_spec.rb
Normal file
17
spec/models/username_validator_spec.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe UsernameValidator do
|
||||
context "#valid_format?" do
|
||||
it 'returns true when username is both valid and available' do
|
||||
expect(UsernameValidator.new('Available').valid_format?).to eq true
|
||||
end
|
||||
|
||||
it 'returns true when the username is valid but not available' do
|
||||
expect(UsernameValidator.new(Fabricate(:user).username).valid_format?).to eq true
|
||||
end
|
||||
|
||||
it 'returns false when the username is not valid' do
|
||||
expect(UsernameValidator.new('not valid.name').valid_format?).to eq false
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user