2017-02-02 17:41:57 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-08-24 11:01:11 +08:00
|
|
|
RSpec.describe Admin::EmojisController do
|
2017-02-02 17:41:57 +08:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
let(:upload) { Fabricate(:upload) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
2017-08-24 11:01:11 +08:00
|
|
|
describe "#create" do
|
2017-02-02 17:41:57 +08:00
|
|
|
describe 'when upload is invalid' do
|
|
|
|
it 'should publish the right error' do
|
|
|
|
message = MessageBus.track_publish do
|
2017-08-24 11:01:11 +08:00
|
|
|
post("/admin/customize/emojis.json",
|
|
|
|
name: 'test',
|
|
|
|
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/fake.jpg")
|
|
|
|
)
|
2017-07-28 09:20:09 +08:00
|
|
|
end.find { |m| m.channel == "/uploads/emoji" }
|
2017-02-02 17:41:57 +08:00
|
|
|
|
|
|
|
expect(message.channel).to eq("/uploads/emoji")
|
|
|
|
expect(message.data["errors"]).to eq([I18n.t('upload.images.size_not_found')])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when emoji name already exists' do
|
|
|
|
it 'should publish the right error' do
|
|
|
|
CustomEmoji.create!(name: 'test', upload: upload)
|
|
|
|
|
|
|
|
message = MessageBus.track_publish do
|
2017-08-24 11:01:11 +08:00
|
|
|
post("/admin/customize/emojis.json",
|
|
|
|
name: 'test',
|
|
|
|
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")
|
|
|
|
)
|
2017-07-28 09:20:09 +08:00
|
|
|
end.find { |m| m.channel == "/uploads/emoji" }
|
2017-02-02 17:41:57 +08:00
|
|
|
|
|
|
|
expect(message.channel).to eq("/uploads/emoji")
|
|
|
|
|
|
|
|
expect(message.data["errors"]).to eq([
|
|
|
|
"Name #{I18n.t('activerecord.errors.models.custom_emoji.attributes.name.taken')}"
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should allow an admin to add a custom emoji' do
|
2017-07-28 09:20:09 +08:00
|
|
|
Emoji.expects(:clear_cache)
|
2017-02-02 17:41:57 +08:00
|
|
|
|
|
|
|
message = MessageBus.track_publish do
|
2017-08-24 11:01:11 +08:00
|
|
|
post("/admin/customize/emojis.json",
|
|
|
|
name: 'test',
|
|
|
|
file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")
|
|
|
|
)
|
2017-07-28 09:20:09 +08:00
|
|
|
end.find { |m| m.channel == "/uploads/emoji" }
|
2017-02-02 17:41:57 +08:00
|
|
|
|
|
|
|
custom_emoji = CustomEmoji.last
|
|
|
|
upload = custom_emoji.upload
|
|
|
|
|
|
|
|
expect(upload.original_filename).to eq('logo.png')
|
|
|
|
expect(message.channel).to eq("/uploads/emoji")
|
|
|
|
expect(message.data["errors"]).to eq(nil)
|
|
|
|
expect(message.data["name"]).to eq(custom_emoji.name)
|
|
|
|
expect(message.data["url"]).to eq(upload.url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-24 11:01:11 +08:00
|
|
|
describe '#destroy' do
|
2017-02-02 17:41:57 +08:00
|
|
|
it 'should allow an admin to delete a custom emoji' do
|
|
|
|
custom_emoji = CustomEmoji.create!(name: 'test', upload: upload)
|
|
|
|
Emoji.clear_cache
|
|
|
|
|
|
|
|
expect { delete "/admin/customize/emojis/#{custom_emoji.name}.json", name: 'test' }
|
|
|
|
.to change { Upload.count }.by(-1)
|
|
|
|
.and change { CustomEmoji.count }.by(-1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|