Files
danbooru/test/functional/admin/users_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

79 lines
3.2 KiB
Ruby

require 'test_helper'
class Admin::UsersControllerTest < ActionDispatch::IntegrationTest
context "Admin::UsersController" do
setup do
@mod = create(:moderator_user)
@user = create(:user)
@admin = create(:admin_user)
end
context "#edit" do
should "render" do
get_auth edit_admin_user_path(@user), @mod
assert_response :success
end
end
context "#update" do
context "on a basic user" do
should "succeed" do
put_auth admin_user_path(@user), @mod, params: {:user => {:level => "30"}}
assert_redirected_to(edit_admin_user_path(@user))
assert_equal(30, @user.reload.level)
assert_match(/promoted "#{@user.name}":\/users\/#{@user.id} from Member to Gold/, ModAction.last.description)
assert_equal(@user, ModAction.last.subject)
assert_equal(@mod, ModAction.last.creator)
end
should "promote the user to unrestricted uploads" do
put_auth admin_user_path(@user), @mod, params: { user: { level: User::Levels::BUILDER, can_upload_free: true }}
assert_redirected_to(edit_admin_user_path(@user.reload))
assert_equal(true, @user.is_builder?)
assert_equal(true, @user.can_upload_free?)
assert_equal(false, @user.can_approve_posts?)
assert_match(/granted unlimited upload privileges to "#{@user.name}":\/users\/#{@user.id}/, ModAction.first.description)
assert_match(/promoted "#{@user.name}":\/users\/#{@user.id} from Member to Builder/, ModAction.last.description)
assert_equal(@user, ModAction.first.subject)
assert_equal(@mod, ModAction.first.creator)
assert_equal(@user, ModAction.last.subject)
assert_equal(@mod, ModAction.last.creator)
end
should "promote the user to approver" do
put_auth admin_user_path(@user), @mod, params: { user: { level: User::Levels::BUILDER, can_approve_posts: true }}
assert_redirected_to(edit_admin_user_path(@user.reload))
assert_equal(true, @user.is_builder?)
assert_equal(false, @user.can_upload_free?)
assert_equal(true, @user.can_approve_posts?)
assert_match(/granted approval privileges to "#{@user.name}":\/users\/#{@user.id}/, ModAction.first.description)
assert_match(/promoted "#{@user.name}":\/users\/#{@user.id} from Member to Builder/, ModAction.last.description)
assert_equal(@user, ModAction.first.subject)
assert_equal(@mod, ModAction.first.creator)
assert_equal(@user, ModAction.last.subject)
assert_equal(@mod, ModAction.last.creator)
end
context "promoted to an admin" do
should "fail" do
put_auth admin_user_path(@user), @mod, params: {:user => {:level => "50"}}
assert_response(403)
assert_equal(20, @user.reload.level)
end
end
end
context "on an admin user" do
should "fail" do
put_auth admin_user_path(@admin), @mod, params: {:user => {:level => "30"}}
assert_response(403)
assert_equal(50, @admin.reload.level)
end
end
end
end
end