unique_username_validator_spec.rb 831 B

12345678910111213141516171819202122232425
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe UniqueUsernameValidator do
  4. describe '#validate' do
  5. it 'does not add errors if username is nil' do
  6. account = double(username: nil, persisted?: false, errors: double(add: nil))
  7. subject.validate(account)
  8. expect(account.errors).to_not have_received(:add)
  9. end
  10. it 'does not add errors when existing one is subject itself' do
  11. account = Fabricate(:account, username: 'abcdef')
  12. expect(account).to be_valid
  13. end
  14. it 'adds an error when the username is already used with ignoring cases' do
  15. Fabricate(:account, username: 'ABCdef')
  16. account = double(username: 'abcDEF', persisted?: false, errors: double(add: nil))
  17. subject.validate(account)
  18. expect(account.errors).to have_received(:add)
  19. end
  20. end
  21. end