diff --git a/app/helpers/checks_helper.rb b/app/helpers/checks_helper.rb new file mode 100644 index 0000000..ec8edd7 --- /dev/null +++ b/app/helpers/checks_helper.rb @@ -0,0 +1,2 @@ +module ChecksHelper +end diff --git a/app/models/check.rb b/app/models/check.rb new file mode 100644 index 0000000..cae12ec --- /dev/null +++ b/app/models/check.rb @@ -0,0 +1,43 @@ +# == Schema Information +# +# Table name: checks +# +# id :bigint(8) not null, primary key +# active :boolean default(TRUE), not null +# comment :string(255) +# domain :string(255) not null +# domain_created_at :datetime +# domain_expire_at :datetime +# domain_updated_at :datetime +# kind :integer not null +# last_run_at :datetime +# last_success_at :datetime +# vendor :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# user_id :bigint(8) +# +# Indexes +# +# index_checks_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (user_id => users.id) +# + +class Check < ApplicationRecord + belongs_to :user + + enum kind: [:domain, :ssl] + + self.skip_time_zone_conversion_for_attributes = [ + :domain_created_at, + :domain_updated_at, + :domain_expire_at, + ] + + validates :kind, presence: true + validates :domain, presence: true + validates :active, presence: true +end diff --git a/app/models/user.rb b/app/models/user.rb index a398135..33f6a36 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,5 +35,6 @@ class User < ApplicationRecord devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :confirmable + has_many :checks validates :tos_accepted, acceptance: true end diff --git a/db/migrate/20180529092950_create_checks.rb b/db/migrate/20180529092950_create_checks.rb new file mode 100644 index 0000000..5178aea --- /dev/null +++ b/db/migrate/20180529092950_create_checks.rb @@ -0,0 +1,19 @@ +class CreateChecks < ActiveRecord::Migration[5.2] + def change + create_table :checks do |t| + t.references :user, foreign_key: true + t.integer :kind, null: false + t.string :domain, null: false + t.datetime :domain_created_at + t.datetime :domain_updated_at + t.datetime :domain_expire_at + t.datetime :last_run_at + t.datetime :last_success_at + t.string :vendor + t.string :comment + t.boolean :active, default: true, null: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 8483285..25fe422 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,24 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_05_24_205809) do +ActiveRecord::Schema.define(version: 2018_05_29_092950) do + + create_table "checks", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| + t.bigint "user_id" + t.integer "kind", null: false + t.string "domain", null: false + t.datetime "domain_created_at" + t.datetime "domain_updated_at" + t.datetime "domain_expire_at" + t.datetime "last_run_at" + t.datetime "last_success_at" + t.string "vendor" + t.string "comment" + t.boolean "active", default: true, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_checks_on_user_id" + end create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.string "email", default: "", null: false @@ -36,4 +53,5 @@ ActiveRecord::Schema.define(version: 2018_05_24_205809) do t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + add_foreign_key "checks", "users" end diff --git a/test/controllers/checks_controller_test.rb b/test/controllers/checks_controller_test.rb new file mode 100644 index 0000000..77435b7 --- /dev/null +++ b/test/controllers/checks_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class ChecksControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/checks.yml b/test/fixtures/checks.yml new file mode 100644 index 0000000..152c76a --- /dev/null +++ b/test/fixtures/checks.yml @@ -0,0 +1,55 @@ +# == Schema Information +# +# Table name: checks +# +# id :bigint(8) not null, primary key +# active :boolean default(TRUE), not null +# comment :string(255) +# domain :string(255) not null +# domain_created_at :datetime +# domain_expire_at :datetime +# domain_updated_at :datetime +# kind :integer not null +# last_run_at :datetime +# last_success_at :datetime +# vendor :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# user_id :bigint(8) +# +# Indexes +# +# index_checks_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (user_id => users.id) +# + +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +domain_example_org: + user: user1 + kind: domain + domain: example.org + domain_created_at: 2017-03-01 17:29:50 + domain_updated_at: 2018-02-15 12:10:00 + domain_expire_at: 2019-03-01 17:29:49 + last_run_at: 2018-05-24 17:29:50 + last_success_at: 2018-05-24 17:29:50 + vendor: "" + comment: "" + active: true + +ssl_www_example_org: + user: user1 + kind: ssl + domain: www.example.org + domain_created_at: 2018-05-24 17:29:50 + domain_updated_at: 2018-05-24 17:29:50 + domain_expire_at: 2019-05-24 17:29:49 + last_run_at: 2018-05-24 17:29:50 + last_success_at: 2018-05-24 17:29:50 + vendor: "" + comment: "MyString" + active: true diff --git a/test/models/check_test.rb b/test/models/check_test.rb new file mode 100644 index 0000000..2aee566 --- /dev/null +++ b/test/models/check_test.rb @@ -0,0 +1,35 @@ +# == Schema Information +# +# Table name: checks +# +# id :bigint(8) not null, primary key +# active :boolean default(TRUE), not null +# comment :string(255) +# domain :string(255) not null +# domain_created_at :datetime +# domain_expire_at :datetime +# domain_updated_at :datetime +# kind :integer not null +# last_run_at :datetime +# last_success_at :datetime +# vendor :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# user_id :bigint(8) +# +# Indexes +# +# index_checks_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (user_id => users.id) +# + +require "test_helper" + +class CheckTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end