2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-05 23:53:59 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 15:12:25 +10:00
|
|
|
RSpec.describe Admin::CustomEmojisController do
|
2018-05-05 23:53:59 +10:00
|
|
|
render_views
|
|
|
|
|
2022-07-05 10:41:40 +10:00
|
|
|
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
2018-05-05 23:53:59 +10:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user, scope: :user
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
before do
|
|
|
|
Fabricate(:custom_emoji)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders index page' do
|
2023-12-01 21:38:15 +11:00
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(response).to have_http_status 200
|
|
|
|
expect(response).to render_template :index
|
2018-05-05 23:53:59 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #new' do
|
|
|
|
it 'renders new page' do
|
2023-12-01 21:38:15 +11:00
|
|
|
get :new
|
|
|
|
|
|
|
|
expect(response).to have_http_status 200
|
|
|
|
expect(response).to render_template :new
|
2018-05-05 23:53:59 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
subject { post :create, params: { custom_emoji: params } }
|
|
|
|
|
|
|
|
let(:image) { fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'emojo.png'), 'image/png') }
|
|
|
|
|
|
|
|
context 'when parameter is valid' do
|
|
|
|
let(:params) { { shortcode: 'test', image: image } }
|
|
|
|
|
|
|
|
it 'creates custom emoji' do
|
2023-05-24 19:23:40 +10:00
|
|
|
expect { subject }.to change(CustomEmoji, :count).by(1)
|
2018-05-05 23:53:59 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when parameter is invalid' do
|
|
|
|
let(:params) { { shortcode: 't', image: image } }
|
|
|
|
|
|
|
|
it 'renders new' do
|
|
|
|
expect(subject).to render_template :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|