Commit 7830fa06580ba29179cecfcd30bb442ba989987e

Authored by Rodrigo Souto
1 parent e0fed871

rails3: fix user_mailer

app/mailers/user_mailer.rb 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +class User::Mailer < ActionMailer::Base
  2 + def activation_email_notify(user)
  3 + user_email = "#{user.login}@#{user.email_domain}"
  4 + @name = user.name
  5 + @email = user_email
  6 + @webmail = MailConf.webmail_url(user.login, user.email_domain)
  7 + @environment = user.environment.name
  8 + @url = url_for(:host => user.environment.default_hostname, :controller => 'home')
  9 +
  10 + mail(
  11 + to: user_email,
  12 + from: "#{user.environment.name} <#{user.environment.contact_email}>",
  13 + subject: _("[%{environment}] Welcome to %{environment} mail!") % { :environment => user.environment.name }
  14 + )
  15 + end
  16 +
  17 + def activation_code(user)
  18 + @recipient = user.name,
  19 + @activation_code = user.activation_code
  20 + @environment = user.environment.name
  21 + @url = user.environment.top_url
  22 +
  23 + mail(
  24 + from: "#{user.environment.name} <#{user.environment.contact_email}>",
  25 + to: user.email,
  26 + subject: _("[%s] Activate your account") % [user.environment.name],
  27 + )
  28 + end
  29 +
  30 + def signup_welcome_email(user)
  31 + @body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name)
  32 +
  33 + email_subject = user.environment.signup_welcome_text_subject
  34 + mail(
  35 + content_type: 'text/html',
  36 + recipients: user.email,
  37 + from: "#{user.environment.name} <#{user.environment.contact_email}>",
  38 + subject: email_subject.blank? ? _("Welcome to environment %s") % [user.environment.name] : email_subject
  39 + )
  40 + end
  41 +end
... ...
app/models/user.rb
... ... @@ -62,48 +62,6 @@ class User &lt; ActiveRecord::Base
62 62 self.person.preferred_domain && self.person.preferred_domain.name || self.environment.default_hostname(true)
63 63 end
64 64  
65   - class Mailer < ActionMailer::Base
66   -
67   - # FIXME use new ActionMailer API here
68   - def activation_email_notify(user)
69   - user_email = "#{user.login}@#{user.email_domain}"
70   - recipients user_email
71   - from "#{user.environment.name} <#{user.environment.contact_email}>"
72   - subject _("[%{environment}] Welcome to %{environment} mail!") % { :environment => user.environment.name }
73   - body :name => user.name,
74   - :email => user_email,
75   - :webmail => MailConf.webmail_url(user.login, user.email_domain),
76   - :environment => user.environment.name,
77   - :url => url_for(:host => user.environment.default_hostname, :controller => 'home')
78   - end
79   -
80   - def activation_code(user)
81   - @recipient = user.name,
82   - @activation_code = user.activation_code
83   - @environment = user.environment.name
84   - @url = user.environment.top_url
85   -
86   - mail(
87   - :from => "#{user.environment.name} <#{user.environment.contact_email}>",
88   - :to => user.email,
89   - :subject => _("[%s] Activate your account") % [user.environment.name],
90   - )
91   - end
92   -
93   - # FIXME use new ActionMailer API here
94   - def signup_welcome_email(user)
95   - email_body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name)
96   - email_subject = user.environment.signup_welcome_text_subject
97   -
98   - content_type 'text/html'
99   - recipients user.email
100   -
101   - from "#{user.environment.name} <#{user.environment.contact_email}>"
102   - subject email_subject.blank? ? _("Welcome to environment %s") % [user.environment.name] : email_subject
103   - body email_body
104   - end
105   - end
106   -
107 65 def signup!
108 66 User.transaction do
109 67 self.save!
... ...
test/unit/user_mailer_test.rb
... ... @@ -14,9 +14,9 @@ class UserMailerTest &lt; ActiveSupport::TestCase
14 14  
15 15 should 'deliver activation email notify' do
16 16 assert_difference ActionMailer::Base.deliveries, :size do
17   - u = Person.find(:first).user
  17 + u = create_user('some-user')
18 18 u.environment = Environment.default
19   - User::Mailer.deliver_activation_email_notify(u)
  19 + User::Mailer.activation_email_notify(u).deliver
20 20 end
21 21 end
22 22  
... ...