warning_presets_controller_spec.rb 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::WarningPresetsController do
  4. render_views
  5. let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  6. before do
  7. sign_in user, scope: :user
  8. end
  9. describe 'GET #index' do
  10. it 'returns http success' do
  11. get :index
  12. expect(response).to have_http_status(:success)
  13. end
  14. end
  15. describe 'GET #edit' do
  16. let(:account_warning_preset) { Fabricate(:account_warning_preset) }
  17. it 'returns http success and renders edit' do
  18. get :edit, params: { id: account_warning_preset.id }
  19. expect(response).to have_http_status(:success)
  20. expect(response).to render_template(:edit)
  21. end
  22. end
  23. describe 'POST #create' do
  24. context 'with valid data' do
  25. it 'creates a new account_warning_preset and redirects' do
  26. expect do
  27. post :create, params: { account_warning_preset: { text: 'The account_warning_preset text.' } }
  28. end.to change(AccountWarningPreset, :count).by(1)
  29. expect(response).to redirect_to(admin_warning_presets_path)
  30. end
  31. end
  32. context 'with invalid data' do
  33. it 'does creates a new account_warning_preset and renders index' do
  34. expect do
  35. post :create, params: { account_warning_preset: { text: '' } }
  36. end.to_not change(AccountWarningPreset, :count)
  37. expect(response).to render_template(:index)
  38. end
  39. end
  40. end
  41. describe 'PUT #update' do
  42. let(:account_warning_preset) { Fabricate(:account_warning_preset, text: 'Original text') }
  43. context 'with valid data' do
  44. it 'updates the account_warning_preset and redirects' do
  45. put :update, params: { id: account_warning_preset.id, account_warning_preset: { text: 'Updated text.' } }
  46. expect(response).to redirect_to(admin_warning_presets_path)
  47. end
  48. end
  49. context 'with invalid data' do
  50. it 'does not update the account_warning_preset and renders index' do
  51. put :update, params: { id: account_warning_preset.id, account_warning_preset: { text: '' } }
  52. expect(response).to render_template(:edit)
  53. end
  54. end
  55. end
  56. describe 'DELETE #destroy' do
  57. let!(:account_warning_preset) { Fabricate(:account_warning_preset) }
  58. it 'destroys the account_warning_preset and redirects' do
  59. delete :destroy, params: { id: account_warning_preset.id }
  60. expect { account_warning_preset.reload }.to raise_error(ActiveRecord::RecordNotFound)
  61. expect(response).to redirect_to(admin_warning_presets_path)
  62. end
  63. end
  64. end