1
0

reset_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Admin::Reset' do
  4. it 'Resets password for account user', :inline_jobs do
  5. account = Fabricate :account
  6. sign_in admin_user
  7. visit admin_account_path(account.id)
  8. emails = capture_emails do
  9. expect { submit_reset }
  10. .to change(Admin::ActionLog.where(target: account.user), :count).by(1)
  11. end
  12. expect(emails.first)
  13. .to be_present
  14. .and(deliver_to(account.user.email))
  15. .and(have_subject(password_change_subject))
  16. expect(emails.last)
  17. .to be_present
  18. .and(deliver_to(account.user.email))
  19. .and(have_subject(reset_instructions_subject))
  20. expect(page)
  21. .to have_content(account.username)
  22. end
  23. def admin_user
  24. Fabricate(:user, role: UserRole.find_by(name: 'Admin'))
  25. end
  26. def submit_reset
  27. click_on I18n.t('admin.accounts.reset_password')
  28. end
  29. def password_change_subject
  30. I18n.t('devise.mailer.password_change.subject')
  31. end
  32. def reset_instructions_subject
  33. I18n.t('devise.mailer.reset_password_instructions.subject')
  34. end
  35. end