diff --git a/app/models/post.rb b/app/models/post.rb index e1bca0b48..7fbfba4ab 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -426,7 +426,9 @@ class Post < ActiveRecord::Base self.parent_id = nil when /^parent:(\d+)$/ - self.parent_id = $1.to_i + if Post.exists?(["id = ? and is_deleted = false", $1.to_i]) + self.parent_id = $1.to_i + end when /^rating:([qse])/i self.rating = $1.downcase diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 1c62c2d06..83cb5bce9 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -390,6 +390,18 @@ class PostTest < ActiveSupport::TestCase setup do @parent = FactoryGirl.create(:post) end + + context "that has been deleted" do + setup do + @parent.update_column(:is_deleted, true) + end + + should "not update the parent relationships" do + @post.update_attributes(:tag_string => "aaa parent:#{@parent.id}") + @post.reload + assert_nil(@post.parent_id) + end + end should "update the parent relationships for both posts" do @post.update_attributes(:tag_string => "aaa parent:#{@parent.id}")