From 084f965b258a8b6622b41e35c67c744d5633145d Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Sun, 7 Jan 2024 13:22:21 +0000 Subject: [PATCH] Add Todos for learning goals --- app/models/learning_goal.rb | 1 + app/models/todo.rb | 4 ++++ db/migrate/20240107131738_create_todos.rb | 12 ++++++++++++ db/schema.rb | 13 ++++++++++++- test/fixtures/todos.yml | 10 ++++++++++ test/models/todo_test.rb | 7 +++++++ 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 app/models/todo.rb create mode 100644 db/migrate/20240107131738_create_todos.rb create mode 100644 test/fixtures/todos.yml create mode 100644 test/models/todo_test.rb diff --git a/app/models/learning_goal.rb b/app/models/learning_goal.rb index 0881b08..bab7dec 100644 --- a/app/models/learning_goal.rb +++ b/app/models/learning_goal.rb @@ -3,6 +3,7 @@ class LearningGoal < ApplicationRecord has_rich_text :description has_rich_text :retrospective + validates :completed, inclusion: { in: [true, false] } validates :title, presence: true diff --git a/app/models/todo.rb b/app/models/todo.rb new file mode 100644 index 0000000..af053c1 --- /dev/null +++ b/app/models/todo.rb @@ -0,0 +1,4 @@ +class Todo < ApplicationRecord + belongs_to :learning_goal + validates :done, inclusion: { in: [true, false] } +end diff --git a/db/migrate/20240107131738_create_todos.rb b/db/migrate/20240107131738_create_todos.rb new file mode 100644 index 0000000..e891d9c --- /dev/null +++ b/db/migrate/20240107131738_create_todos.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index a2af531..3af3095 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: 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 enable_extension "plpgsql" @@ -140,6 +140,16 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_06_103226) do t.datetime "updated_at", null: false 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| t.string "username", 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 "learning_goals", "users" add_foreign_key "microposts", "users" + add_foreign_key "todos", "learning_goals" end diff --git a/test/fixtures/todos.yml b/test/fixtures/todos.yml new file mode 100644 index 0000000..1c5322d --- /dev/null +++ b/test/fixtures/todos.yml @@ -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 diff --git a/test/models/todo_test.rb b/test/models/todo_test.rb new file mode 100644 index 0000000..614a849 --- /dev/null +++ b/test/models/todo_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class TodoTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end