Commit acff33fea0161d24e6b31d73cf9b11d3fe6d97a3
Committed by
Luciano Prestes
1 parent
953a006f
Exists in
merge_deactive_and_ban
AI3285: Send email when user is deactivated
- Add ban_user_mail.html.erb template - Add tests Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Parley Martins <parley@outlook.com>
Showing
4 changed files
with
32 additions
and
2 deletions
Show diff stats
app/mailers/user_mailer.rb
... | ... | @@ -44,15 +44,19 @@ class UserMailer < ActionMailer::Base |
44 | 44 | def ban_user_mail_with_reason(user, reason, deactivated_profile) |
45 | 45 | subject = _("[%{environment}] Profile deactivated") % { :environment => user.environment.name } |
46 | 46 | @reason = reason |
47 | + @deactivated_name = deactivated_profile.name | |
48 | + end | |
49 | + | |
50 | + def ban_user_mail(user) | |
47 | 51 | @recipient = user.name |
48 | 52 | @name = user.name |
49 | - @deactivated_name = deactivated_profile.name | |
53 | + @email = user.email | |
50 | 54 | @environment = user.environment.name |
51 | 55 | @url = url_for(:host => user.environment.default_hostname, :controller => 'home') |
52 | 56 | mail( |
53 | 57 | to: user.email, |
54 | 58 | from: "#{user.environment.name} <#{user.environment.contact_email}>", |
55 | - subject: _(subject) % { :environment => user.environment.name } | |
59 | + subject: _(subject) % { :environment => user.environment.name } | |
56 | 60 | ) |
57 | 61 | end |
58 | 62 | ... | ... |
app/models/user.rb
... | ... | @@ -133,6 +133,7 @@ class User < ActiveRecord::Base |
133 | 133 | self.person.visible = false |
134 | 134 | begin |
135 | 135 | self.person.save! && self.save! |
136 | + UserMailer.ban_user_mail(person.user).deliver | |
136 | 137 | rescue Exception => exception |
137 | 138 | logger.error(exception.to_s) |
138 | 139 | false | ... | ... |
test/unit/user_mailer_test.rb
... | ... | @@ -18,6 +18,7 @@ class UserMailerTest < ActiveSupport::TestCase |
18 | 18 | end |
19 | 19 | end |
20 | 20 | |
21 | +<<<<<<< HEAD | |
21 | 22 | should 'deliver deactivation email' do |
22 | 23 | assert_difference 'ActionMailer::Base.deliveries.size' do |
23 | 24 | u = create_user('some-user') |
... | ... | @@ -31,6 +32,18 @@ class UserMailerTest < ActiveSupport::TestCase |
31 | 32 | assert_match("[#{u.environment}] Profile deactivated", email.subject) |
32 | 33 | end |
33 | 34 | |
35 | + should 'deliver deactivation email notify' do | |
36 | + user = create_user('some-user', :email => 'teste@teste.com') | |
37 | + assert_difference 'ActionMailer::Base.deliveries.size' do | |
38 | + UserMailer.ban_user_mail(user).deliver | |
39 | + end | |
40 | + end | |
41 | + | |
42 | + should 'verify deactivation email notification' do | |
43 | + user = create_user('some-user', :email => 'teste@teste.com') | |
44 | + email = UserMailer.ban_user_mail(user).deliver | |
45 | + end | |
46 | + | |
34 | 47 | private |
35 | 48 | |
36 | 49 | def read_fixture(action) | ... | ... |