Files
danbooru/test/functional/moderator/post/posts_controller_test.rb
evazion 34057b25e1 mod actions: record the subject of the mod action.
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.
2022-09-25 04:04:28 -05:00

83 lines
2.3 KiB
Ruby

require 'test_helper'
module Moderator
module Post
class PostsControllerTest < ActionDispatch::IntegrationTest
context "The moderator posts controller" do
setup do
@admin = create(:admin_user)
travel_to(1.month.ago) do
@user = create(:gold_user)
end
as(@user) do
@post = create(:post_with_file)
end
end
context "confirm_move_favorites action" do
should "render" do
get_auth confirm_move_favorites_moderator_post_post_path(@post), @admin
assert_response :success
end
end
context "move_favorites action" do
setup do
@admin = create(:admin_user)
end
should "render" do
as(@user) do
@parent = create(:post)
@child = create(:post, parent: @parent)
end
users = FactoryBot.create_list(:user, 2)
users.each do |u|
Favorite.create!(post: @child, user: u)
@child.reload
end
post_auth move_favorites_moderator_post_post_path(@child.id), @admin, params: { commit: "Submit" }
assert_redirected_to(@child)
@parent.reload
@child.reload
as(@admin) do
assert_equal(users.map(&:id).sort, @parent.favorites.map(&:user_id).sort)
assert_equal([], @child.favorites.map(&:user_id))
end
end
end
context "expunge action" do
should "render" do
post_auth expunge_moderator_post_post_path(@post), @admin, params: { format: "js" }
assert_response :success
assert_equal(false, ::Post.exists?(@post.id))
end
end
context "ban action" do
should "render" do
post_auth ban_moderator_post_post_path(@post), @admin
assert_redirected_to @post
assert_equal(true, @post.reload.is_banned?)
end
end
context "unban action" do
should "render" do
@post.ban!(@admin)
post_auth unban_moderator_post_post_path(@post), @admin
assert_redirected_to(@post)
assert_equal(false, @post.reload.is_banned?)
end
end
end
end
end
end