mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
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.
70 lines
2.1 KiB
Ruby
Vendored
70 lines
2.1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe CustomEmoji::Create do
|
|
describe described_class::Contract, type: :model do
|
|
it { is_expected.to validate_presence_of(:file) }
|
|
end
|
|
|
|
describe ".call" do
|
|
subject(:result) { described_class.call(params:, **dependencies) }
|
|
|
|
fab!(:actor, :admin)
|
|
|
|
let(:params) { { file:, name: "PaRTY.png", group: "Foo" } }
|
|
let(:dependencies) { { guardian: actor.guardian } }
|
|
let(:file) do
|
|
Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/images/logo.png"), "image/png")
|
|
end
|
|
|
|
context "without an uploaded file" do
|
|
let(:file) { nil }
|
|
|
|
it { is_expected.to fail_a_contract }
|
|
end
|
|
|
|
context "with files instead of a file" do
|
|
let(:params) { { files: [file], name: "party" } }
|
|
|
|
it { is_expected.to run_successfully }
|
|
end
|
|
|
|
context "when the upload is invalid" do
|
|
let(:file) do
|
|
Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/images/fake.jpg"), "image/jpeg")
|
|
end
|
|
|
|
it { is_expected.to fail_with_an_invalid_model(:upload) }
|
|
end
|
|
|
|
context "when the emoji is invalid" do
|
|
fab!(:existing_emoji) { Fabricate(:custom_emoji, name: "party") }
|
|
|
|
it { is_expected.to fail_with_an_invalid_model(:custom_emoji) }
|
|
end
|
|
|
|
context "when everything is valid" do
|
|
it { is_expected.to run_successfully }
|
|
|
|
it "creates a normalized custom emoji owned by the actor" do
|
|
expect(result.custom_emoji).to have_attributes(name: "party", group: "foo", user: actor)
|
|
expect(result.custom_emoji.upload.original_filename).to eq("logo.png")
|
|
end
|
|
|
|
it "logs the creation" do
|
|
expect { result }.to change {
|
|
UserHistory.where(action: UserHistory.actions[:custom_emoji_create]).count
|
|
}.by(1)
|
|
|
|
expect(UserHistory.last).to have_attributes(acting_user_id: actor.id, new_value: "party")
|
|
end
|
|
|
|
it "invalidates the custom emoji cache" do
|
|
expect(Emoji.custom.map(&:name)).not_to include("party")
|
|
|
|
result
|
|
|
|
expect(Emoji.custom.map(&:name)).to include("party")
|
|
end
|
|
end
|
|
end
|
|
end
|