Commit 322e838c authored by dgt's avatar dgt
Browse files

Bringing back email notifications - first steps

- added a cronjob to call mailer for digest
- added unit test for additional change types for single notification
parent e89ba9e4
......@@ -19,6 +19,8 @@ class CronController < ActionController::Base
Tracking::Daily.update
when 'codes_expire'
Page::AccessCode.cleanup_expired
when 'deliver_digests'
Mailer::PageHistories.deliver_digests
else
raise 'no such cron action'
end
......
......@@ -77,7 +77,7 @@ class Mailer::PageHistories < ActionMailer::Base
def self.page_histories
Page::History.where(notification_digest_sent_at: nil)
.where('DATE(page_histories.created_at) >= DATE(?)', DIGEST_TIMESPAN.ago)
.where('DATE(page_histories.created_at) < DATE(?)', Time.now)
# .where('DATE(page_histories.created_at) < DATE(?)', Time.now) # do we need this? we do not have histories from the future
end
def page_histories_for(user)
......
......@@ -71,6 +71,10 @@ module Crabgrass
config.exceptions_app = Crabgrass::PublicExceptions.new(Rails.public_path)
# FIXME: Needed for Rails 4.2 according to the documentation
# config.active_job.queue_adapter = :delayed_job
##
## PLUGINS
##
......
......@@ -13,6 +13,7 @@ Crabgrass::Application.configure do
config.action_mailer.raise_delivery_errors = false
config.log_level = Conf.log_level || :debug
config.action_mailer.default_url_options = { host: 'localhost' }
## FIXME: when reloading plugins is enabled, SearchFilter.filters will be
## empty after the first request.
config.reload_plugins = false
......
......@@ -40,3 +40,8 @@ every 1.day do
curl 'codes_expire'
curl 'tracking_update_dailies'
end
every 1.hour, :at => '0:20' do
curl 'deliver_digests'
end
......@@ -52,6 +52,16 @@ class Mailer::PageHistoriesTest < ActionMailer::TestCase
assert_includes mail.body, 'Green! has modified the page title'
end
def test_send_simple_update_comment_and_wiki
receive_notifications 'Single'
added_comment_as users(:red), 1.minute.ago
updated_wiki_as users(:red), 1.minute.ago
mail = mailer_class.deliver_updates_for(page, to: [@user]).first
assert ActionMailer::Base.deliveries.present?
assert_includes mail.body, 'Red! added a comment'
assert_includes mail.body, 'Red! has updated the page content'
end
def test_send_paranoid_update
with_paranoid_emails
receive_notifications 'Single'
......@@ -87,6 +97,23 @@ class Mailer::PageHistoriesTest < ActionMailer::TestCase
Page::History::ChangeTitle.create user: user, page: page, created_at: time
end
def added_comment_as(user, time = 1.day.ago)
post = FactoryGirl.create(:post)
page.add_post(user, body: post)
page.updated_by user
page.save
assert page.discussion.present?
Page::History::AddComment.create user: user, page: page, created_at: time, item: post
end
def updated_wiki_as(user, time = 1.day.ago)
page.updated_by user
page.save
assert page.discussion.present?
Page::History::UpdatedContent.create user: user, page: page, created_at: time
end
def page
@page ||= pages(:blue_page)
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment