Add specs for DisallowedHashtagsValidator (#9653)
In order to implement tests easier, `#select_tags` created.
This commit is contained in:
parent
0f938ff29c
commit
4725aeec9f
2 changed files with 53 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue