about summary refs log tree commit diff
path: root/spec/mailers
diff options
context:
space:
mode:
authorAkihiko Odaki (@fn_aki@pawoo.net) <akihiko.odaki.4i@stu.hosei.ac.jp>2017-06-17 08:15:00 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-06-17 01:15:00 +0200
commit74d10b9b9d60426ed44e5c6d361db7a44996236a (patch)
tree87c4475b5844f7facfc72042ad602168b205bdcb /spec/mailers
parent2356580cee9d485d6e33d7b51ea2d83632cf791e (diff)
Spec UserMailer (#3757)
Diffstat (limited to 'spec/mailers')
-rw-r--r--spec/mailers/user_mailer_spec.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb
new file mode 100644
index 000000000..1f6d44015
--- /dev/null
+++ b/spec/mailers/user_mailer_spec.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+describe UserMailer, type: :mailer do
+  let(:receiver) { Fabricate(:user) }
+
+  shared_examples 'localized subject' do |*args, **kwrest|
+    it 'renders subject localized for the locale of the receiver' do
+      locale = I18n.available_locales.sample
+      receiver.update!(locale: locale)
+      expect(mail.subject).to eq I18n.t(*args, kwrest.merge(locale: locale))
+    end
+
+    it 'renders subject localized for the default locale if the locale of the receiver is unavailable' do
+      receiver.update!(locale: nil)
+      expect(mail.subject).to eq I18n.t(*args, kwrest.merge(locale: I18n.default_locale))
+    end
+  end
+
+  describe 'confirmation_instructions' do
+    let(:mail) { UserMailer.confirmation_instructions(receiver, 'spec') }
+
+    it 'renders confirmation instructions' do
+      receiver.update!(locale: nil)
+      expect(mail.body.encoded).to include receiver.email
+      expect(mail.body.encoded).to include 'spec'
+      expect(mail.body.encoded).to include Rails.configuration.x.local_domain
+    end
+
+    include_examples 'localized subject',
+                     'devise.mailer.confirmation_instructions.subject',
+                     instance: Rails.configuration.x.local_domain
+  end
+
+  describe 'reset_password_instructions' do
+    let(:mail) { UserMailer.reset_password_instructions(receiver, 'spec') }
+
+    it 'renders reset password instructions' do
+      receiver.update!(locale: nil)
+      expect(mail.body.encoded).to include receiver.email
+      expect(mail.body.encoded).to include 'spec'
+    end
+
+    include_examples 'localized subject',
+                     'devise.mailer.reset_password_instructions.subject'
+  end
+
+  describe 'password_change' do
+    let(:mail) { UserMailer.password_change(receiver) }
+
+    it 'renders password change notification' do
+      receiver.update!(locale: nil)
+      expect(mail.body.encoded).to include receiver.email
+    end
+
+    include_examples 'localized subject',
+                     'devise.mailer.password_change.subject'
+  end
+end