From 8e3fd1b8236448f01221b1d7745736e50de51e11 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 2 Jan 2025 11:08:25 -0500 Subject: [PATCH] Convert `disputes/appeals` spec controller->system (#33434) --- .../disputes/appeals_controller_spec.rb | 47 ---------------- spec/system/disputes/appeals_spec.rb | 53 +++++++++++++++++++ 2 files changed, 53 insertions(+), 47 deletions(-) delete mode 100644 spec/controllers/disputes/appeals_controller_spec.rb create mode 100644 spec/system/disputes/appeals_spec.rb diff --git a/spec/controllers/disputes/appeals_controller_spec.rb b/spec/controllers/disputes/appeals_controller_spec.rb deleted file mode 100644 index 3e874bbdcc..0000000000 --- a/spec/controllers/disputes/appeals_controller_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Disputes::AppealsController do - render_views - - before { sign_in current_user, scope: :user } - - let!(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } - - describe '#create' do - subject { post :create, params: params } - - context 'with valid params' do - let(:current_user) { Fabricate(:user) } - let(:strike) { Fabricate(:account_warning, target_account: current_user.account) } - let(:params) { { strike_id: strike.id, appeal: { text: 'Foo' } } } - - it 'notifies staff about new appeal and redirects back to strike page', :inline_jobs do - emails = capture_emails { subject } - - expect(emails.size) - .to eq(1) - expect(emails.first) - .to have_attributes( - to: contain_exactly(admin.email), - subject: eq(I18n.t('admin_mailer.new_appeal.subject', username: current_user.account.acct, instance: Rails.configuration.x.local_domain)) - ) - expect(response).to redirect_to(disputes_strike_path(strike.id)) - end - end - - context 'with invalid params' do - let(:current_user) { Fabricate(:user) } - let(:strike) { Fabricate(:account_warning, target_account: current_user.account) } - let(:params) { { strike_id: strike.id, appeal: { text: '' } } } - - it 'does not send email and renders strike show page', :inline_jobs do - emails = capture_emails { subject } - - expect(emails).to be_empty - expect(response).to render_template('disputes/strikes/show') - end - end - end -end diff --git a/spec/system/disputes/appeals_spec.rb b/spec/system/disputes/appeals_spec.rb new file mode 100644 index 0000000000..a225635fb2 --- /dev/null +++ b/spec/system/disputes/appeals_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Dispute Appeals' do + let(:user) { Fabricate(:user) } + let!(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } + + before { sign_in user } + + describe 'Submitting an appeal', :inline_jobs do + let(:strike) { Fabricate(:account_warning, target_account: user.account) } + + it 'Submits the appeal and notifies admins' do + visit disputes_strike_path(strike) + + # Invalid with missing attribute + fill_in 'appeal_text', with: '' + emails = capture_emails do + expect { submit_form } + .to_not change(Appeal, :count) + end + expect(emails) + .to be_empty + expect(page) + .to have_content(/can't be blank/) + + # Valid with text + fill_in 'appeal_text', with: 'It wasnt me this time!' + emails = capture_emails do + expect { submit_form } + .to change(Appeal, :count).by(1) + end + expect(emails) + .to contain_exactly( + have_attributes( + to: contain_exactly(admin.email), + subject: eq(new_appeal_subject) + ) + ) + expect(page) + .to have_content(I18n.t('disputes.strikes.appealed_msg')) + end + + def new_appeal_subject + I18n.t('admin_mailer.new_appeal.subject', username: user.account.acct, instance: Rails.configuration.x.local_domain) + end + + def submit_form + click_on I18n.t('disputes.strikes.appeals.submit') + end + end +end