mirror of
https://github.com/Evolix/chexpire.git
synced 2024-05-05 02:05:09 +02:00
Notification model & migration.
This commit is contained in:
parent
73e5695cb2
commit
dc2c1b88d0
2
app/helpers/notifications_helper.rb
Normal file
2
app/helpers/notifications_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module NotificationsHelper
|
||||
end
|
|
@ -29,6 +29,7 @@
|
|||
class Check < ApplicationRecord
|
||||
belongs_to :user
|
||||
has_many :logs, class_name: "CheckLog"
|
||||
has_many :notifications
|
||||
|
||||
enum kind: [:domain, :ssl]
|
||||
|
||||
|
|
34
app/models/notification.rb
Normal file
34
app/models/notification.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: notifications
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# channel :integer not null
|
||||
# delay :integer not null
|
||||
# recipient :string(255) not null
|
||||
# sent_at :datetime
|
||||
# status :integer default("pending"), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# check_id :bigint(8)
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_notifications_on_check_id (check_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (check_id => checks.id)
|
||||
#
|
||||
|
||||
class Notification < ApplicationRecord
|
||||
belongs_to :check
|
||||
|
||||
enum kind: [:email]
|
||||
enum status: [:pending, :ongoing, :succeed, :failed]
|
||||
|
||||
validates :kind, presence: true
|
||||
validates :channel, presence: true
|
||||
validates :recipient, presence: true
|
||||
validates :delay, presence: true
|
||||
end
|
14
db/migrate/20180531101412_create_notifications.rb
Normal file
14
db/migrate/20180531101412_create_notifications.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
class CreateNotifications < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :notifications do |t|
|
||||
t.references :check, foreign_key: true
|
||||
t.integer :channel, null: false
|
||||
t.string :recipient, null: false
|
||||
t.integer :delay, null: false
|
||||
t.integer :status, null: false, default: 0
|
||||
t.datetime :sent_at
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
15
db/schema.rb
15
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2018_05_30_123611) do
|
||||
ActiveRecord::Schema.define(version: 2018_05_31_101412) do
|
||||
|
||||
create_table "check_logs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
||||
t.bigint "check_id"
|
||||
|
@ -41,6 +41,18 @@ ActiveRecord::Schema.define(version: 2018_05_30_123611) do
|
|||
t.index ["user_id"], name: "index_checks_on_user_id"
|
||||
end
|
||||
|
||||
create_table "notifications", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
||||
t.bigint "check_id"
|
||||
t.integer "channel", null: false
|
||||
t.string "recipient", null: false
|
||||
t.integer "delay", null: false
|
||||
t.integer "status", default: 0, null: false
|
||||
t.datetime "sent_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["check_id"], name: "index_notifications_on_check_id"
|
||||
end
|
||||
|
||||
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
||||
t.string "email", default: "", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
|
@ -67,4 +79,5 @@ ActiveRecord::Schema.define(version: 2018_05_30_123611) do
|
|||
|
||||
add_foreign_key "check_logs", "checks"
|
||||
add_foreign_key "checks", "users"
|
||||
add_foreign_key "notifications", "checks"
|
||||
end
|
||||
|
|
7
test/controllers/notifications_controller_test.rb
Normal file
7
test/controllers/notifications_controller_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class NotificationsControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
40
test/fixtures/notifications.yml
vendored
Normal file
40
test/fixtures/notifications.yml
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: notifications
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# channel :integer not null
|
||||
# delay :integer not null
|
||||
# recipient :string(255) not null
|
||||
# sent_at :datetime
|
||||
# status :integer default("pending"), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# check_id :bigint(8)
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_notifications_on_check_id (check_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (check_id => checks.id)
|
||||
#
|
||||
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
check: domain_example_org
|
||||
channel: email
|
||||
recipient: myemail@example.org
|
||||
delay: 30
|
||||
sent_at: 2018-05-31 10:14:12
|
||||
status: succeed
|
||||
|
||||
two:
|
||||
check: domain_example_org
|
||||
channel: email
|
||||
recipient: myemail@example.org
|
||||
delay: 10
|
||||
sent_at: 2018-05-31 10:14:12
|
||||
status: succeed
|
30
test/models/notification_test.rb
Normal file
30
test/models/notification_test.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: notifications
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# channel :integer not null
|
||||
# delay :integer not null
|
||||
# recipient :string(255) not null
|
||||
# sent_at :datetime
|
||||
# status :integer default("pending"), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# check_id :bigint(8)
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_notifications_on_check_id (check_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (check_id => checks.id)
|
||||
#
|
||||
|
||||
require "test_helper"
|
||||
|
||||
class NotificationTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Reference in a new issue