discourse/spec/services/themes/destroy_spec.rb
Krzysztof Kotlarek e774b0c46a
FIX: Add delete button to themes grid (#34606)
The delete button is disabled for default/system themes and shows
appropriate visual feedback.

- Add delete button to theme dropdown menu in themes grid card
- Prevent deletion of default and system themes
2025-08-29 10:09:23 +08:00

50 lines
1.3 KiB
Ruby

# frozen_string_literal: true
RSpec.describe Themes::Destroy do
describe described_class::Contract, type: :model do
it { is_expected.to validate_presence_of(:id) }
it { is_expected.to allow_values(1, "1", 42).for(:id) }
it { is_expected.not_to allow_values(-1, 0).for(:id) }
end
describe ".call" do
subject(:result) { described_class.call(params:, **dependencies) }
fab!(:theme)
fab!(:admin)
let(:params) { { id: theme.id } }
let(:dependencies) { { guardian: admin.guardian } }
context "when data is invalid" do
let(:params) { {} }
it { is_expected.to fail_a_contract }
end
context "for invalid theme id" do
before { theme.destroy! }
it { is_expected.to fail_to_find_a_model(:theme) }
end
context "for a default theme" do
before { theme.set_default! }
it { is_expected.to fail_a_policy(:not_default) }
end
context "when everything is ok" do
it { is_expected.to run_successfully }
it "destroys the theme" do
expect { result }.to change { Theme.find_by(id: theme.id) }.to(nil)
end
it "logs the theme destroy" do
expect_any_instance_of(StaffActionLogger).to receive(:log_theme_destroy).with(theme)
result
end
end
end
end