2023-02-24 05:53:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
|
2023-11-28 23:17:46 -05:00
|
|
|
describe DiscourseAi::Nsfw::EntryPoint do
|
2023-12-13 22:07:28 -05:00
|
|
|
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
2023-02-24 05:53:43 -05:00
|
|
|
|
|
|
|
describe "registering event callbacks" do
|
2023-02-24 07:11:58 -05:00
|
|
|
fab!(:image_upload) { Fabricate(:upload) }
|
|
|
|
let(:raw_with_upload) { "A public post with an image.\n![](#{image_upload.short_path})" }
|
|
|
|
|
|
|
|
before { SiteSetting.ai_nsfw_detection_enabled = true }
|
|
|
|
|
2023-02-24 05:53:43 -05:00
|
|
|
context "when creating a post" do
|
|
|
|
let(:creator) do
|
2023-02-24 07:11:58 -05:00
|
|
|
PostCreator.new(user, raw: raw_with_upload, title: "this is my new topic title")
|
2023-02-24 05:53:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "queues a job on create if sentiment analysis is enabled" do
|
|
|
|
expect { creator.create }.to change(Jobs::EvaluatePostUploads.jobs, :size).by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does nothing if sentiment analysis is disabled" do
|
|
|
|
SiteSetting.ai_nsfw_detection_enabled = false
|
|
|
|
|
|
|
|
expect { creator.create }.not_to change(Jobs::EvaluatePostUploads.jobs, :size)
|
|
|
|
end
|
2023-02-24 07:11:58 -05:00
|
|
|
|
|
|
|
it "does nothing if the post has no uploads" do
|
|
|
|
creator_2 =
|
|
|
|
PostCreator.new(user, raw: "this is a test", title: "this is my new topic title")
|
|
|
|
|
|
|
|
expect { creator_2.create }.not_to change(Jobs::EvaluatePostUploads.jobs, :size)
|
|
|
|
end
|
2023-02-24 05:53:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when editing a post" do
|
|
|
|
fab!(:post) { Fabricate(:post, user: user) }
|
|
|
|
let(:revisor) { PostRevisor.new(post) }
|
|
|
|
|
|
|
|
it "queues a job on update if sentiment analysis is enabled" do
|
2023-02-24 07:11:58 -05:00
|
|
|
expect { revisor.revise!(user, raw: raw_with_upload) }.to change(
|
2023-02-24 05:53:43 -05:00
|
|
|
Jobs::EvaluatePostUploads.jobs,
|
|
|
|
:size,
|
|
|
|
).by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does nothing if sentiment analysis is disabled" do
|
|
|
|
SiteSetting.ai_nsfw_detection_enabled = false
|
|
|
|
|
2023-02-24 07:11:58 -05:00
|
|
|
expect { revisor.revise!(user, raw: raw_with_upload) }.not_to change(
|
|
|
|
Jobs::EvaluatePostUploads.jobs,
|
|
|
|
:size,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does nothing if the new raw has no uploads" do
|
|
|
|
expect { revisor.revise!(user, raw: "this is a test") }.not_to change(
|
2023-02-24 05:53:43 -05:00
|
|
|
Jobs::EvaluatePostUploads.jobs,
|
|
|
|
:size,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|