mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 02:39:37 +02:00
parent
0cc3a53deb
commit
f127716a39
5 changed files with 36 additions and 22 deletions
|
@ -1,11 +1,9 @@
|
|||
class DomainExpirationEmailJob < ActiveJob::Base
|
||||
queue_as :default
|
||||
|
||||
def perform(domain_id:)
|
||||
class DomainExpirationEmailJob < Que::Job
|
||||
def run(domain_id:)
|
||||
domain = Domain.find(domain_id)
|
||||
|
||||
return if domain.registered?
|
||||
|
||||
DomainMailer.expiration(domain).deliver!
|
||||
DomainMailer.expiration(domain: domain).deliver!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,18 +32,27 @@ class DomainCron
|
|||
end
|
||||
|
||||
def self.start_expire_period
|
||||
STDOUT << "#{Time.zone.now.utc} - Expiring domains\n" unless Rails.env.test?
|
||||
Rails.logger.info('Expiring domains')
|
||||
|
||||
::PaperTrail.whodunnit = "cron - #{__method__}"
|
||||
domains = Domain.where('valid_to <= ?', Time.zone.now)
|
||||
|
||||
domains = Domain.expired
|
||||
marked = 0
|
||||
real = 0
|
||||
|
||||
domains.each do |domain|
|
||||
next unless domain.expirable?
|
||||
real += 1
|
||||
domain.set_graceful_expired
|
||||
STDOUT << "#{Time.zone.now.utc} DomainCron.start_expire_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test?
|
||||
domain.save(validate: false) and marked += 1
|
||||
|
||||
send_time = domain.valid_to + Setting.expiration_reminder_mail.to_i.days
|
||||
saved = domain.save(validate: false)
|
||||
|
||||
if saved
|
||||
DomainExpirationEmailJob.enqueue(domain_id: domain.id, run_at: send_time)
|
||||
marked += 1
|
||||
end
|
||||
end
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - Successfully expired #{marked} of #{real} domains\n" unless Rails.env.test?
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DomainExpirationEmailJob do
|
||||
it 'queues the job' do
|
||||
expect { described_class.perform_later }.to have_enqueued_job(described_class)
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
describe '#run' do
|
||||
let(:domain) { instance_double(Domain) }
|
||||
|
||||
before :example do
|
||||
|
@ -22,7 +18,7 @@ RSpec.describe DomainExpirationEmailJob do
|
|||
it 'sends email notification' do
|
||||
expect(DomainMailer).to receive(:expiration).with(domain: domain).and_return(message)
|
||||
expect(message).to receive(:deliver!)
|
||||
described_class.perform_now(domain_id: 1)
|
||||
described_class.enqueue(domain_id: 1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -33,7 +29,7 @@ RSpec.describe DomainExpirationEmailJob do
|
|||
|
||||
it 'does not send email notification' do
|
||||
expect(DomainMailer).to_not receive(:expiration)
|
||||
described_class.perform_now(domain_id: 1)
|
||||
described_class.enqueue(domain_id: 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DomainCron do
|
||||
before :example do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
|
||||
@domain = Fabricate(:domain)
|
||||
end
|
||||
|
||||
it 'should expire domains' do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
@domain = Fabricate(:domain)
|
||||
|
||||
Setting.expire_warning_period = 1
|
||||
Setting.redemption_grace_period = 1
|
||||
|
||||
|
@ -28,6 +25,9 @@ RSpec.describe DomainCron do
|
|||
end
|
||||
|
||||
it 'should start redemption grace period' do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
@domain = Fabricate(:domain)
|
||||
|
||||
old_valid_to = Time.zone.now - 10.days
|
||||
@domain.valid_to = old_valid_to
|
||||
@domain.statuses = [DomainStatus::EXPIRED]
|
||||
|
@ -38,4 +38,15 @@ RSpec.describe DomainCron do
|
|||
@domain.reload
|
||||
@domain.statuses.include?(DomainStatus::EXPIRED).should == true
|
||||
end
|
||||
|
||||
describe '::start_expire_period', db: false do
|
||||
before :example do
|
||||
travel_to Time.zone.parse('05.07.2010')
|
||||
end
|
||||
|
||||
it 'logs start time' do
|
||||
expect(Rails.logger).to receive(:info).with('Expiring domains')
|
||||
described_class.start_expire_period
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe RegistrarPresenter do
|
||||
let(:registrar) { instance_double(Registrar) }
|
||||
let(:presenter) { described_class.new(registrar: registrar, view: nil) }
|
||||
let(:presenter) { described_class.new(registrar: registrar, view: view) }
|
||||
|
||||
describe '#name' do
|
||||
it 'returns name' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue