about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorysksn <bluewhale1982@gmail.com>2018-12-29 15:22:51 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-12-29 07:22:51 +0100
commit4725aeec9f6d91d099e93ac13b3be8df5200e5e6 (patch)
treeaf814c1a9f029777cdef204ba3f47cd486e126a8 /spec
parent0f938ff29c2e9bf92e3eb9c23be8d4ba3a1b97f7 (diff)
Add specs for DisallowedHashtagsValidator (#9653)
In order to implement tests easier, `#select_tags` created.
Diffstat (limited to 'spec')
-rw-r--r--spec/validators/disallowed_hashtags_validator_spec.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/validators/disallowed_hashtags_validator_spec.rb b/spec/validators/disallowed_hashtags_validator_spec.rb
new file mode 100644
index 000000000..8ec1302ab
--- /dev/null
+++ b/spec/validators/disallowed_hashtags_validator_spec.rb
@@ -0,0 +1,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