闭社主体 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.

25 lines
831 B

  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