You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.0 KiB

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