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.

60 lines
2.0 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe UserMailer, type: :mailer do
  4. let(:receiver) { Fabricate(:user) }
  5. shared_examples 'localized subject' do |*args, **kwrest|
  6. it 'renders subject localized for the locale of the receiver' do
  7. locale = I18n.available_locales.sample
  8. receiver.update!(locale: locale)
  9. expect(mail.subject).to eq I18n.t(*args, kwrest.merge(locale: locale))
  10. end
  11. it 'renders subject localized for the default locale if the locale of the receiver is unavailable' do
  12. receiver.update!(locale: nil)
  13. expect(mail.subject).to eq I18n.t(*args, kwrest.merge(locale: I18n.default_locale))
  14. end
  15. end
  16. describe 'confirmation_instructions' do
  17. let(:mail) { UserMailer.confirmation_instructions(receiver, 'spec') }
  18. it 'renders confirmation instructions' do
  19. receiver.update!(locale: nil)
  20. expect(mail.body.encoded).to include receiver.email
  21. expect(mail.body.encoded).to include 'spec'
  22. expect(mail.body.encoded).to include Rails.configuration.x.local_domain
  23. end
  24. include_examples 'localized subject',
  25. 'devise.mailer.confirmation_instructions.subject',
  26. instance: Rails.configuration.x.local_domain
  27. end
  28. describe 'reset_password_instructions' do
  29. let(:mail) { UserMailer.reset_password_instructions(receiver, 'spec') }
  30. it 'renders reset password instructions' do
  31. receiver.update!(locale: nil)
  32. expect(mail.body.encoded).to include receiver.email
  33. expect(mail.body.encoded).to include 'spec'
  34. end
  35. include_examples 'localized subject',
  36. 'devise.mailer.reset_password_instructions.subject'
  37. end
  38. describe 'password_change' do
  39. let(:mail) { UserMailer.password_change(receiver) }
  40. it 'renders password change notification' do
  41. receiver.update!(locale: nil)
  42. expect(mail.body.encoded).to include receiver.email
  43. end
  44. include_examples 'localized subject',
  45. 'devise.mailer.password_change.subject'
  46. end
  47. end