From 2c06694b4cdaa2eec11ba75798f6e1966c960fb3 Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Sat, 6 Jan 2024 09:42:36 +0000 Subject: [PATCH] Add learning goal model --- app/models/learning_goal.rb | 7 +++++++ db/migrate/20240106093517_create_learning_goals.rb | 13 +++++++++++++ db/schema.rb | 14 +++++++++++++- test/fixtures/action_text/rich_texts.yml | 4 ++++ test/fixtures/learning_goals.yml | 13 +++++++++++++ test/models/learning_goal_test.rb | 4 ++++ 6 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/models/learning_goal.rb create mode 100644 db/migrate/20240106093517_create_learning_goals.rb create mode 100644 test/fixtures/learning_goals.yml create mode 100644 test/models/learning_goal_test.rb diff --git a/app/models/learning_goal.rb b/app/models/learning_goal.rb new file mode 100644 index 0000000..6aae83c --- /dev/null +++ b/app/models/learning_goal.rb @@ -0,0 +1,7 @@ +class LearningGoal < ApplicationRecord + belongs_to :user + + has_rich_text :description, :retrospective + + validates :title, presence: true +end diff --git a/db/migrate/20240106093517_create_learning_goals.rb b/db/migrate/20240106093517_create_learning_goals.rb new file mode 100644 index 0000000..6776322 --- /dev/null +++ b/db/migrate/20240106093517_create_learning_goals.rb @@ -0,0 +1,13 @@ +class CreateLearningGoals < ActiveRecord::Migration[7.1] + def change + create_table :learning_goals do |t| + t.string :title, null: false + t.date :starts_on + t.date :ends_on + t.boolean :completed, null: false, default: false + t.references :user, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3978ac6..e07295c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2023_12_31_112357) do +ActiveRecord::Schema[7.1].define(version: 2024_01_06_093517) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -97,6 +97,17 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_31_112357) do t.index ["exercise_type_id"], name: "index_exercises_on_exercise_type_id" end + create_table "learning_goals", force: :cascade do |t| + t.string "title", null: false + t.date "starts_on" + t.date "ends_on" + t.boolean "completed", default: false, null: false + t.bigint "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_learning_goals_on_user_id" + end + create_table "microposts", force: :cascade do |t| t.bigint "user_id", null: false t.datetime "created_at", null: false @@ -143,5 +154,6 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_31_112357) do add_foreign_key "diary_entries", "users" add_foreign_key "exercises", "diary_entries" add_foreign_key "exercises", "exercise_types" + add_foreign_key "learning_goals", "users" add_foreign_key "microposts", "users" end diff --git a/test/fixtures/action_text/rich_texts.yml b/test/fixtures/action_text/rich_texts.yml index 10d53f0..defca85 100644 --- a/test/fixtures/action_text/rich_texts.yml +++ b/test/fixtures/action_text/rich_texts.yml @@ -10,3 +10,7 @@ draft_blog_post: record: draft (BlogPost) name: content body:

Just some text

+learning_goal_one: + record: linux (LearningGoal) + name: content + body:

Learning about Linux

diff --git a/test/fixtures/learning_goals.yml b/test/fixtures/learning_goals.yml new file mode 100644 index 0000000..d323fc0 --- /dev/null +++ b/test/fixtures/learning_goals.yml @@ -0,0 +1,13 @@ +sql: + title: SQL + starts_on: 2024-01-06 + ends_on: 2024-06-06 + completed: false + user: trevor + +linux: + title: Linux + starts_on: 2023-03-06 + ends_on: 2023-06-06 + completed: true + user: trevor diff --git a/test/models/learning_goal_test.rb b/test/models/learning_goal_test.rb new file mode 100644 index 0000000..90cd7e9 --- /dev/null +++ b/test/models/learning_goal_test.rb @@ -0,0 +1,4 @@ +require "test_helper" + +class LearningGoalTest < ActiveSupport::TestCase +end