0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/spec/services/custom_emoji/destroy_spec.rb
Martin Brennan 9e9de80295
UX: Better admin emoji page sorting & filtering and service refactors (#41892)
This commit uses `DFilterControls` for emoji list filtering, and sorts
the
emoji by group then by name, with default always at the top:

<img width="1101" height="803" alt="image"
src="https://github.com/user-attachments/assets/77e384c1-33b1-4741-bd55-ca86cd5f2a03"
/>

I've also refactored the create + delete endpoints into services.
2026-07-24 12:01:21 +10:00

62 lines
1.7 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe CustomEmoji::Destroy do
describe described_class::Contract, type: :model do
it { is_expected.to validate_presence_of(:name) }
end
describe ".call" do
subject(:result) { described_class.call(params:, **dependencies) }
fab!(:actor, :admin)
fab!(:custom_emoji) { Fabricate(:custom_emoji, name: "party") }
let(:params) { { name: } }
let(:dependencies) { { guardian: actor.guardian } }
let(:name) { "party" }
context "without a name" do
let(:name) { nil }
it { is_expected.to fail_a_contract }
end
context "when the custom emoji does not exist" do
let(:name) { "missing" }
it { is_expected.to run_successfully }
it "enqueues a rebake for the requested name" do
expect_enqueued_with(job: :rebake_custom_emoji_posts, args: { name: }) { result }
end
end
context "when the custom emoji exists" do
it { is_expected.to run_successfully }
it "deletes the custom emoji" do
expect { result }.to change { CustomEmoji.exists?(custom_emoji.id) }.from(true).to(false)
end
it "logs the destruction" do
expect { result }.to change {
UserHistory.where(action: UserHistory.actions[:custom_emoji_destroy]).count
}.by(1)
expect(UserHistory.last).to have_attributes(acting_user_id: actor.id, previous_value: name)
end
it "invalidates the custom emoji cache" do
expect(Emoji.custom.map(&:name)).to include(name)
result
expect(Emoji.custom.map(&:name)).not_to include(name)
end
it "enqueues a rebake for the deleted emoji" do
expect_enqueued_with(job: :rebake_custom_emoji_posts, args: { name: }) { result }
end
end
end
end