got rid of removedpost, restore classic is_deleted mechanics

This commit is contained in:
albert
2011-02-12 17:37:48 -05:00
parent 33f5350677
commit f48000a8b5
21 changed files with 204 additions and 371 deletions

View File

@@ -1,13 +0,0 @@
Factory.define(:removed_post) do |f|
f.md5 {|x| Time.now.to_f.to_s}
f.uploader {|x| x.association(:user)}
f.uploader_ip_addr "127.0.0.1"
f.tag_string "tag1 tag2"
f.tag_count 2
f.tag_count_general 2
f.file_ext "jpg"
f.image_width 100
f.image_height 200
f.file_size 2000
f.rating "q"
end

View File

@@ -12,6 +12,30 @@ class PostModerationControllerTest < ActionController::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "delete action" do
setup do
@post = Factory.create(:post)
end
should "delete a post" do
post :delete, {:post_id => @post.id, :format => "js"}, {:user_id => @mod.id}
@post.reload
assert_equal(true, @post.is_deleted?)
end
end
context "undelete action" do
setup do
@post = Factory.create(:post, :is_deleted => true)
end
should "undelete a post" do
post :undelete, {:post_id => @post.id, :format => "js"}, {:user_id => @mod.id}
@post.reload
assert_equal(false, @post.is_deleted?)
end
end
context "moderate action" do
setup do

View File

@@ -14,6 +14,7 @@ module UploadTestMethods
FileUtils.copy_file(path, tempfile.path)
(class << tempfile; self; end).class_eval do
alias local_path path
define_method(:tempfile) {self}
define_method(:original_filename) {filename}
define_method(:content_type) {content_type}
end

View File

@@ -13,47 +13,30 @@ class PostTest < ActiveSupport::TestCase
CurrentUser.ip_addr = nil
end
context "Removal:" do
context "Removing a post" do
context "Deletion:" do
context "Deleting a post" do
should "update the fast count" do
post = Factory.create(:post, :tag_string => "aaa")
assert_equal(1, Post.fast_count)
assert_equal(1, Post.fast_count("aaa"))
post.remove!
post.delete!
assert_equal(0, Post.fast_count)
assert_equal(0, Post.fast_count("aaa"))
end
should "duplicate the post in the archive table and remove it from the base table" do
should "toggle the is_deleted flag" do
post = Factory.create(:post)
assert_difference("RemovedPost.count", 1) do
assert_difference("Post.count", -1) do
post.remove!
end
end
removed_post = RemovedPost.last
assert_equal(post.tag_string, removed_post.tag_string)
assert_equal(false, post.is_deleted?)
post.delete!
assert_equal(true, post.is_deleted?)
end
should "decrement the tag counts" do
post = Factory.create(:post, :tag_string => "aaa")
assert_equal(1, Tag.find_by_name("aaa").post_count)
post.remove!
post.delete!
assert_equal(0, Tag.find_by_name("aaa").post_count)
end
should "preserve the id" do
post = Factory.create(:post, :tag_string => "aaa")
post_id = post.id
post.remove!
removed_post = RemovedPost.last
assert_equal(post_id, removed_post.id)
removed_post.unremove!
post = Post.last
assert_equal(post_id, post.id)
end
end
end
@@ -100,7 +83,7 @@ class PostTest < ActiveSupport::TestCase
c1 = Factory.create(:post, :parent_id => p1.id)
user = Factory.create(:user)
c1.add_favorite(user)
c1.remove!
c1.delete!
p1.reload
assert(!Favorite.exists?(:post_id => c1.id, :user_id => user.id))
assert(Favorite.exists?(:post_id => p1.id, :user_id => user.id))
@@ -109,7 +92,7 @@ class PostTest < ActiveSupport::TestCase
should "update the parent's has_children flag" do
p1 = Factory.create(:post)
c1 = Factory.create(:post, :parent_id => p1.id)
c1.remove!
c1.delete!
p1.reload
assert(!p1.has_children?, "Parent should not have children")
end
@@ -120,7 +103,7 @@ class PostTest < ActiveSupport::TestCase
should "remove the parent of that child" do
p1 = Factory.create(:post)
c1 = Factory.create(:post, :parent_id => p1.id)
p1.remove!
p1.delete!
c1.reload
assert_nil(c1.parent)
end
@@ -132,7 +115,7 @@ class PostTest < ActiveSupport::TestCase
c1 = Factory.create(:post, :parent_id => p1.id)
c2 = Factory.create(:post, :parent_id => p1.id)
c3 = Factory.create(:post, :parent_id => p1.id)
p1.remove!
p1.delete!
c1.reload
c2.reload
c3.reload
@@ -147,10 +130,8 @@ class PostTest < ActiveSupport::TestCase
should "not preserve the parent's has_children flag" do
p1 = Factory.create(:post)
c1 = Factory.create(:post, :parent_id => p1.id)
c1.remove!
c1 = RemovedPost.last
c1.unremove!
c1 = Post.last
c1.delete!
c1.undelete!
p1.reload
assert_nil(p1.parent_id)
assert(!p1.has_children?, "Parent should not have children")
@@ -182,15 +163,6 @@ class PostTest < ActiveSupport::TestCase
assert_equal("approver:#{CurrentUser.name}", post.approver_string)
end
should "preserve the unapproval association even when removed" do
post = Factory.create(:post)
post.unapprove!("bad")
post.remove!
removed_post = RemovedPost.last
assert_not_nil(removed_post.unapproval)
assert_equal("bad", removed_post.unapproval.reason)
end
context "that was previously approved by person X" do
should "not allow person X to reapprove that post" do
user = Factory.create(:janitor_user, :name => "xxx")

View File

@@ -30,7 +30,7 @@ class UserTest < ActiveSupport::TestCase
user.update_attribute(:is_contributor, false)
40.times do
Factory.create(:removed_post, :uploader => user)
Factory.create(:post, :uploader => user, :is_deleted => true)
end
assert(!user.can_upload?)