This commit is contained in:
albert
2013-03-17 20:56:34 -04:00
parent 781bfcef3c
commit 69607c0ea8
4 changed files with 23 additions and 2 deletions

View File

@@ -47,7 +47,7 @@ class ForumPostsController < ApplicationController
def destroy
@forum_post = ForumPost.find(params[:id])
raise User::PrivilegeError unless CurrentUser.is_janitor?
raise User::PrivilegeError unless @forum_post.editable_by?(CurrentUser.user)
@forum_post.update_attribute(:is_deleted, true)
respond_with(@forum_post)
end

View File

@@ -10,6 +10,7 @@ class ForumPost < ActiveRecord::Base
validates_presence_of :body, :creator_id
validate :validate_topic_is_unlocked
before_destroy :validate_topic_is_unlocked
after_save :delete_topic_if_original_post
module SearchMethods
def body_matches(body)
@@ -122,6 +123,14 @@ class ForumPost < ActiveRecord::Base
ForumPost.exists?(["id = ? and id = (select _.id from forum_posts _ where _.topic_id = ? order by _.id asc limit 1)", id, topic_id])
end
def delete_topic_if_original_post
if is_deleted? && is_original_post?
topic.update_attribute(:is_deleted, true)
end
true
end
def build_response
dup.tap do |x|
x.body = x.quoted_response

View File

@@ -5,7 +5,7 @@
<%= f.input :title %>
<%= f.simple_fields_for :original_post do |pf| %>
<% unless @forum_topic.new_record? %>
<% if !@forum_topic.new_record? %>
<%= hidden_field_tag "forum_topic[original_post_attributes][topic_id]", @forum_topic.id %>
<% end %>

View File

@@ -69,6 +69,18 @@ class ForumPostTest < ActiveSupport::TestCase
assert_equal(@user.id, post.creator_id)
end
context "that is deleted" do
setup do
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
@post.update_attribute(:is_deleted, true)
@topic.reload
end
should "also delete the topic" do
assert(@topic.is_deleted)
end
end
context "updated by a second user" do
setup do
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)