fixes #2110
This commit is contained in:
@@ -55,14 +55,14 @@ class ForumPostsController < ApplicationController
|
|||||||
def destroy
|
def destroy
|
||||||
@forum_post = ForumPost.find(params[:id])
|
@forum_post = ForumPost.find(params[:id])
|
||||||
check_privilege(@forum_post)
|
check_privilege(@forum_post)
|
||||||
@forum_post.update_column(:is_deleted, true)
|
@forum_post.delete!
|
||||||
respond_with(@forum_post)
|
respond_with(@forum_post)
|
||||||
end
|
end
|
||||||
|
|
||||||
def undelete
|
def undelete
|
||||||
@forum_post = ForumPost.find(params[:id])
|
@forum_post = ForumPost.find(params[:id])
|
||||||
check_privilege(@forum_post)
|
check_privilege(@forum_post)
|
||||||
@forum_post.update_attribute(:is_deleted, false)
|
@forum_post.undelete!
|
||||||
respond_with(@forum_post)
|
respond_with(@forum_post)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -119,8 +119,18 @@ class ForumPost < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete!
|
||||||
|
update_attribute(:is_deleted, true)
|
||||||
|
update_topic_updated_at_on_destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
def undelete!
|
||||||
|
update_attribute(:is_deleted, true)
|
||||||
|
update_topic_updated_at_on_create
|
||||||
|
end
|
||||||
|
|
||||||
def update_topic_updated_at_on_destroy
|
def update_topic_updated_at_on_destroy
|
||||||
max = ForumPost.where(:topic_id => topic.id).maximum(:updated_at)
|
max = ForumPost.where(:topic_id => topic.id, :is_deleted => false).maximum(:updated_at)
|
||||||
if max
|
if max
|
||||||
ForumTopic.update_all(["response_count = response_count - 1, updated_at = ?", max], {:id => topic.id})
|
ForumTopic.update_all(["response_count = response_count - 1, updated_at = ?", max], {:id => topic.id})
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -26,6 +26,16 @@ class ForumPostTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "that is deleted" do
|
||||||
|
should "update the topic's updated_at timestamp" do
|
||||||
|
@topic.reload
|
||||||
|
assert_equal(@posts[-1].updated_at.to_i, @topic.updated_at.to_i)
|
||||||
|
@posts[-1].delete!
|
||||||
|
@topic.reload
|
||||||
|
assert_equal(@posts[-2].updated_at.to_i, @topic.updated_at.to_i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
should "know which page it's on" do
|
should "know which page it's on" do
|
||||||
assert_equal(2, @posts[3].forum_topic_page)
|
assert_equal(2, @posts[3].forum_topic_page)
|
||||||
assert_equal(2, @posts[4].forum_topic_page)
|
assert_equal(2, @posts[4].forum_topic_page)
|
||||||
@@ -102,7 +112,7 @@ class ForumPostTest < ActiveSupport::TestCase
|
|||||||
context "that is deleted" do
|
context "that is deleted" do
|
||||||
setup do
|
setup do
|
||||||
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
|
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
|
||||||
@post.update_attribute(:is_deleted, true)
|
@post.delete!
|
||||||
@topic.reload
|
@topic.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user