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