From 06d6b35e884dbfa10ba7cb0069b5dd8c25c76399 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 14 Oct 2024 04:31:12 -0400 Subject: [PATCH] Convert `admin/tags` controller specs to system specs (#32447) --- .../controllers/admin/tags_controller_spec.rb | 82 ------------------- spec/system/admin/tags_spec.rb | 38 +++++++++ 2 files changed, 38 insertions(+), 82 deletions(-) delete mode 100644 spec/controllers/admin/tags_controller_spec.rb create mode 100644 spec/system/admin/tags_spec.rb diff --git a/spec/controllers/admin/tags_controller_spec.rb b/spec/controllers/admin/tags_controller_spec.rb deleted file mode 100644 index 1df2bc400..000000000 --- a/spec/controllers/admin/tags_controller_spec.rb +++ /dev/null @@ -1,82 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Admin::TagsController do - render_views - - before do - sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')) - end - - describe 'GET #index' do - before do - Fabricate(:tag) - - tag_filter = instance_double(Admin::TagFilter, results: Tag.all) - allow(Admin::TagFilter).to receive(:new).and_return(tag_filter) - end - - let(:params) { { order: 'newest' } } - - it 'returns http success' do - get :index - - expect(response).to have_http_status(200) - expect(response).to render_template(:index) - - expect(Admin::TagFilter) - .to have_received(:new) - .with(hash_including(params)) - end - - describe 'with filters' do - let(:params) { { order: 'newest', name: 'test' } } - - it 'returns http success' do - get :index, params: { name: 'test' } - - expect(response).to have_http_status(200) - expect(response).to render_template(:index) - - expect(Admin::TagFilter) - .to have_received(:new) - .with(hash_including(params)) - end - end - end - - describe 'GET #show' do - let!(:tag) { Fabricate(:tag) } - - before do - get :show, params: { id: tag.id } - end - - it 'returns status 200' do - expect(response).to have_http_status(200) - end - end - - describe 'PUT #update' do - let!(:tag) { Fabricate(:tag, listable: false) } - - context 'with valid params' do - it 'updates the tag' do - put :update, params: { id: tag.id, tag: { listable: '1' } } - - expect(response).to redirect_to(admin_tag_path(tag.id)) - expect(tag.reload).to be_listable - end - end - - context 'with invalid params' do - it 'does not update the tag' do - put :update, params: { id: tag.id, tag: { name: 'cant-change-name' } } - - expect(response).to have_http_status(200) - expect(response).to render_template(:show) - end - end - end -end diff --git a/spec/system/admin/tags_spec.rb b/spec/system/admin/tags_spec.rb new file mode 100644 index 000000000..a3eca80d1 --- /dev/null +++ b/spec/system/admin/tags_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Admin Tags' do + describe 'Tag interaction' do + let!(:tag) { Fabricate(:tag, name: 'test') } + + before { sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } + + it 'allows tags listing and editing' do + visit admin_tags_path + + expect(page) + .to have_title(I18n.t('admin.tags.title')) + + click_on '#test' + + fill_in display_name_field, with: 'NewTagName' + expect { click_on submit_button } + .to_not(change { tag.reload.display_name }) + expect(page) + .to have_content(match_error_text) + + fill_in display_name_field, with: 'TEST' + expect { click_on submit_button } + .to(change { tag.reload.display_name }.to('TEST')) + end + + def display_name_field + I18n.t('simple_form.labels.defaults.display_name') + end + + def match_error_text + I18n.t('tags.does_not_match_previous_name') + end + end +end