Add Todos for learning goals

This commit is contained in:
Trevor Vallender 2024-01-07 13:22:21 +00:00
parent 658bc90ed7
commit 084f965b25
6 changed files with 46 additions and 1 deletions

View File

@ -3,6 +3,7 @@ class LearningGoal < ApplicationRecord
has_rich_text :description has_rich_text :description
has_rich_text :retrospective has_rich_text :retrospective
validates :completed, inclusion: { in: [true, false] }
validates :title, presence: true validates :title, presence: true

4
app/models/todo.rb Normal file
View File

@ -0,0 +1,4 @@
class Todo < ApplicationRecord
belongs_to :learning_goal
validates :done, inclusion: { in: [true, false] }
end

View File

@ -0,0 +1,12 @@
class CreateTodos < ActiveRecord::Migration[7.1]
def change
create_table :todos do |t|
t.belongs_to :learning_goal, null: false, foreign_key: true
t.boolean :done, null: false, default: false
t.string :title, null: false, default: ''
t.date :due
t.timestamps
end
end
end

13
db/schema.rb generated
View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2024_01_06_103226) do ActiveRecord::Schema[7.1].define(version: 2024_01_07_131738) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -140,6 +140,16 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_06_103226) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
create_table "todos", force: :cascade do |t|
t.bigint "learning_goal_id", null: false
t.boolean "done", default: false, null: false
t.string "title", default: "", null: false
t.date "due"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["learning_goal_id"], name: "index_todos_on_learning_goal_id"
end
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "username", null: false t.string "username", null: false
t.string "password_digest", null: false t.string "password_digest", null: false
@ -161,4 +171,5 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_06_103226) do
add_foreign_key "exercises", "exercise_types" add_foreign_key "exercises", "exercise_types"
add_foreign_key "learning_goals", "users" add_foreign_key "learning_goals", "users"
add_foreign_key "microposts", "users" add_foreign_key "microposts", "users"
add_foreign_key "todos", "learning_goals"
end end

10
test/fixtures/todos.yml vendored Normal file
View File

@ -0,0 +1,10 @@
one:
learning_goal: sql
done: false
title: Read SQL for Mere Mortals
due: <%= 3.years.from_now %>
two:
learning_goal: linux
done: true
title: Install Debian

7
test/models/todo_test.rb Normal file
View File

@ -0,0 +1,7 @@
require "test_helper"
class TodoTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end