diff --git a/app/components/debates/form_component.html.erb b/app/components/debates/form_component.html.erb
index b469e6792..f7d1b2098 100644
--- a/app/components/debates/form_component.html.erb
+++ b/app/components/debates/form_component.html.erb
@@ -18,11 +18,6 @@
<%= translations_form.text_area :description,
maxlength: Debate.description_max_length,
class: "html-area" %>
- <% if @debate.errors.present? && locale == translations_form.locale %>
-
- <%= @debate.errors[:description][0] %>
-
- <% end %>
<% end %>
diff --git a/app/models/debate.rb b/app/models/debate.rb
index ce034693f..5341197f7 100644
--- a/app/models/debate.rb
+++ b/app/models/debate.rb
@@ -30,7 +30,7 @@ class Debate < ApplicationRecord
validates_translation :title, presence: true, length: { in: 4..Debate.title_max_length }
validates_translation :description, presence: true
- validate :description_sanitized
+ validate :description_length
validates :author, presence: true
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
@@ -164,13 +164,17 @@ class Debate < ApplicationRecord
orders
end
- def description_sanitized
+ def description_length
real_description_length = ActionView::Base.full_sanitizer.sanitize(description.to_s).squish.length
+
if real_description_length < Debate.description_min_length
errors.add(:description, :too_short, count: Debate.description_min_length)
+ translation.errors.add(:description, :too_short, count: Debate.description_min_length)
end
+
if real_description_length > Debate.description_max_length
errors.add(:description, :too_long, count: Debate.description_max_length)
+ translation.errors.add(:description, :too_long, count: Debate.description_max_length)
end
end
end
diff --git a/spec/system/debates_spec.rb b/spec/system/debates_spec.rb
index 956782b81..6e61163af 100644
--- a/spec/system/debates_spec.rb
+++ b/spec/system/debates_spec.rb
@@ -247,6 +247,18 @@ describe "Debates" do
expect(page).to have_content error_message
end
+ scenario "Short description errors" do
+ login_as(create(:user))
+
+ visit new_debate_path
+ fill_in_ckeditor "Initial debate text", with: "Go!"
+ click_button "Start a debate"
+
+ within ".form-error.html-area" do
+ expect(page).to have_content "is too short"
+ end
+ end
+
scenario "JS injection is prevented but safe html is respected", :no_js do
author = create(:user)
login_as(author)