diff options
-rw-r--r-- | app/mailers/track_mailer.rb | 7 | ||||
-rw-r--r-- | spec/mailers/track_mailer_spec.rb | 6 |
2 files changed, 5 insertions, 8 deletions
diff --git a/app/mailers/track_mailer.rb b/app/mailers/track_mailer.rb index 391143214..bc3c162a3 100644 --- a/app/mailers/track_mailer.rb +++ b/app/mailers/track_mailer.rb @@ -39,11 +39,8 @@ class TrackMailer < ApplicationMailer def self.alert_tracks done_something = false now = Time.now() - users = User.find(:all, :conditions => [ "last_daily_track_email < ?", now - 1.day ]) - if users.empty? - return done_something - end - for user in users + User.find_each(:conditions => [ "last_daily_track_email < ?", + now - 1.day ]) do |user| next if !user.should_be_emailed? || !user.receive_email_alerts email_about_things = [] diff --git a/spec/mailers/track_mailer_spec.rb b/spec/mailers/track_mailer_spec.rb index a3b849980..32012ca42 100644 --- a/spec/mailers/track_mailer_spec.rb +++ b/spec/mailers/track_mailer_spec.rb @@ -13,7 +13,7 @@ describe TrackMailer do it 'should ask for all the users whose last daily track email was sent more than a day ago' do expected_conditions = [ "last_daily_track_email < ?", Time.utc(2007, 11, 11, 23, 59)] - User.should_receive(:find).with(:all, :conditions => expected_conditions).and_return([]) + User.should_receive(:find_each).with(:conditions => expected_conditions) TrackMailer.alert_tracks end @@ -26,7 +26,7 @@ describe TrackMailer do :url_name => 'test-name', :get_locale => 'en', :should_be_emailed? => true) - User.stub!(:find).and_return([@user]) + User.stub!(:find_each).and_yield(@user) @user.stub!(:receive_email_alerts).and_return(true) @user.stub!(:no_xapian_reindex=) end @@ -124,7 +124,7 @@ describe TrackMailer do :save! => true, :url_name => 'test-name', :should_be_emailed? => false) - User.stub!(:find).and_return([@user]) + User.stub!(:find_each).and_yield(@user) @user.stub!(:receive_email_alerts).and_return(true) @user.stub!(:no_xapian_reindex=) end |