闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.2 KiB

  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 dots' do
  15. pending 'allowing dots in username is still in development'
  16. Fabricate(:account, username: 'abcd.ef')
  17. account = double(username: 'ab.cdef', persisted?: false, errors: double(add: nil))
  18. subject.validate(account)
  19. expect(account.errors).to have_received(:add)
  20. end
  21. it 'adds an error when the username is already used with ignoring cases' do
  22. Fabricate(:account, username: 'ABCdef')
  23. account = double(username: 'abcDEF', persisted?: false, errors: double(add: nil))
  24. subject.validate(account)
  25. expect(account.errors).to have_received(:add)
  26. end
  27. end
  28. end