unreserved_username_validator_spec.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.nil?' 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.nil?' do
  19. let(:username) { '' }
  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, I18n.t('accounts.reserved_username'))
  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