diff options
-rw-r--r-- | app/mailers/track_mailer.rb | 10 | ||||
-rw-r--r-- | spec/mailers/track_mailer_spec.rb | 6 |
2 files changed, 7 insertions, 9 deletions
diff --git a/app/mailers/track_mailer.rb b/app/mailers/track_mailer.rb index 391143214..7157e12d8 100644 --- a/app/mailers/track_mailer.rb +++ b/app/mailers/track_mailer.rb @@ -39,11 +39,9 @@ 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 + one_week_ago = now - 7.days + 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 = [] @@ -76,7 +74,7 @@ class TrackMailer < ApplicationMailer end next if track_thing.created_at >= result[:model].described_at # made before the track was created - next if result[:model].described_at < now - 7.days # older than 1 week (see 14 days / 7 days in comment above) + next if result[:model].described_at < one_week_ago # older than 1 week (see 14 days / 7 days in comment above) next if done_info_request_events.include?(result[:model].id) # definitely already done # OK alert this one 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 |