discourse/spec/requests/admin/unknown_reviewables_controller_spec.rb
Krzysztof Kotlarek 5eb7d6d9c0
FEATURE: Gracefully handle unhandled reviewables (#31118)
Plugins like for example AI or Akismet create reviewable items. When the
plugin is disabled, then we cannot properly handle those items.

In that situation, we should display warnings about unhandled types.
Instruct admin to reenable plugins. In addition, we should allow the
admin to delete all pending reviews from disabled plugins.
2025-02-05 14:38:45 +11:00

38 lines
1017 B
Ruby

# frozen_string_literal: true
require "rails_helper"
RSpec.describe Admin::UnknownReviewablesController do
let(:admin) { Fabricate(:admin) }
let(:user) { Fabricate(:user) }
fab!(:reviewable)
fab!(:unknown_reviewable) { Fabricate(:reviewable, type: "ReviewablePost") }
describe "#destroy" do
context "when user is an admin" do
before do
sign_in admin
allow(Reviewable).to receive(:types).and_return([ReviewableUser])
end
it "destroys all pending reviewables of specified types" do
delete "/admin/unknown_reviewables/destroy.json"
expect(response.code).to eq("200")
reviewable.reload
expect { unknown_reviewable.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
context "when user is not an admin" do
before { sign_in user }
it "raises Discourse::InvalidAccess" do
delete "/admin/unknown_reviewables/destroy.json"
expect(response.code).to eq("404")
end
end
end
end