reviewer reminder worker
This commit is contained in:
parent
5f3dfb5c96
commit
bf6c686e2e
32
app/workers/reviewer_reminder.rb
Normal file
32
app/workers/reviewer_reminder.rb
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
class ReviewerReminder
|
||||||
|
def initialize
|
||||||
|
@collection = reminder_collection
|
||||||
|
end
|
||||||
|
|
||||||
|
def count
|
||||||
|
@collection.count
|
||||||
|
end
|
||||||
|
alias size count
|
||||||
|
|
||||||
|
def reminders
|
||||||
|
@reminders ||= @collection.to_hash.map { |r| OpenStruct.new(r) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_all
|
||||||
|
reminders.each do |reminder|
|
||||||
|
ReviewerMailer.reminder(reminder).deliver_now
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def reminder_collection
|
||||||
|
sql = "select u.name, u.email, c.test_hash, c.project
|
||||||
|
from reviewer_votes rev
|
||||||
|
inner join users u on u.id = rev.user_id
|
||||||
|
inner join candidates c on c.id = rev.candidate_id
|
||||||
|
where rev.vote = 0 and rev.veto = 0 and u.active is not false;"
|
||||||
|
ActiveRecord::Base.connection.exec_query(sql)
|
||||||
|
end
|
||||||
|
end
|
@ -5,4 +5,10 @@ namespace :reminders do
|
|||||||
reminders = CandidateReminder.new
|
reminders = CandidateReminder.new
|
||||||
reminders.send_all
|
reminders.send_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "send reminders to reviewers"
|
||||||
|
task reviewers: :environment do
|
||||||
|
reminders = ReviewerReminder.new
|
||||||
|
reminders.send_all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
25
test/workers/reviewer_reminder_test.rb
Normal file
25
test/workers/reviewer_reminder_test.rb
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ReviewerReminderTest < ActiveSupport::TestCase
|
||||||
|
test "collection is created with four results" do
|
||||||
|
reminders = ReviewerReminder.new
|
||||||
|
assert_equal 3, reminders.size
|
||||||
|
end
|
||||||
|
|
||||||
|
test "each reminder has needed attributes" do
|
||||||
|
collection = ReviewerReminder.new
|
||||||
|
|
||||||
|
assert_instance_of String, collection.reminders.first.name
|
||||||
|
assert_instance_of String, collection.reminders.first.email
|
||||||
|
assert_instance_of String, collection.reminders.first.test_hash
|
||||||
|
end
|
||||||
|
|
||||||
|
test "send_all sends emails for each reviewer and test" do
|
||||||
|
collection = ReviewerReminder.new
|
||||||
|
|
||||||
|
assert_difference("ActionMailer::Base.deliveries.size", collection.count) do
|
||||||
|
collection.send_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user