Files
danbooru/test/functional/moderator/post/posts_controller_test.rb
evazion 1653392361 posts: stop updating fav_string attribute.
Stop updating the fav_string attribute on posts. The column still exists
on the table, but is no longer used or updated.

Like the pool_string in 7d503f08, the fav_string was used in the past to
facilitate `fav:X` searches. Posts had a hidden fav_string column that
contained a list of every user who favorited the post. These were
treated like fake hidden tags on the post so that a search for `fav:X`
was treated like a tag search.

The fav_string attribute has been unused for search purposes for a while
now. It was only kept because of technicalities that required
departitioning the favorites table first (340e1008e) before it could be
removed. Basically, removing favorites with `@favorite.destroy` was
slow because Rails always deletes object by ID, but we didn't have an
index on favorites.id, and we couldn't easily add one until the
favorites table was departitioned.

Fixes #4652. See https://github.com/danbooru/danbooru/issues/4652#issuecomment-754993802
for more discussion of issues caused by the fav_string (in short: write
amplification, post table bloat, and favorite inconsistency problems).
2021-10-09 22:36:26 -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)
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.favorited_users.map(&:id).sort)
assert_equal([], @child.favorited_users.map(&: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!
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