闭社主体 forked from https://github.com/tootsuite/mastodon
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.

47 lines
1.2 KiB

  1. require 'rails_helper'
  2. RSpec.describe Admin::ChangeEmailsController, type: :controller do
  3. render_views
  4. let(:admin) { Fabricate(:user, admin: true) }
  5. before do
  6. sign_in admin
  7. end
  8. describe "GET #show" do
  9. it "returns http success" do
  10. account = Fabricate(:account)
  11. user = Fabricate(:user, account: account)
  12. get :show, params: { account_id: 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).and_return(double('email', deliver_later: nil))
  19. end
  20. it "returns http success" do
  21. account = Fabricate(:account)
  22. user = Fabricate(:user, account: account)
  23. previous_email = user.email
  24. post :update, params: { account_id: 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).not_to 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(account.id))
  31. end
  32. end
  33. end