Files
danbooru/test/functional/moderator/post/posts_controller_test.rb
evazion 3ae62d08eb favorites: show favlist when hovering over favcount.
Changes:

* Make it so you can click or hover over a post's favorite count to see
  the list of public favorites.
* Remove the "Show »" button next to the favorite count.
* Make the favorites list visible to all users. Before favorites were
  only visible to Gold users.
* Make the /favorites page show the list of all public favorites,
  instead of redirecting to the current user's favorites.
* Add /posts/:id/favorites endpoint.
* Add /users/:id/favorites endpoint.

This is for several reasons:

* To make viewing favorites work the same way as viewing upvotes.
* To make posts load faster for Gold users. Before, we loaded all the
  favorites when viewing a post, even when the user didn't look at them.
  This made pageloads slower for posts that had hundreds or thousands of
  favorites. Now we only load the favlist if the user hovers over the favcount.
* To make the favorite list visible to all users. Before, it wasn't
  visible to non-Gold users, because of the performance issue listed above.
* To make it more obvious that favorites are public by default. Before,
  since regular users could only see the favcount, they may have
  mistakenly believed other users couldn't see their favorites.
2021-11-20 02:40:18 -06: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.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!
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