From 0fa0f5f42eba77eff1eaf9129ca6977ff3f4b83c Mon Sep 17 00:00:00 2001 From: Jez Caudle Date: Sat, 11 Jun 2022 19:42:21 +0100 Subject: [PATCH] Added princples to the data base. --- Gemfile | 2 +- app/models/principle.rb | 3 ++ db/migrate/20220611182950_principle.rb | 4 ++ .../20220611183116_create_principles.rb | 12 +++++ db/schema.rb | 44 ++++++++++++------- test/fixtures/principles.yml | 11 +++++ test/models/principle_test.rb | 7 +++ 7 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 app/models/principle.rb create mode 100644 db/migrate/20220611182950_principle.rb create mode 100644 db/migrate/20220611183116_create_principles.rb create mode 100644 test/fixtures/principles.yml create mode 100644 test/models/principle_test.rb diff --git a/Gemfile b/Gemfile index 4f7f413..008abee 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } gem 'devise' gem 'cancancan' -ruby "3.0.3" +ruby "3.0.4" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" gem "rails", "~> 7.0.2.3" diff --git a/app/models/principle.rb b/app/models/principle.rb new file mode 100644 index 0000000..64f6a05 --- /dev/null +++ b/app/models/principle.rb @@ -0,0 +1,3 @@ +class Principle < ApplicationRecord + belongs_to :caf +end diff --git a/db/migrate/20220611182950_principle.rb b/db/migrate/20220611182950_principle.rb new file mode 100644 index 0000000..10247f9 --- /dev/null +++ b/db/migrate/20220611182950_principle.rb @@ -0,0 +1,4 @@ +class Principle < ActiveRecord::Migration[7.0] + def change + end +end diff --git a/db/migrate/20220611183116_create_principles.rb b/db/migrate/20220611183116_create_principles.rb new file mode 100644 index 0000000..0dc65bd --- /dev/null +++ b/db/migrate/20220611183116_create_principles.rb @@ -0,0 +1,12 @@ +class CreatePrinciples < ActiveRecord::Migration[7.0] + def change + create_table :principles do |t| + t.references :caf, null: false, foreign_key: true + t.string :name + t.text :description + + t.timestamps + end + add_index :principles, :name + end +end diff --git a/db/schema.rb b/db/schema.rb index 9d52f6c..f92d193 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,15 +10,14 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_02_10_171858) do - +ActiveRecord::Schema[7.0].define(version: 2022_06_11_183116) do create_table "action_text_rich_texts", charset: "latin1", force: :cascade do |t| t.string "name", null: false t.text "body", size: :long t.string "record_type", null: false t.bigint "record_id", null: false - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true end @@ -27,7 +26,7 @@ ActiveRecord::Schema.define(version: 2022_02_10_171858) do t.string "record_type", null: false t.bigint "record_id", null: false t.bigint "blob_id", null: false - t.datetime "created_at", precision: 6, null: false + t.datetime "created_at", null: false t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true end @@ -40,7 +39,7 @@ ActiveRecord::Schema.define(version: 2022_02_10_171858) do t.string "service_name", null: false t.bigint "byte_size", null: false t.string "checksum" - t.datetime "created_at", precision: 6, null: false + t.datetime "created_at", null: false t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true end @@ -54,15 +53,15 @@ ActiveRecord::Schema.define(version: 2022_02_10_171858) do t.bigint "company_id", null: false t.string "name" t.text "description" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["company_id"], name: "index_cafs_on_company_id" end create_table "companies", charset: "latin1", force: :cascade do |t| t.string "name" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "companies_users", id: false, charset: "latin1", force: :cascade do |t| @@ -72,23 +71,33 @@ ActiveRecord::Schema.define(version: 2022_02_10_171858) do t.index ["user_id"], name: "index_companies_users_on_user_id" end + create_table "principles", charset: "latin1", force: :cascade do |t| + t.bigint "caf_id", null: false + t.string "name" + t.text "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["caf_id"], name: "index_principles_on_caf_id" + t.index ["name"], name: "index_principles_on_name" + end + create_table "users", charset: "latin1", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" - t.datetime "reset_password_sent_at", precision: 6 - t.datetime "remember_created_at", precision: 6 + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at", precision: 6 - t.datetime "last_sign_in_at", precision: 6 + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.integer "failed_attempts", default: 0, null: false t.string "unlock_token" - t.datetime "locked_at", precision: 6 + t.datetime "locked_at" t.integer "role" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true @@ -97,4 +106,5 @@ ActiveRecord::Schema.define(version: 2022_02_10_171858) do add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "cafs", "companies" + add_foreign_key "principles", "cafs" end diff --git a/test/fixtures/principles.yml b/test/fixtures/principles.yml new file mode 100644 index 0000000..f1d3711 --- /dev/null +++ b/test/fixtures/principles.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + caf: one + name: MyString + description: MyText + +two: + caf: two + name: MyString + description: MyText diff --git a/test/models/principle_test.rb b/test/models/principle_test.rb new file mode 100644 index 0000000..1898b02 --- /dev/null +++ b/test/models/principle_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class PrincipleTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end