change_emails_controller_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Admin::ChangeEmailsController do
  4. render_views
  5. let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  6. before do
  7. sign_in admin
  8. end
  9. describe 'GET #show' do
  10. it 'returns http success' do
  11. user = Fabricate(:user)
  12. get :show, params: { account_id: user.account.id }
  13. expect(response).to have_http_status(200)
  14. end
  15. end
  16. describe 'GET #update' do
  17. before do
  18. allow(UserMailer).to receive(:confirmation_instructions)
  19. .and_return(instance_double(ActionMailer::MessageDelivery, deliver_later: nil))
  20. end
  21. it 'returns http success' do
  22. user = Fabricate(:user)
  23. previous_email = user.email
  24. post :update, params: { account_id: user.account.id, user: { unconfirmed_email: 'test@example.com' } }
  25. user.reload
  26. expect(user.email).to eq previous_email
  27. expect(user.unconfirmed_email).to eq 'test@example.com'
  28. expect(user.confirmation_token).to_not be_nil
  29. expect(UserMailer).to have_received(:confirmation_instructions).with(user, user.confirmation_token, { to: 'test@example.com' })
  30. expect(response).to redirect_to(admin_account_path(user.account.id))
  31. end
  32. end
  33. end