about summary refs log tree commit diff
path: root/app/workers
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-10 09:45:43 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-10 15:45:43 +0200
commitd142544159dee7a93e31c886737e12c5bca8844a (patch)
tree6de1b55769c8def200d34b2a10de54966ea89619 /app/workers
parent7ac092513c3c298ad80cb80f7bee76ca8ed56235 (diff)
Spec coverage and refactor of digest mailer worker (#2961)
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/digest_mailer_worker.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/app/workers/digest_mailer_worker.rb b/app/workers/digest_mailer_worker.rb
index dedb21e4e..028db89a9 100644
--- a/app/workers/digest_mailer_worker.rb
+++ b/app/workers/digest_mailer_worker.rb
@@ -5,10 +5,21 @@ class DigestMailerWorker
 
   sidekiq_options queue: 'mailers'
 
+  attr_reader :user
+
   def perform(user_id)
-    user = User.find(user_id)
-    return unless user.settings.notification_emails['digest']
+    @user = User.find(user_id)
+    deliver_digest if user_receives_digest?
+  end
+
+  private
+
+  def deliver_digest
     NotificationMailer.digest(user.account).deliver_now!
     user.touch(:last_emailed_at)
   end
+
+  def user_receives_digest?
+    user.settings.notification_emails['digest']
+  end
 end