From 668ce14ff27369c72af2897fb82659f4f4b5dc7f Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 18 Dec 2024 03:34:15 -0500 Subject: [PATCH] Convert `admin/custom_emojis` spec controller->system (#33327) --- .../admin/custom_emojis_controller_spec.rb | 57 ------------------- spec/system/admin/custom_emojis_spec.rb | 39 ++++++++++++- 2 files changed, 37 insertions(+), 59 deletions(-) delete mode 100644 spec/controllers/admin/custom_emojis_controller_spec.rb diff --git a/spec/controllers/admin/custom_emojis_controller_spec.rb b/spec/controllers/admin/custom_emojis_controller_spec.rb deleted file mode 100644 index 57c2a6d21b..0000000000 --- a/spec/controllers/admin/custom_emojis_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/system/admin/custom_emojis_spec.rb b/spec/system/admin/custom_emojis_spec.rb index e47f21f8a9..d597e30313 100644 --- a/spec/system/admin/custom_emojis_spec.rb +++ b/spec/system/admin/custom_emojis_spec.rb @@ -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