1
0

confirmations_controller_spec.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. require 'rails_helper'
  2. RSpec.describe Admin::ConfirmationsController, type: :controller do
  3. render_views
  4. before do
  5. sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
  6. end
  7. describe 'POST #create' do
  8. it 'confirms the user' do
  9. user = Fabricate(:user, confirmed_at: false)
  10. post :create, params: { account_id: user.account.id }
  11. expect(response).to redirect_to(admin_accounts_path)
  12. expect(user.reload).to be_confirmed
  13. end
  14. it 'raises an error when there is no account' do
  15. post :create, params: { account_id: 'fake' }
  16. expect(response).to have_http_status(404)
  17. end
  18. it 'raises an error when there is no user' do
  19. account = Fabricate(:account, user: nil)
  20. post :create, params: { account_id: account.id }
  21. expect(response).to have_http_status(404)
  22. end
  23. end
  24. describe 'POST #resernd' do
  25. subject { post :resend, params: { account_id: user.account.id } }
  26. let!(:user) { Fabricate(:user, confirmed_at: confirmed_at) }
  27. before do
  28. allow(UserMailer).to receive(:confirmation_instructions) { double(:email, deliver_later: nil) }
  29. end
  30. context 'when email is not confirmed' do
  31. let(:confirmed_at) { nil }
  32. it 'resends confirmation mail' do
  33. expect(subject).to redirect_to admin_accounts_path
  34. expect(flash[:notice]).to eq I18n.t('admin.accounts.resend_confirmation.success')
  35. expect(UserMailer).to have_received(:confirmation_instructions).once
  36. end
  37. end
  38. context 'when email is confirmed' do
  39. let(:confirmed_at) { Time.zone.now }
  40. it 'does not resend confirmation mail' do
  41. expect(subject).to redirect_to admin_accounts_path
  42. expect(flash[:error]).to eq I18n.t('admin.accounts.resend_confirmation.already_confirmed')
  43. expect(UserMailer).not_to have_received(:confirmation_instructions)
  44. end
  45. end
  46. end
  47. end