From 379198e99a79da6dbf02e3e411f0cf1298dbc05f Mon Sep 17 00:00:00 2001 From: Waishnav Date: Sun, 21 Jul 2024 15:15:02 +0530 Subject: [PATCH] fix: test fails --- app/controllers/simple_discussion/forum_posts_controller.rb | 4 ++-- app/controllers/simple_discussion/forum_threads_controller.rb | 4 ++-- app/models/forum_post.rb | 2 +- app/models/forum_thread.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/simple_discussion/forum_posts_controller.rb b/app/controllers/simple_discussion/forum_posts_controller.rb index 4303e97..23e59e9 100644 --- a/app/controllers/simple_discussion/forum_posts_controller.rb +++ b/app/controllers/simple_discussion/forum_posts_controller.rb @@ -13,7 +13,7 @@ def create SimpleDiscussion::ForumPostNotificationJob.perform_later(@forum_post) redirect_to simple_discussion.forum_thread_path(@forum_thread, anchor: "forum_post_#{@forum_post.id}") else - render template: "simple_discussion/forum_threads/show" + render template: "simple_discussion/forum_threads/show", status: :unprocessable_entity end end @@ -24,7 +24,7 @@ def update if @forum_post.update(forum_post_params) redirect_to simple_discussion.forum_thread_path(@forum_thread) else - render action: :edit + render action: :edit, status: :unprocessable_entity end end diff --git a/app/controllers/simple_discussion/forum_threads_controller.rb b/app/controllers/simple_discussion/forum_threads_controller.rb index d7e5bf0..6edc92d 100644 --- a/app/controllers/simple_discussion/forum_threads_controller.rb +++ b/app/controllers/simple_discussion/forum_threads_controller.rb @@ -45,7 +45,7 @@ def create SimpleDiscussion::ForumThreadNotificationJob.perform_later(@forum_thread) redirect_to simple_discussion.forum_thread_path(@forum_thread) else - render action: :new + render action: :new, status: :unprocessable_entity end end @@ -56,7 +56,7 @@ def update if @forum_thread.update(forum_thread_params) redirect_to simple_discussion.forum_thread_path(@forum_thread), notice: I18n.t("your_changes_were_saved") else - render action: :edit + render action: :edit, status: :unprocessable_entity end end diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 5ea5b62..64fc95e 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -2,8 +2,8 @@ class ForumPost < ApplicationRecord belongs_to :forum_thread, counter_cache: true, touch: true belongs_to :user - before_validation :clean_body, if: -> { SimpleDiscussion.profanity_filter } validates :user_id, :body, presence: true + validate :clean_body, if: -> { SimpleDiscussion.profanity_filter } scope :sorted, -> { order(:created_at) } diff --git a/app/models/forum_thread.rb b/app/models/forum_thread.rb index 63f2d9c..88b3b0a 100644 --- a/app/models/forum_thread.rb +++ b/app/models/forum_thread.rb @@ -16,7 +16,7 @@ class ForumThread < ApplicationRecord validates :user_id, :title, presence: true validates_associated :forum_posts - before_validation :clean_title, if: -> { SimpleDiscussion.profanity_filter } + validate :clean_title, if: -> { SimpleDiscussion.profanity_filter } scope :pinned_first, -> { order(pinned: :desc) } scope :solved, -> { where(solved: true) }