Remove report method from User model

This commit is contained in:
Andreas Nedbal 2025-03-08 15:10:09 +01:00 committed by Andreas Nedbal
parent ae02840c69
commit fa1d09ec44
2 changed files with 7 additions and 16 deletions

View file

@ -148,21 +148,6 @@ class User < ApplicationRecord
def admin? = has_cached_role?(:administrator)
# region stuff used for reporting/moderation
def report(object, reason = nil)
target_user = if object.instance_of?(::User)
object
elsif object.respond_to? :user
object.user
end
existing = Report.find_by(type: "Reports::#{object.class}", target_id: object.id, user_id: id, target_user_id: target_user&.id, resolved: false)
if existing.nil?
Report.create(type: "Reports::#{object.class}", target_id: object.id, user_id: id, target_user_id: target_user&.id, reason:)
end
end
# endregion
def can_export?
return (Time.zone.now > export_created_at.in(1.week)) && !export_processing unless export_created_at.nil?

View file

@ -37,7 +37,13 @@ RSpec.describe User, type: :model do
describe "before_destroy" do
it "marks reports about this user as deleted" do
other_user = FactoryBot.create(:user)
other_user.report me, "va tutto benissimo"
UseCase::Report::Create.call(
reporter_id: other_user.id,
object_id: me.screen_name,
object_type: "User",
reason: "va tutto benissimo",
)
expect { me.destroy }
.to change { Reports::User.find_by(target_id: me.id).resolved? }