diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index d15da0dcf..41a475371 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -44,7 +44,14 @@ class ForumTopicsController < ApplicationController def destroy @forum_topic = ForumTopic.find(params[:id]) check_privilege(@forum_topic) - @forum_topic.destroy + @forum_topic.update_attribute(:is_deleted, true) + respond_with(@forum_topic) + end + + def undelete + @forum_topic = ForumTopic.find(params[:id]) + check_privilege(@forum_topic) + @forum_topic.update_attribute(:is_deleted, false) respond_with(@forum_topic) end diff --git a/test/functional/forum_posts_controller_test.rb b/test/functional/forum_posts_controller_test.rb index ebf099a06..9fc007c98 100644 --- a/test/functional/forum_posts_controller_test.rb +++ b/test/functional/forum_posts_controller_test.rb @@ -76,10 +76,23 @@ class ForumPostsControllerTest < ActionController::TestCase context "destroy action" do should "destroy the posts" do - assert_difference("ForumPost.count", -1) do - post :destroy, {:id => @forum_post.id}, {:user_id => @user.id} - end - assert_redirected_to(forum_posts_path) + post :destroy, {:id => @forum_post.id}, {:user_id => @user.id} + assert_redirected_to(forum_post_path(@forum_post)) + @forum_post.reload + assert_equal(true, @forum_post.is_deleted?) + end + end + + context "undelete action" do + setup do + @forum_post.update_attribute(:is_deleted, true) + end + + should "restore the post" do + post :undelete, {:id => @forum_post.id}, {:user_id => @user.id} + assert_redirected_to(forum_post_path(@forum_post)) + @forum_post.reload + assert_equal(false, @forum_post.is_deleted?) end end end diff --git a/test/functional/forum_topics_controller_test.rb b/test/functional/forum_topics_controller_test.rb index d9a50a0cb..8bb3756c8 100644 --- a/test/functional/forum_topics_controller_test.rb +++ b/test/functional/forum_topics_controller_test.rb @@ -79,10 +79,23 @@ class ForumTopicsControllerTest < ActionController::TestCase end should "destroy the topic and any associated posts" do - assert_difference(["ForumPost.count", "ForumTopic.count"], -1) do - post :destroy, {:id => @forum_topic.id}, {:user_id => @user.id} - end - assert_redirected_to(forum_topics_path) + post :destroy, {:id => @forum_topic.id}, {:user_id => @user.id} + assert_redirected_to(forum_topic_path(@forum_topic)) + @forum_topic.reload + assert_equal(true, @forum_topic.is_deleted?) + end + end + + context "undelete action" do + setup do + @forum_topic.update_attribute(:is_deleted, true) + end + + should "restore the topic" do + post :undelete, {:id => @forum_topic.id}, {:user_id => @user.id} + assert_redirected_to(forum_topic_path(@forum_topic)) + @forum_topic.reload + assert_equal(false, @forum_topic.is_deleted?) end end end