Browse Source

Add Check.domain_expires_in_days

rails6
Jérémy Lecour 1 year ago
parent
commit
e9de5d5c32
3 changed files with 18 additions and 6 deletions
  1. +2
    -6
      app/mailers/notifications_mailer.rb
  2. +4
    -0
      app/models/check.rb
  3. +12
    -0
      test/models/check_test.rb

+ 2
- 6
app/mailers/notifications_mailer.rb View File

@ -11,19 +11,15 @@ class NotificationsMailer < ApplicationMailer
end
def domain_expires_soon
@expire_in_days = Integer(@check.domain_expires_at.to_date - Date.today)
I18n.with_locale params&.fetch(:locale) { @check.user.locale } do
subject = t(".subject", domain: @check.domain, count: @expire_in_days)
subject = t(".subject", domain: @check.domain, count: @check.domain_expires_in_days)
mail subject: subject, to: @notification.recipient
end
end
def ssl_expires_soon
@expire_in_days = Integer(@check.domain_expires_at.to_date - Date.today)
I18n.with_locale params&.fetch(:locale) { @check.user.locale } do
subject = t(".subject", domain: @check.domain, count: @expire_in_days)
subject = t(".subject", domain: @check.domain, count: @check.domain_expires_in_days)
mail subject: subject, to: @notification.recipient
end
end


+ 4
- 0
app/models/check.rb View File

@ -105,6 +105,10 @@ class Check < ApplicationRecord
end
end
def domain_expires_in_days
Integer(domain_expires_at.to_date - Time.now.utc.to_date)
end
private
def domain_created_at_past


+ 12
- 0
test/models/check_test.rb View File

@ -123,4 +123,16 @@ class CheckTest < ActiveSupport::TestCase
check.save!
assert check.mode?
end
test "expiration in days (future)" do
check = create(:check, domain_expires_at: 1.week.from_now)
assert_equal 7, check.domain_expires_in_days
end
test "expiration in days (past)" do
check = create(:check, domain_expires_at: 1.week.ago)
assert_equal -7, check.domain_expires_in_days
end
end

Loading…
Cancel
Save