appeals_controller_spec.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Disputes::AppealsController do
  4. render_views
  5. before { sign_in current_user, scope: :user }
  6. let!(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  7. describe '#create' do
  8. subject { post :create, params: params }
  9. context 'with valid params' do
  10. let(:current_user) { Fabricate(:user) }
  11. let(:strike) { Fabricate(:account_warning, target_account: current_user.account) }
  12. let(:params) { { strike_id: strike.id, appeal: { text: 'Foo' } } }
  13. it 'notifies staff about new appeal and redirects back to strike page', :sidekiq_inline do
  14. emails = capture_emails { subject }
  15. expect(emails.size)
  16. .to eq(1)
  17. expect(emails.first)
  18. .to have_attributes(
  19. to: contain_exactly(admin.email),
  20. subject: eq(I18n.t('admin_mailer.new_appeal.subject', username: current_user.account.acct, instance: Rails.configuration.x.local_domain))
  21. )
  22. expect(response).to redirect_to(disputes_strike_path(strike.id))
  23. end
  24. end
  25. context 'with invalid params' do
  26. let(:current_user) { Fabricate(:user) }
  27. let(:strike) { Fabricate(:account_warning, target_account: current_user.account) }
  28. let(:params) { { strike_id: strike.id, appeal: { text: '' } } }
  29. it 'does not send email and renders strike show page', :sidekiq_inline do
  30. emails = capture_emails { subject }
  31. expect(emails).to be_empty
  32. expect(response).to render_template('disputes/strikes/show')
  33. end
  34. end
  35. end
  36. end