diff options
-rw-r--r-- | app/models/user.rb | 16 | ||||
-rw-r--r-- | spec/models/track_mailer_spec.rb | 33 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 11 |
3 files changed, 51 insertions, 9 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 82c7c5fae..aee701031 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -343,6 +343,12 @@ class User < ActiveRecord::Base } end + def record_bounce(message) + self.email_bounced_at = Time.now + self.email_bounce_message = message + self.save! + end + private def User.encrypted_password(password, salt) @@ -354,21 +360,15 @@ class User < ActiveRecord::Base self.salt = self.object_id.to_s + rand.to_s end - def record_bounce(message) - self.email_bounced_at = Time.now - self.email_bounce_message = message - self.save! - end - def should_be_emailed? return (self.email_confirmed && self.email_bounced_at.nil?) end def User.record_bounce_for_email(email, message) - user = self.find_user_by_email(email) + user = User.find_user_by_email(email) return false if user.nil? - if user.self.email_bounced_at.nil? + if user.email_bounced_at.nil? user.record_bounce(message) end return true diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb index 828904d02..504d65144 100644 --- a/spec/models/track_mailer_spec.rb +++ b/spec/models/track_mailer_spec.rb @@ -21,7 +21,8 @@ describe TrackMailer do @user = mock_model(User, :no_xapian_reindex= => false, :last_daily_track_email= => true, :save! => true, - :url_name => 'test-name') + :url_name => 'test-name', + :should_be_emailed? => true) User.stub!(:find).and_return([@user]) @user.stub!(:no_xapian_reindex=) end @@ -109,6 +110,36 @@ describe TrackMailer do end + describe 'when a user should not be emailed' do + before do + @user = mock_model(User, :no_xapian_reindex= => false, + :last_daily_track_email= => true, + :save! => true, + :url_name => 'test-name', + :should_be_emailed? => false) + User.stub!(:find).and_return([@user]) + @user.stub!(:no_xapian_reindex=) + end + + it 'should not ask for any daily track things for the user' do + expected_conditions = [ "tracking_user_id = ? and track_medium = ?", @user.id, 'email_daily' ] + TrackThing.should_not_receive(:find).with(:all, :conditions => expected_conditions).and_return([]) + TrackMailer.alert_tracks + end + + + it 'should not set the no_xapian_reindex flag on the user' do + @user.should_not_receive(:no_xapian_reindex=).with(true) + TrackMailer.alert_tracks + end + + it 'should not update the time of the user\'s last daily tracking email' do + @user.should_not_receive(:last_daily_track_email=).with(Time.now) + @user.should_not_receive(:save!) + TrackMailer.alert_tracks + end + end + end describe 'delivering the email' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ee6916ffc..fc56d3365 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -282,3 +282,14 @@ describe User, "when setting a profile photo" do # end end +describe User, "when emails have bounced" do + fixtures :users + + it "should record bounces" do + User.record_bounce_for_email("bob@localhost", "The reason we think the email bounced (e.g. a bounce message)") + + user = User.find_user_by_email("bob@localhost") + user.email_bounced_at.should_not be_nil + user.email_bounce_message.should == "The reason we think the email bounced (e.g. a bounce message)" + end +end |