appeals_controller_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. subject
  15. expect(ActionMailer::Base.deliveries.first.to).to eq([admin.email])
  16. expect(response).to redirect_to(disputes_strike_path(strike.id))
  17. end
  18. end
  19. context 'with invalid params' do
  20. let(:current_user) { Fabricate(:user) }
  21. let(:strike) { Fabricate(:account_warning, target_account: current_user.account) }
  22. let(:params) { { strike_id: strike.id, appeal: { text: '' } } }
  23. it 'does not send email and renders strike show page', :sidekiq_inline do
  24. subject
  25. expect(ActionMailer::Base.deliveries.size).to eq(0)
  26. expect(response).to render_template('disputes/strikes/show')
  27. end
  28. end
  29. end
  30. end