Add learning goal model

This commit is contained in:
Trevor Vallender 2024-01-06 09:42:36 +00:00
parent c2b2017d6c
commit 2c06694b4c
6 changed files with 54 additions and 1 deletions

View File

@ -0,0 +1,7 @@
class LearningGoal < ApplicationRecord
belongs_to :user
has_rich_text :description, :retrospective
validates :title, presence: true
end

View File

@ -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

14
db/schema.rb generated
View File

@ -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

View File

@ -10,3 +10,7 @@ draft_blog_post:
record: draft (BlogPost)
name: content
body: <p>Just some text</p>
learning_goal_one:
record: linux (LearningGoal)
name: content
body: <p>Learning about Linux</p>

13
test/fixtures/learning_goals.yml vendored Normal file
View File

@ -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

View File

@ -0,0 +1,4 @@
require "test_helper"
class LearningGoalTest < ActiveSupport::TestCase
end