diff options
author | ysksn <bluewhale1982@gmail.com> | 2018-12-29 15:22:51 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2018-12-29 07:22:51 +0100 |
commit | 4725aeec9f6d91d099e93ac13b3be8df5200e5e6 (patch) | |
tree | af814c1a9f029777cdef204ba3f47cd486e126a8 /app | |
parent | 0f938ff29c2e9bf92e3eb9c23be8d4ba3a1b97f7 (diff) |
Add specs for DisallowedHashtagsValidator (#9653)
In order to implement tests easier, `#select_tags` created.
Diffstat (limited to 'app')
-rw-r--r-- | app/validators/disallowed_hashtags_validator.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/app/validators/disallowed_hashtags_validator.rb b/app/validators/disallowed_hashtags_validator.rb index 22c027b0f..ee06b20f6 100644 --- a/app/validators/disallowed_hashtags_validator.rb +++ b/app/validators/disallowed_hashtags_validator.rb @@ -4,14 +4,19 @@ class DisallowedHashtagsValidator < ActiveModel::Validator def validate(status) return unless status.local? && !status.reblog? - tags = Extractor.extract_hashtags(status.text) - tags.keep_if { |tag| disallowed_hashtags.include? tag.downcase } + @status = status + tags = select_tags status.errors.add(:text, I18n.t('statuses.disallowed_hashtags', tags: tags.join(', '), count: tags.size)) unless tags.empty? end private + def select_tags + tags = Extractor.extract_hashtags(@status.text) + tags.keep_if { |tag| disallowed_hashtags.include? tag.downcase } + end + def disallowed_hashtags return @disallowed_hashtags if @disallowed_hashtags |