Convert admin/custom_emojis spec controller->system (#33327)

This commit is contained in:
Matt Jankowski 2024-12-18 03:34:15 -05:00 committed by GitHub
parent ca2a7d66b8
commit 668ce14ff2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 59 deletions

View file

@ -1,57 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::CustomEmojisController do
render_views
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
before do
sign_in user, scope: :user
end
describe 'GET #index' do
before do
Fabricate(:custom_emoji)
end
it 'renders index page' do
get :index
expect(response).to have_http_status 200
expect(response).to render_template :index
end
end
describe 'GET #new' do
it 'renders new page' do
get :new
expect(response).to have_http_status 200
expect(response).to render_template :new
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
expect { subject }.to change(CustomEmoji, :count).by(1)
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

View file

@ -5,8 +5,43 @@ require 'rails_helper'
RSpec.describe 'Admin::CustomEmojis' do
let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
before do
sign_in current_user
before { sign_in current_user }
describe 'Listing existing emoji' do
let!(:custom_emoji) { Fabricate :custom_emoji }
it 'Shows records' do
visit admin_custom_emojis_path
expect(page)
.to have_content(I18n.t('admin.custom_emojis.title'))
.and have_content(custom_emoji.shortcode)
end
end
describe 'Creating a new emoji' do
it 'saves a new emoji record with valid attributes' do
visit new_admin_custom_emoji_path
expect(page)
.to have_content(I18n.t('admin.custom_emojis.title'))
expect { submit_form }
.to_not change(CustomEmoji, :count)
expect(page)
.to have_content(/errors below/)
fill_in I18n.t('admin.custom_emojis.shortcode'),
with: 'test'
attach_file 'custom_emoji_image',
Rails.root.join('spec', 'fixtures', 'files', 'emojo.png')
expect { submit_form }
.to change(CustomEmoji, :count).by(1)
end
def submit_form
click_on I18n.t('admin.custom_emojis.upload')
end
end
describe 'Performing batch updates' do