21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-02 17:00:49 +02:00

Merge pull request #20 from Evolix/pr-rename-delay-to-interval

Rename Notifications.delay to .interval
This commit is contained in:
Colin Darie 2018-07-02 09:57:02 +02:00 committed by GitHub
commit 1a50f36223
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 40 additions and 35 deletions

View file

@ -67,7 +67,7 @@ class ChecksController < ApplicationController
def check_params(*others) def check_params(*others)
params.require(:check).permit(:domain, :domain_created_at, :comment, :vendor, *others, params.require(:check).permit(:domain, :domain_created_at, :comment, :vendor, *others,
notifications_attributes: [:id, :channel, :recipient, :delay]) notifications_attributes: [:id, :channel, :recipient, :interval])
end end
def build_empty_notification def build_empty_notification

View file

@ -35,7 +35,7 @@ class NotificationsController < ApplicationController
end end
def notification_params def notification_params
params.require(:notification).permit(:channel, :recipient, :delay) params.require(:notification).permit(:channel, :recipient, :interval)
end end
def check_path def check_path

View file

@ -32,7 +32,7 @@ class Check < ApplicationRecord
has_many :notifications, validate: true, dependent: :destroy has_many :notifications, validate: true, dependent: :destroy
accepts_nested_attributes_for :notifications, accepts_nested_attributes_for :notifications,
allow_destroy: true, allow_destroy: true,
reject_if: lambda { |at| at["recipient"].blank? && at["delay"].blank? } reject_if: lambda { |at| at["recipient"].blank? && at["interval"].blank? }
enum kind: [:domain, :ssl] enum kind: [:domain, :ssl]

View file

@ -4,7 +4,7 @@
# #
# id :bigint(8) not null, primary key # id :bigint(8) not null, primary key
# channel :integer default("email"), not null # channel :integer default("email"), not null
# delay :integer not null # interval :integer not null
# recipient :string(255) not null # recipient :string(255) not null
# sent_at :datetime # sent_at :datetime
# status :integer default("pending"), not null # status :integer default("pending"), not null
@ -28,7 +28,7 @@ class Notification < ApplicationRecord
enum status: [:pending, :ongoing, :succeed, :failed] enum status: [:pending, :ongoing, :succeed, :failed]
validates :channel, presence: true validates :channel, presence: true
validates :delay, numericality: { only_integer: true, greater_than_or_equal_to: 1 } validates :interval, numericality: { only_integer: true, greater_than_or_equal_to: 1 }
validates :recipient, presence: true validates :recipient, presence: true
scope :active_check, -> { Check.active } scope :active_check, -> { Check.active }

View file

@ -4,7 +4,7 @@ module Notifier
scope scope
.where("checks.domain_expires_at >= CURDATE()") .where("checks.domain_expires_at >= CURDATE()")
.where("DATE(checks.domain_expires_at) .where("DATE(checks.domain_expires_at)
<= DATE_ADD(CURDATE(), INTERVAL notifications.delay DAY)") <= DATE_ADD(CURDATE(), INTERVAL notifications.interval DAY)")
end end
def resolve_check_failed def resolve_check_failed

View file

@ -15,7 +15,7 @@
</div> </div>
<div class="form-group col-md-2"> <div class="form-group col-md-2">
<%= f.input :delay, as: :integer, label: false %> <%= f.input :interval, as: :integer, label: false %>
</div> </div>
<div class="form-group col-md-1"> <div class="form-group col-md-1">

View file

@ -10,6 +10,6 @@
</div> </div>
<div class="col-md-2"> <div class="col-md-2">
<%= f.label :delay %> <%= f.label :interval %>
</div> </div>
</div> </div>

View file

@ -3,7 +3,7 @@
-- --
<p> <p>
You received this email because of the notification <%= delay %> days before the expiry date.<br /> You received this email because of the notification <%= interval %> days before the expiry date.<br />
You can handle the notifications for this check by following this link:<br /> You can handle the notifications for this check by following this link:<br />
<%= link_to nil, edit_check_url(check) %> <%= link_to nil, edit_check_url(check) %>
</p> </p>

View file

@ -1,6 +1,6 @@
-- --
You received this email because of the notification <%= delay %> days before the expiry date. You received this email because of the notification <%= interval %> days before the expiry date.
You can handle the notifications for this check by following this link: You can handle the notifications for this check by following this link:
<%= edit_check_url(check) %> <%= edit_check_url(check) %>

View file

@ -2,7 +2,7 @@
<br /> <br />
-- --
<p>You received this email because of the notification <%= delay %> days before <p>You received this email because of the notification <%= interval %> days before
the last known expiry date.<br /> the last known expiry date.<br />
You can handle the check by following this link: <br /> You can handle the check by following this link: <br />
<%= link_to nil, edit_check_url(check) %> <%= link_to nil, edit_check_url(check) %>

View file

@ -1,6 +1,6 @@
-- --
You received this email because of the notification <%= delay %> days before You received this email because of the notification <%= interval %> days before
the last known expiry date. the last known expiry date.
You can handle the check by following this link: You can handle the check by following this link:
<%= edit_check_url(check) %> <%= edit_check_url(check) %>

View file

@ -9,4 +9,4 @@
<%= render "check_comment_vendor" %> <%= render "check_comment_vendor" %>
<%= render "footer_expires_soon", delay: @notification.delay, check: @check %> <%= render "footer_expires_soon", interval: @notification.interval, check: @check %>

View file

@ -6,4 +6,4 @@ the domain <%= @check.domain %> will expire <%= format_utc(@check.domain_expires
<%= render "check_comment_vendor" %> <%= render "check_comment_vendor" %>
<%= render "footer_expires_soon", delay: @notification.delay, check: @check %> <%= render "footer_expires_soon", interval: @notification.interval, check: @check %>

View file

@ -22,4 +22,4 @@ or delete the check by following this link: <br /><br />
<%= render "check_comment_vendor" %> <%= render "check_comment_vendor" %>
<%= render "footer_recurrent_failures", delay: @notification.delay, check: @check %> <%= render "footer_recurrent_failures", interval: @notification.interval, check: @check %>

View file

@ -13,4 +13,4 @@ or delete the check by following this link:
<%= render "check_comment_vendor" %> <%= render "check_comment_vendor" %>
<%= render "footer_recurrent_failures", delay: @notification.delay, check: @check %> <%= render "footer_recurrent_failures", interval: @notification.interval, check: @check %>

View file

@ -58,7 +58,7 @@ Rails.application.configure do
config.active_record.verbose_query_logs = true config.active_record.verbose_query_logs = true
# Debug mode disables concatenation and preprocessing of assets. # Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large # This option may cause significant intervals in view rendering with a large
# number of complex assets. # number of complex assets.
config.assets.debug = true config.assets.debug = true

View file

@ -58,4 +58,4 @@ en:
form: form:
notifications_hint: | notifications_hint: |
Receive notifications to warn you when our system detects that the Receive notifications to warn you when our system detects that the
expiration date is coming. The delay is set in number of days. expiration date is coming. The time is set in number of days.

View file

@ -0,0 +1,5 @@
class RenameNotificationsDelayToInterval < ActiveRecord::Migration[5.2]
def change
rename_column :notifications, :delay, :interval
end
end

View file

@ -45,7 +45,7 @@ ActiveRecord::Schema.define(version: 2018_06_13_055303) do
t.bigint "check_id" t.bigint "check_id"
t.integer "channel", default: 0, null: false t.integer "channel", default: 0, null: false
t.string "recipient", null: false t.string "recipient", null: false
t.integer "delay", null: false t.integer "interval", null: false
t.integer "status", default: 0, null: false t.integer "status", default: 0, null: false
t.datetime "sent_at" t.datetime "sent_at"
t.datetime "created_at", null: false t.datetime "created_at", null: false

View file

@ -35,7 +35,7 @@ check_chexpire_org_error = Check.create!(
Notification.create!( Notification.create!(
check: check_chexpire_org, check: check_chexpire_org,
delay: 15, interval: 15,
channel: :email, channel: :email,
recipient: "colin@example.org", recipient: "colin@example.org",
status: :pending, status: :pending,
@ -43,7 +43,7 @@ Notification.create!(
Notification.create!( Notification.create!(
check: check_chexpire_org_error, check: check_chexpire_org_error,
delay: 15, interval: 15,
channel: :email, channel: :email,
recipient: "colin@example.org", recipient: "colin@example.org",
status: :pending, status: :pending,

View file

@ -4,7 +4,7 @@
# #
# id :bigint(8) not null, primary key # id :bigint(8) not null, primary key
# channel :integer default("email"), not null # channel :integer default("email"), not null
# delay :integer not null # interval :integer not null
# recipient :string(255) not null # recipient :string(255) not null
# sent_at :datetime # sent_at :datetime
# status :integer default("pending"), not null # status :integer default("pending"), not null
@ -24,7 +24,7 @@
FactoryBot.define do FactoryBot.define do
factory :notification do factory :notification do
check check
delay 30 interval 30
channel :email channel :email
recipient "recipient@domain.fr" recipient "recipient@domain.fr"
status :pending status :pending

View file

@ -3,7 +3,7 @@ require "test_helper"
class NotificationsMailerTest < ActionMailer::TestCase class NotificationsMailerTest < ActionMailer::TestCase
test "domain_expires_soon" do test "domain_expires_soon" do
check = create(:check, domain_expires_at: Time.new(2018, 6, 10, 12, 0, 5, "+02:00")) check = create(:check, domain_expires_at: Time.new(2018, 6, 10, 12, 0, 5, "+02:00"))
notification = build(:notification, delay: 10, check: check, recipient: "colin@example.org") notification = build(:notification, interval: 10, check: check, recipient: "colin@example.org")
Date.stub :today, Date.new(2018, 6, 2) do Date.stub :today, Date.new(2018, 6, 2) do
mail = NotificationsMailer.with(notification: notification).domain_expires_soon mail = NotificationsMailer.with(notification: notification).domain_expires_soon

View file

@ -4,7 +4,7 @@
# #
# id :bigint(8) not null, primary key # id :bigint(8) not null, primary key
# channel :integer default("email"), not null # channel :integer default("email"), not null
# delay :integer not null # interval :integer not null
# recipient :string(255) not null # recipient :string(255) not null
# sent_at :datetime # sent_at :datetime
# status :integer default("pending"), not null # status :integer default("pending"), not null

View file

@ -27,9 +27,9 @@ module Notifier
assert_includes notifications, n2 assert_includes notifications, n2
end end
test "#resolve_expires_soon gets only checks inside delay" do test "#resolve_expires_soon gets only checks inside interval" do
n1 = create(:notification, check: build(:check, :expires_next_week), delay: 6) n1 = create(:notification, check: build(:check, :expires_next_week), interval: 6)
n2 = create(:notification, check: build(:check, :expires_next_week), delay: 7) n2 = create(:notification, check: build(:check, :expires_next_week), interval: 7)
notifications = @resolver.resolve_expires_soon notifications = @resolver.resolve_expires_soon
@ -39,9 +39,9 @@ module Notifier
test "#resolve_expires_soon can gets several notifications for a same check" do test "#resolve_expires_soon can gets several notifications for a same check" do
check = create(:check, :expires_next_week) check = create(:check, :expires_next_week)
n1 = create(:notification, check: check, delay: 3) n1 = create(:notification, check: check, interval: 3)
n2 = create(:notification, check: check, delay: 10) n2 = create(:notification, check: check, interval: 10)
n3 = create(:notification, check: check, delay: 30) n3 = create(:notification, check: check, interval: 30)
notifications = @resolver.resolve_expires_soon notifications = @resolver.resolve_expires_soon

View file

@ -17,7 +17,7 @@ class ChecksTest < ApplicationSystemTestCase
recipient = "recipient@example.org" recipient = "recipient@example.org"
fill_in("check[notifications_attributes][0][recipient]", with: recipient) fill_in("check[notifications_attributes][0][recipient]", with: recipient)
fill_in("check[notifications_attributes][0][delay]", with: 30) fill_in("check[notifications_attributes][0][interval]", with: 30)
click_button click_button
@ -28,7 +28,7 @@ class ChecksTest < ApplicationSystemTestCase
notification = Notification.last notification = Notification.last
assert_equal recipient, notification.recipient assert_equal recipient, notification.recipient
assert_equal 30, notification.delay assert_equal 30, notification.interval
assert notification.email? assert notification.email?
assert notification.pending? assert notification.pending?
end end
@ -67,7 +67,7 @@ class ChecksTest < ApplicationSystemTestCase
recipient = "recipient2@example.org" recipient = "recipient2@example.org"
fill_in("check[notifications_attributes][2][recipient]", with: recipient) fill_in("check[notifications_attributes][2][recipient]", with: recipient)
fill_in("check[notifications_attributes][2][delay]", with: 55) fill_in("check[notifications_attributes][2][interval]", with: 55)
assert_difference "Notification.where(check_id: #{@check.id}).count", +1 do assert_difference "Notification.where(check_id: #{@check.id}).count", +1 do
click_button "Update Check" click_button "Update Check"
@ -79,7 +79,7 @@ class ChecksTest < ApplicationSystemTestCase
notification = Notification.last notification = Notification.last
assert_equal recipient, notification.recipient assert_equal recipient, notification.recipient
assert_equal 55, notification.delay assert_equal 55, notification.interval
assert notification.email? assert notification.email?
assert notification.pending? assert notification.pending?
end end