The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

49 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe DisallowedHashtagsValidator, type: :validator do
  4. let(:disallowed_tags) { [] }
  5. describe '#validate' do
  6. before do
  7. disallowed_tags.each { |name| Fabricate(:tag, name: name, usable: false) }
  8. described_class.new.validate(status)
  9. end
  10. let(:status) { double(errors: errors, local?: local, reblog?: reblog, text: disallowed_tags.map { |x| '#' + x }.join(' ')) }
  11. let(:errors) { double(add: nil) }
  12. context 'for a remote reblog' do
  13. let(:local) { false }
  14. let(:reblog) { true }
  15. it 'does not add errors' do
  16. expect(errors).not_to have_received(:add).with(:text, any_args)
  17. end
  18. end
  19. context 'for a local original status' do
  20. let(:local) { true }
  21. let(:reblog) { false }
  22. context 'when does not contain any disallowed hashtags' do
  23. let(:disallowed_tags) { [] }
  24. it 'does not add errors' do
  25. expect(errors).not_to have_received(:add).with(:text, any_args)
  26. end
  27. end
  28. context 'when contains disallowed hashtags' do
  29. let(:disallowed_tags) { %w(a b c) }
  30. it 'adds an error' do
  31. expect(errors).to have_received(:add)
  32. .with(:text, I18n.t('statuses.disallowed_hashtags', tags: disallowed_tags.join(', '), count: disallowed_tags.size))
  33. end
  34. end
  35. end
  36. end
  37. end