From 54e5869dfcee3a305106a59189ae752e9e78735a Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 21 May 2013 18:02:35 -0700 Subject: [PATCH] fixes #1636 --- app/models/post.rb | 7 +++++++ test/unit/post_test.rb | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/app/models/post.rb b/app/models/post.rb index 57901d8d1..8bdc36e28 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -617,6 +617,12 @@ class Post < ActiveRecord::Base update_column(:pool_string, pool_string) unless new_record? pool.remove!(self) end + + def remove_from_all_pools + pools.find_each do |pool| + pool.remove!(self) + end + end end module VoteMethods @@ -823,6 +829,7 @@ class Post < ActiveRecord::Base update_children_on_destroy update_parent_on_destroy decrement_tag_post_counts + remove_from_all_pools destroy end diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 9980d42d5..804693251 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -31,6 +31,14 @@ class PostTest < ActiveSupport::TestCase end end + should "remove the post from all pools" do + pool = FactoryGirl.create(:pool) + pool.add!(@post) + @post.expunge! + pool.reload + assert_equal("", pool.post_ids) + end + should "destroy the record" do @post.expunge! assert_equal([], @post.errors.full_messages)