change_email_controller_spec.rb 1.2 KB

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