Add a polymorphic `subject` field that records the subject of the mod action. The subject is the post, user, comment, artist, etc the mod action is for. * The subject for the user ban and unban actions is the user, not the ban itself. * The subject for the user feedback update and deletion actions is the user, not the feedback itself. * The subject for the post undeletion action is the post, not the approval itself. * The subject for the move favorites action is the source post where the favorites were moved from, not the destination post where the favorites were moved to. * The subject for the post permanent delete action is nil, because the post itself is hard deleted. * When a post is permanently deleted, all mod actions related to the post are deleted as well.
62 lines
1.7 KiB
Ruby
62 lines
1.7 KiB
Ruby
require 'test_helper'
|
|
|
|
class FavoriteGroupTest < ActiveSupport::TestCase
|
|
def setup
|
|
@fav_group = create(:favorite_group)
|
|
end
|
|
|
|
context "searching by post id" do
|
|
should "return the fav group" do
|
|
posts = create_list(:post, 3)
|
|
|
|
@fav_group.add(posts[0])
|
|
assert_equal(@fav_group.id, FavoriteGroup.for_post(posts[0].id).first.id)
|
|
|
|
@fav_group.add(posts[1])
|
|
assert_equal(@fav_group.id, FavoriteGroup.for_post(posts[1].id).first.id)
|
|
|
|
@fav_group.add(posts[2])
|
|
assert_equal(@fav_group.id, FavoriteGroup.for_post(posts[2].id).first.id)
|
|
end
|
|
end
|
|
|
|
context "expunging a post" do
|
|
should "remove it from all favorite groups" do
|
|
@post = create(:post_with_file, filename: "test.jpg")
|
|
|
|
@fav_group.add(@post)
|
|
assert_equal([@post.id], @fav_group.post_ids)
|
|
|
|
@post.expunge!(create(:admin_user))
|
|
assert_equal([], @fav_group.reload.post_ids)
|
|
end
|
|
end
|
|
|
|
context "adding a post to a favgroup" do
|
|
should "not allow adding duplicate posts" do
|
|
post = create(:post)
|
|
|
|
@fav_group.add(post)
|
|
assert(@fav_group.valid?)
|
|
assert_equal([post.id], @fav_group.reload.post_ids)
|
|
|
|
@fav_group.add(post)
|
|
assert_equal(false, @fav_group.valid?)
|
|
assert_match(/Favgroup already contains post #{post.id}/, @fav_group.errors.full_messages.join)
|
|
|
|
assert_equal([post.id], @fav_group.reload.post_ids)
|
|
|
|
@fav_group.reload.update(post_ids: [post.id, post.id])
|
|
refute(@fav_group.valid?)
|
|
assert_equal([post.id], @fav_group.reload.post_ids)
|
|
end
|
|
|
|
should "not allow adding nonexistent posts" do
|
|
@fav_group.update(post_ids: [0])
|
|
|
|
refute(@fav_group.valid?)
|
|
assert_equal([], @fav_group.reload.post_ids)
|
|
end
|
|
end
|
|
end
|