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.

44 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe UnreservedUsernameValidator, type: :validator do
  4. describe '#validate' do
  5. before do
  6. allow(validator).to receive(:reserved_username?) { reserved_username }
  7. validator.validate(account)
  8. end
  9. let(:validator) { described_class.new }
  10. let(:account) { double(username: username, errors: errors) }
  11. let(:errors ) { double(add: nil) }
  12. context '@username.blank?' do
  13. let(:username) { nil }
  14. it 'not calls errors.add' do
  15. expect(errors).not_to have_received(:add).with(:username, any_args)
  16. end
  17. end
  18. context '!@username.blank?' do
  19. let(:username) { 'f' }
  20. context 'reserved_username?' do
  21. let(:reserved_username) { true }
  22. it 'calls erros.add' do
  23. expect(errors).to have_received(:add).with(:username, :reserved)
  24. end
  25. end
  26. context '!reserved_username?' do
  27. let(:reserved_username) { false }
  28. it 'not calls erros.add' do
  29. expect(errors).not_to have_received(:add).with(:username, any_args)
  30. end
  31. end
  32. end
  33. end
  34. end