From a4c3d332d0ff2faf835f42a5aa886109fa50367f Mon Sep 17 00:00:00 2001 From: Mariela-t Date: Tue, 26 Nov 2024 21:12:26 -0800 Subject: [PATCH] Added comment model --- .ruby-version | 2 +- app/models/comment.rb | 4 ++++ db/migrate/20241127050712_create_comments.rb | 11 +++++++++++ db/schema.rb | 14 +++++++++++++- test/fixtures/comments.yml | 11 +++++++++++ test/models/comment_test.rb | 7 +++++++ 6 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 app/models/comment.rb create mode 100644 db/migrate/20241127050712_create_comments.rb create mode 100644 test/fixtures/comments.yml create mode 100644 test/models/comment_test.rb diff --git a/.ruby-version b/.ruby-version index b502146..be94e6f 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.2 +3.2.2 diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..dadd048 --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,4 @@ +class Comment < ApplicationRecord + belongs_to :user + belongs_to :entry +end diff --git a/db/migrate/20241127050712_create_comments.rb b/db/migrate/20241127050712_create_comments.rb new file mode 100644 index 0000000..6d9ea6a --- /dev/null +++ b/db/migrate/20241127050712_create_comments.rb @@ -0,0 +1,11 @@ +class CreateComments < ActiveRecord::Migration[7.1] + def change + create_table :comments do |t| + t.references :user, null: false, foreign_key: true + t.references :entry, null: false, foreign_key: true + t.string :text + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4b50dca..d1f85fe 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,17 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_11_25_222152) do +ActiveRecord::Schema[7.1].define(version: 2024_11_27_050712) do + create_table "comments", force: :cascade do |t| + t.integer "user_id", null: false + t.integer "entry_id", null: false + t.string "text" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["entry_id"], name: "index_comments_on_entry_id" + t.index ["user_id"], name: "index_comments_on_user_id" + end + create_table "entries", force: :cascade do |t| t.integer "user_id", null: false t.string "text" @@ -36,5 +46,7 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + add_foreign_key "comments", "entries" + add_foreign_key "comments", "users" add_foreign_key "entries", "users" end diff --git a/test/fixtures/comments.yml b/test/fixtures/comments.yml new file mode 100644 index 0000000..985b552 --- /dev/null +++ b/test/fixtures/comments.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + user: one + entry: one + text: MyString + +two: + user: two + entry: two + text: MyString diff --git a/test/models/comment_test.rb b/test/models/comment_test.rb new file mode 100644 index 0000000..5a6feda --- /dev/null +++ b/test/models/comment_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class CommentTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end