2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
RSpec.describe Admin::EmojisController do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
|
|
fab!(:upload) { Fabricate(:upload) }
|
2017-02-02 04:41:57 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
2018-06-11 00:39:31 -04:00
|
|
|
describe '#index' do
|
|
|
|
it "returns a list of custom emojis" do
|
|
|
|
CustomEmoji.create!(name: 'osama-test-emoji', upload: upload)
|
|
|
|
Emoji.clear_cache
|
|
|
|
|
|
|
|
get "/admin/customize/emojis.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
2020-05-07 11:04:12 -04:00
|
|
|
json = response.parsed_body
|
2018-06-11 00:39:31 -04:00
|
|
|
expect(json[0]["name"]).to eq("osama-test-emoji")
|
|
|
|
expect(json[0]["url"]).to eq(upload.url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
describe "#create" do
|
2017-02-02 04:41:57 -05:00
|
|
|
describe 'when upload is invalid' do
|
|
|
|
it 'should publish the right error' do
|
2017-12-17 18:31:19 -05:00
|
|
|
|
|
|
|
post "/admin/customize/emojis.json", params: {
|
|
|
|
name: 'test',
|
|
|
|
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/fake.jpg")
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response.status).to eq(422)
|
2020-05-07 11:04:12 -04:00
|
|
|
parsed = response.parsed_body
|
2017-12-17 18:31:19 -05:00
|
|
|
expect(parsed["errors"]).to eq([I18n.t('upload.images.size_not_found')])
|
2017-02-02 04:41:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when emoji name already exists' do
|
|
|
|
it 'should publish the right error' do
|
|
|
|
CustomEmoji.create!(name: 'test', upload: upload)
|
|
|
|
|
2017-12-17 18:31:19 -05:00
|
|
|
post "/admin/customize/emojis.json", params: {
|
|
|
|
name: 'test',
|
|
|
|
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")
|
|
|
|
}
|
2017-02-02 04:41:57 -05:00
|
|
|
|
2017-12-17 18:31:19 -05:00
|
|
|
expect(response.status).to eq(422)
|
2020-05-07 11:04:12 -04:00
|
|
|
parsed = response.parsed_body
|
2017-12-17 18:31:19 -05:00
|
|
|
expect(parsed["errors"]).to eq([
|
2017-02-02 04:41:57 -05:00
|
|
|
"Name #{I18n.t('activerecord.errors.models.custom_emoji.attributes.name.taken')}"
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should allow an admin to add a custom emoji' do
|
|
|
|
Emoji.expects(:clear_cache)
|
|
|
|
|
2020-03-30 14:16:10 -04:00
|
|
|
post "/admin/customize/emojis.json", params: {
|
|
|
|
name: 'test',
|
|
|
|
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")
|
|
|
|
}
|
2017-02-02 04:41:57 -05:00
|
|
|
|
2020-03-30 14:16:10 -04:00
|
|
|
custom_emoji = CustomEmoji.last
|
|
|
|
upload = custom_emoji.upload
|
2017-02-02 04:41:57 -05:00
|
|
|
|
2020-03-30 14:16:10 -04:00
|
|
|
expect(upload.original_filename).to eq('logo.png')
|
2017-12-17 18:31:19 -05:00
|
|
|
|
2020-05-07 11:04:12 -04:00
|
|
|
data = response.parsed_body
|
2020-03-30 14:16:10 -04:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(data["errors"]).to eq(nil)
|
|
|
|
expect(data["name"]).to eq(custom_emoji.name)
|
|
|
|
expect(data["url"]).to eq(upload.url)
|
|
|
|
expect(custom_emoji.group).to eq(nil)
|
|
|
|
end
|
2017-12-17 18:31:19 -05:00
|
|
|
|
2020-03-30 14:16:10 -04:00
|
|
|
it 'should allow an admin to add a custom emoji with a custom group' do
|
|
|
|
Emoji.expects(:clear_cache)
|
|
|
|
|
|
|
|
post "/admin/customize/emojis.json", params: {
|
|
|
|
name: 'test',
|
|
|
|
group: 'Foo',
|
|
|
|
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")
|
|
|
|
}
|
|
|
|
|
|
|
|
custom_emoji = CustomEmoji.last
|
|
|
|
|
2020-05-07 11:04:12 -04:00
|
|
|
data = response.parsed_body
|
2020-03-30 14:16:10 -04:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(custom_emoji.group).to eq("foo")
|
2017-02-02 04:41:57 -05:00
|
|
|
end
|
2021-11-16 18:20:44 -05:00
|
|
|
|
|
|
|
it 'should fix up the emoji name' do
|
|
|
|
Emoji.expects(:clear_cache).times(3)
|
|
|
|
|
|
|
|
post "/admin/customize/emojis.json", params: {
|
|
|
|
name: 'test.png',
|
|
|
|
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")
|
|
|
|
}
|
|
|
|
|
|
|
|
custom_emoji = CustomEmoji.last
|
|
|
|
upload = custom_emoji.upload
|
|
|
|
|
|
|
|
expect(upload.original_filename).to eq('logo.png')
|
|
|
|
expect(custom_emoji.name).to eq("test")
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
post "/admin/customize/emojis.json", params: {
|
|
|
|
name: 'st&#* onk$',
|
|
|
|
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")
|
|
|
|
}
|
|
|
|
|
|
|
|
custom_emoji = CustomEmoji.last
|
|
|
|
expect(custom_emoji.name).to eq("st_onk_")
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
post "/admin/customize/emojis.json", params: {
|
|
|
|
name: 'PaRTYpaRrot',
|
|
|
|
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")
|
|
|
|
}
|
|
|
|
|
|
|
|
custom_emoji = CustomEmoji.last
|
|
|
|
expect(custom_emoji.name).to eq("partyparrot")
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
2017-02-02 04:41:57 -05:00
|
|
|
end
|
|
|
|
|
2017-08-23 23:01:11 -04:00
|
|
|
describe '#destroy' do
|
2017-02-02 04:41:57 -05:00
|
|
|
it 'should allow an admin to delete a custom emoji' do
|
|
|
|
custom_emoji = CustomEmoji.create!(name: 'test', upload: upload)
|
|
|
|
Emoji.clear_cache
|
|
|
|
|
2017-08-31 00:06:56 -04:00
|
|
|
expect do
|
|
|
|
delete "/admin/customize/emojis/#{custom_emoji.name}.json",
|
|
|
|
params: { name: 'test' }
|
2017-11-20 17:50:23 -05:00
|
|
|
end.to change { CustomEmoji.count }.by(-1)
|
2017-02-02 04:41:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|