2020-06-30 12:08:57 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe CustomEmoji do
|
|
|
|
describe 'Associations' do
|
|
|
|
it { is_expected.to belong_to(:namespace) }
|
|
|
|
it { is_expected.to have_db_column(:file) }
|
|
|
|
it { is_expected.to validate_length_of(:name).is_at_most(36) }
|
|
|
|
it { is_expected.to validate_presence_of(:name) }
|
2020-07-21 15:09:40 +00:00
|
|
|
it { is_expected.to have_db_column(:external) }
|
2020-06-30 12:08:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'exclusion of duplicated emoji' do
|
|
|
|
let(:emoji_name) { Gitlab::Emoji.emojis_names.sample }
|
2020-11-16 21:09:02 +00:00
|
|
|
let(:group) { create(:group, :private) }
|
2020-06-30 12:08:57 +00:00
|
|
|
|
|
|
|
it 'disallows emoji names of built-in emoji' do
|
2020-11-16 21:09:02 +00:00
|
|
|
new_emoji = build(:custom_emoji, name: emoji_name, group: group)
|
2020-06-30 12:08:57 +00:00
|
|
|
|
|
|
|
expect(new_emoji).not_to be_valid
|
|
|
|
expect(new_emoji.errors.messages).to eq(name: ["#{emoji_name} is already being used for another emoji"])
|
|
|
|
end
|
|
|
|
|
2020-12-02 21:09:44 +00:00
|
|
|
it 'disallows very long invalid emoji name without regular expression backtracking issues' do
|
|
|
|
new_emoji = build(:custom_emoji, name: 'a' * 10000 + '!', group: group)
|
|
|
|
|
|
|
|
Timeout.timeout(1) do
|
|
|
|
expect(new_emoji).not_to be_valid
|
|
|
|
expect(new_emoji.errors.messages).to eq(name: ["is too long (maximum is 36 characters)", "is invalid"])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-30 12:08:57 +00:00
|
|
|
it 'disallows duplicate custom emoji names within namespace' do
|
2020-11-16 21:09:02 +00:00
|
|
|
old_emoji = create(:custom_emoji, group: group)
|
|
|
|
new_emoji = build(:custom_emoji, name: old_emoji.name, namespace: old_emoji.namespace, group: group)
|
2020-06-30 12:08:57 +00:00
|
|
|
|
|
|
|
expect(new_emoji).not_to be_valid
|
|
|
|
expect(new_emoji.errors.messages).to eq(name: ["has already been taken"])
|
|
|
|
end
|
2020-11-16 21:09:02 +00:00
|
|
|
|
|
|
|
it 'disallows non http and https file value' do
|
|
|
|
emoji = build(:custom_emoji, name: 'new-name', group: group, file: 'ftp://some-url.in')
|
|
|
|
|
|
|
|
expect(emoji).not_to be_valid
|
|
|
|
expect(emoji.errors.messages).to eq(file: ["is blocked: Only allowed schemes are http, https"])
|
|
|
|
end
|
2020-06-30 12:08:57 +00:00
|
|
|
end
|
|
|
|
end
|