mirror of
https://ghfast.top/https://github.com/discourse/discourse-akismet.git
synced 2026-07-15 11:36:24 +08:00
40 lines
1.1 KiB
Ruby
40 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe UserProfile do
|
|
describe "Callbacks to enqueue akismet checks" do
|
|
before do
|
|
SiteSetting.akismet_review_users = true
|
|
SiteSetting.akismet_enabled = true
|
|
end
|
|
|
|
let(:user) do
|
|
Fabricate(
|
|
:user,
|
|
trust_level: TrustLevel[0],
|
|
user_auth_token_logs: [UserAuthTokenLog.new(client_ip: "127.0.0.1", action: "an_action")],
|
|
)
|
|
end
|
|
|
|
it "triggers a job to check for spam when the bio changes" do
|
|
user_profile = user.user_profile
|
|
user_profile.bio_raw = "Check if I'm spam"
|
|
|
|
assert_checks_triggered(user_profile, 1)
|
|
end
|
|
|
|
it "triggers a job to check for spam when the user website changes" do
|
|
user_profile = user.user_profile
|
|
user_profile.website = "https://example.com/totally-legit-not-bogus-at-all/"
|
|
|
|
assert_checks_triggered(user_profile, 1)
|
|
end
|
|
|
|
it "doesn't trigger a job when the the bio haven't changed" do
|
|
assert_checks_triggered(user.user_profile, 0)
|
|
end
|
|
|
|
def assert_checks_triggered(user_profile, qty)
|
|
expect { user_profile.save! }.to change(Jobs::CheckAkismetUser.jobs, :size).by(qty)
|
|
end
|
|
end
|
|
end
|