Skip to content

Commit 5d7b005

Browse files
committed
Improve implementations with suggestions
1 parent 3bae074 commit 5d7b005

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

app/models/concerns/post_validations.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module PostValidations
88
validate :maximum_tag_length, if: -> { post_type.has_tags }
99
validate :no_spaces_in_tags, if: -> { post_type.has_tags }
1010
validate :stripped_minimum_body, if: -> { !body_markdown.nil? }
11-
validate :stripped_minimum_title, if: -> { !title.nil? && !['HelpDoc', 'PolicyDoc'].include?(post_type.name) }
11+
validate :stripped_minimum_title, if: -> { !title.nil? }
1212
validate :maximum_title_length, if: -> { !title.nil? }
1313
validate :required_tags?, if: -> { post_type.has_tags && post_type.has_category }
1414
end
@@ -46,7 +46,14 @@ def stripped_minimum_body
4646
end
4747

4848
def stripped_minimum_title
49-
min_title = category.nil? ? 15 : category.min_title_length
49+
min_title = if ['HelpDoc', 'PolicyDoc'].include?(post_type.name)
50+
1
51+
elsif category.nil?
52+
15
53+
else
54+
category.min_title_length
55+
end
56+
5057
if (title&.gsub(/(?:^[\s\t\u2000-\u200F]+|[\s\t\u2000-\u200F]+$)/, '')&.length || 0) < min_title
5158
errors.add(:title, "must be more than #{min_title} non-whitespace characters long")
5259
end

0 commit comments

Comments
 (0)