The code powering m.abunchtell.com https://m.abunchtell.com
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

47 řádky
1.2 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe DisallowedHashtagsValidator, type: :validator do
  4. describe '#validate' do
  5. before do
  6. allow_any_instance_of(described_class).to receive(:select_tags) { tags }
  7. described_class.new.validate(status)
  8. end
  9. let(:status) { double(errors: errors, local?: local, reblog?: reblog, text: '') }
  10. let(:errors) { double(add: nil) }
  11. context 'unless status.local? && !status.reblog?' do
  12. let(:local) { false }
  13. let(:reblog) { true }
  14. it 'not calls errors.add' do
  15. expect(errors).not_to have_received(:add).with(:text, any_args)
  16. end
  17. end
  18. context 'status.local? && !status.reblog?' do
  19. let(:local) { true }
  20. let(:reblog) { false }
  21. context 'tags.empty?' do
  22. let(:tags) { [] }
  23. it 'not calls errors.add' do
  24. expect(errors).not_to have_received(:add).with(:text, any_args)
  25. end
  26. end
  27. context '!tags.empty?' do
  28. let(:tags) { %w(a b c) }
  29. it 'calls errors.add' do
  30. expect(errors).to have_received(:add)
  31. .with(:text, I18n.t('statuses.disallowed_hashtags', tags: tags.join(', '), count: tags.size))
  32. end
  33. end
  34. end
  35. end
  36. end