0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-05 21:57:36 +08:00
discourse/spec/models/custom_emoji_spec.rb
Martin Brennan b736e72b1c
DEV: Retroactive review and refactor of custom emoji bulk import/export (#41860)
Followup bd3906ce64

Converts the new endpoints made in the original PR into
service classes, using AI to drive implementation based
on the service authoring skill:

* CustomEmoji::Export
* CustomEmoji::PreviewImport
* CustomEmoji::ConfirmImport

In addition, some supporting action, lib, and serializer
classes have been added. This fixed a couple of
bugs as well:

* Import names now go through `Emoji.sanitize_emoji_name` like
single-emoji create
* No-group imports no longer persist a literal "default" string
* Two 500s (suspicious zip entries, malformed CSV) became proper 422s
* Duplicate CSV names are flagged at preview instead of exploding the
confirm transaction
*` Emoji.clear_cache `moved outside the transaction
2026-07-22 10:06:54 +10:00

27 lines
936 B
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe CustomEmoji do
describe "validations" do
subject(:custom_emoji) { Fabricate.build(:custom_emoji) }
it { is_expected.to validate_length_of(:group).is_at_most(described_class::MAX_GROUP_LENGTH) }
end
describe ".normalize_group" do
it "returns nil for blank values" do
expect(described_class.normalize_group(nil)).to be_nil
expect(described_class.normalize_group("")).to be_nil
expect(described_class.normalize_group(" ")).to be_nil
end
it "returns nil for the default group regardless of case" do
expect(described_class.normalize_group("default")).to be_nil
expect(described_class.normalize_group("Default")).to be_nil
expect(described_class.normalize_group(" DEFAULT ")).to be_nil
end
it "strips and downcases any other group" do
expect(described_class.normalize_group(" Fun ")).to eq("fun")
end
end
end