marks notifications as emailed after rake
This commit is contained in:
@@ -7,7 +7,7 @@ class EmailDigest
|
|||||||
end
|
end
|
||||||
|
|
||||||
def notifications
|
def notifications
|
||||||
user.notifications.not_emailed.where(notifiable_type: "ProposalNotification").to_a
|
user.notifications.not_emailed.where(notifiable_type: "ProposalNotification")
|
||||||
end
|
end
|
||||||
|
|
||||||
def pending_notifications?
|
def pending_notifications?
|
||||||
@@ -16,8 +16,12 @@ class EmailDigest
|
|||||||
|
|
||||||
def deliver
|
def deliver
|
||||||
if pending_notifications?
|
if pending_notifications?
|
||||||
Mailer.proposal_notification_digest(user, notifications).deliver_later
|
Mailer.proposal_notification_digest(user, notifications.to_a).deliver_later
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mark_as_emailed
|
||||||
|
notifications.update_all(emailed_at: Time.now)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -5,6 +5,7 @@ namespace :emails do
|
|||||||
User.email_digest.find_each do |user|
|
User.email_digest.find_each do |user|
|
||||||
email_digest = EmailDigest.new(user)
|
email_digest = EmailDigest.new(user)
|
||||||
email_digest.deliver
|
email_digest.deliver
|
||||||
|
email_digest.mark_as_emailed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -94,4 +94,27 @@ describe EmailDigest do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "mark_as_emailed" do
|
||||||
|
|
||||||
|
it "marks notifications as emailed" do
|
||||||
|
user = create(:user)
|
||||||
|
|
||||||
|
proposal_notification = create(:proposal_notification)
|
||||||
|
notification1 = create(:notification, notifiable: proposal_notification, user: user)
|
||||||
|
notification2 = create(:notification, notifiable: proposal_notification, user: user)
|
||||||
|
|
||||||
|
expect(notification1.emailed_at).to_not be
|
||||||
|
expect(notification2.emailed_at).to_not be
|
||||||
|
|
||||||
|
email_digest = EmailDigest.new(user)
|
||||||
|
email_digest.mark_as_emailed
|
||||||
|
|
||||||
|
notification1.reload
|
||||||
|
notification2.reload
|
||||||
|
expect(notification1.emailed_at).to be
|
||||||
|
expect(notification2.emailed_at).to be
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user