Commit a289c353d2f36a5aed97c27434ff058c6c634960
1 parent
924f3a20
Exists in
staging
and in
42 other branches
ActionItem1219: deliver the e-mail after saving the model
Before the save transaction ends, postfix process will not have an updated vision of the users table, and the e-mail will fail.
Showing
3 changed files
with
16 additions
and
11 deletions
Show diff stats
app/models/email_activation.rb
app/models/user.rb
| ... | ... | @@ -39,17 +39,6 @@ class User < ActiveRecord::Base |
| 39 | 39 | @person_data || {} |
| 40 | 40 | end |
| 41 | 41 | |
| 42 | - attr_accessor :had_email_disabled | |
| 43 | - before_update do |user| | |
| 44 | - user.had_email_disabled = !User.find(user.id).enable_email | |
| 45 | - true | |
| 46 | - end | |
| 47 | - after_update do |user| | |
| 48 | - if user.had_email_disabled && user.enable_email && !user.environment.nil? | |
| 49 | - User::Mailer.deliver_activation_email_notify(user) | |
| 50 | - end | |
| 51 | - end | |
| 52 | - | |
| 53 | 42 | def email_domain |
| 54 | 43 | self.person.preferred_domain && self.person.preferred_domain.name || self.environment.default_hostname(true) |
| 55 | 44 | end | ... | ... |
test/unit/email_activation_test.rb
| ... | ... | @@ -2,6 +2,12 @@ require File.dirname(__FILE__) + '/../test_helper' |
| 2 | 2 | |
| 3 | 3 | class EmailActivationTest < Test::Unit::TestCase |
| 4 | 4 | |
| 5 | + def setup | |
| 6 | + ActionMailer::Base.delivery_method = :test | |
| 7 | + ActionMailer::Base.perform_deliveries = true | |
| 8 | + ActionMailer::Base.deliveries = [] | |
| 9 | + end | |
| 10 | + | |
| 5 | 11 | should 'require a requestor' do |
| 6 | 12 | task = EmailActivation.new |
| 7 | 13 | task.valid? |
| ... | ... | @@ -25,6 +31,15 @@ class EmailActivationTest < Test::Unit::TestCase |
| 25 | 31 | assert ze.enable_email |
| 26 | 32 | end |
| 27 | 33 | |
| 34 | + should 'deliver email after enabling mailbox' do | |
| 35 | + ze = create_user('zezinho', :environment_id => Environment.default.id, :email => 'ze@example.com') | |
| 36 | + assert !ze.enable_email | |
| 37 | + task = EmailActivation.create!(:requestor => ze.person, :target => Environment.default) | |
| 38 | + task.finish | |
| 39 | + | |
| 40 | + assert_equal ['zezinho@colivre.net'], ActionMailer::Base.deliveries.first.to | |
| 41 | + end | |
| 42 | + | |
| 28 | 43 | should 'create only once pending task by user' do |
| 29 | 44 | ze = create_user('zezinho', :environment_id => Environment.default.id) |
| 30 | 45 | task = EmailActivation.new(:requestor => ze.person, :target => Environment.default) | ... | ... |