appeals_controller_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. require 'rails_helper'
  2. RSpec.describe Admin::Disputes::AppealsController, type: :controller do
  3. render_views
  4. before { sign_in current_user, scope: :user }
  5. let(:target_account) { Fabricate(:account) }
  6. let(:strike) { Fabricate(:account_warning, target_account: target_account, action: :suspend) }
  7. let(:appeal) { Fabricate(:appeal, strike: strike, account: target_account) }
  8. before do
  9. target_account.suspend!
  10. end
  11. describe 'POST #approve' do
  12. let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  13. before do
  14. allow(UserMailer).to receive(:appeal_approved).and_return(double('email', deliver_later: nil))
  15. post :approve, params: { id: appeal.id }
  16. end
  17. it 'unsuspends a suspended account' do
  18. expect(target_account.reload.suspended?).to be false
  19. end
  20. it 'redirects back to the strike page' do
  21. expect(response).to redirect_to(disputes_strike_path(appeal.strike))
  22. end
  23. it 'notifies target account about approved appeal' do
  24. expect(UserMailer).to have_received(:appeal_approved).with(target_account.user, appeal)
  25. end
  26. end
  27. describe 'POST #reject' do
  28. let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  29. before do
  30. allow(UserMailer).to receive(:appeal_rejected).and_return(double('email', deliver_later: nil))
  31. post :reject, params: { id: appeal.id }
  32. end
  33. it 'redirects back to the strike page' do
  34. expect(response).to redirect_to(disputes_strike_path(appeal.strike))
  35. end
  36. it 'notifies target account about rejected appeal' do
  37. expect(UserMailer).to have_received(:appeal_rejected).with(target_account.user, appeal)
  38. end
  39. end
  40. end