diff options
author | Sean McGivern <sean@gitlab.com> | 2018-03-30 14:05:20 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-03-30 14:55:05 +0100 |
commit | 2db218f8bf186c509c927ce3e9d0502fee4f8349 (patch) | |
tree | 8290216f729e4d5d376986720b5f730eb16e4141 /spec/workers | |
parent | 5ab75649f3ea00b64cb63e7e5283100c6b70cfb5 (diff) | |
download | gitlab-ce-2db218f8bf186c509c927ce3e9d0502fee4f8349.tar.gz |
Send emails for issues due tomorrow
Also, refactor the mail sending slightly: instead of one worker sending all
emails, create a worker per project with issues due, which will send all emails
for that project.
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/issue_due_scheduler_worker_spec.rb | 23 | ||||
-rw-r--r-- | spec/workers/issue_due_worker_spec.rb | 17 | ||||
-rw-r--r-- | spec/workers/mail_scheduler/issue_due_worker_spec.rb | 21 |
3 files changed, 44 insertions, 17 deletions
diff --git a/spec/workers/issue_due_scheduler_worker_spec.rb b/spec/workers/issue_due_scheduler_worker_spec.rb new file mode 100644 index 00000000000..eff5855834c --- /dev/null +++ b/spec/workers/issue_due_scheduler_worker_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe IssueDueSchedulerWorker do + describe '#perform' do + it 'schedules one MailScheduler::IssueDueWorker per project with open issues due tomorrow' do + project1 = create(:project) + project2 = create(:project) + project_closed_issue = create(:project) + project_issue_due_another_day = create(:project) + + create(:issue, :opened, project: project1, due_date: Date.tomorrow) + create(:issue, :opened, project: project1, due_date: Date.tomorrow) + create(:issue, :opened, project: project2, due_date: Date.tomorrow) + create(:issue, :closed, project: project_closed_issue, due_date: Date.tomorrow) + create(:issue, :opened, project: project_issue_due_another_day, due_date: Date.today) + + expect(MailScheduler::IssueDueWorker).to receive(:perform_async).with(project1.id) + expect(MailScheduler::IssueDueWorker).to receive(:perform_async).with(project2.id) + + described_class.new.perform + end + end +end diff --git a/spec/workers/issue_due_worker_spec.rb b/spec/workers/issue_due_worker_spec.rb deleted file mode 100644 index 9004edbee3a..00000000000 --- a/spec/workers/issue_due_worker_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'spec_helper' - -describe IssueDueWorker do - describe 'perform' do - let(:worker) { described_class.new } - - it 'finds issues due on the day run' do - issue1 = create(:issue, :opened, due_date: Date.today) - create(:issue, :opened, due_date: 3.days.from_now) - create(:issue, :opened, due_date: 4.days.from_now) - - expect_any_instance_of(NotificationService).to receive(:issue_due_email).with(issue1) - - worker.perform - end - end -end diff --git a/spec/workers/mail_scheduler/issue_due_worker_spec.rb b/spec/workers/mail_scheduler/issue_due_worker_spec.rb new file mode 100644 index 00000000000..48ac1b8a1a4 --- /dev/null +++ b/spec/workers/mail_scheduler/issue_due_worker_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe MailScheduler::IssueDueWorker do + describe '#perform' do + let(:worker) { described_class.new } + let(:project) { create(:project) } + + it 'sends emails for open issues due tomorrow in the project specified' do + issue1 = create(:issue, :opened, project: project, due_date: Date.tomorrow) + issue2 = create(:issue, :opened, project: project, due_date: Date.tomorrow) + create(:issue, :closed, project: project, due_date: Date.tomorrow) # closed + create(:issue, :opened, project: project, due_date: 2.days.from_now) # due on another day + create(:issue, :opened, due_date: Date.tomorrow) # different project + + expect_any_instance_of(NotificationService).to receive(:issue_due).with(issue1) + expect_any_instance_of(NotificationService).to receive(:issue_due).with(issue2) + + worker.perform(project.id) + end + end +end |