diff --git a/app/models/review_message.rb b/app/models/review_message.rb new file mode 100644 index 0000000..a2a7ded --- /dev/null +++ b/app/models/review_message.rb @@ -0,0 +1,32 @@ +# == Schema Information +# +# Table name: review_messages +# +# id :bigint not null, primary key +# content :string +# feedback_type :string +# created_at :datetime not null +# updated_at :datetime not null +# question_id :bigint not null +# user_id :bigint not null +# +# Indexes +# +# index_review_messages_on_question_id (question_id) +# index_review_messages_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (question_id => questions.id) +# fk_rails_... (user_id => users.id) +# +class ReviewMessage < ApplicationRecord + extend Enumerize + + belongs_to :question + belongs_to :user + + enumerize :feedback_type, in: %i[request_changes approve answer] + + validates :content, presence: true +end diff --git a/app/models/review_request.rb b/app/models/review_request.rb new file mode 100644 index 0000000..f013b56 --- /dev/null +++ b/app/models/review_request.rb @@ -0,0 +1,25 @@ +# == Schema Information +# +# Table name: review_requests +# +# id :bigint not null, primary key +# answered :string +# created_at :datetime not null +# updated_at :datetime not null +# question_id :bigint not null +# user_id :bigint not null +# +# Indexes +# +# index_review_requests_on_question_id (question_id) +# index_review_requests_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (question_id => questions.id) +# fk_rails_... (user_id => users.id) +# +class ReviewRequest < ApplicationRecord + belongs_to :question + belongs_to :user +end diff --git a/db/migrate/20220721132854_create_review_requests.rb b/db/migrate/20220721132854_create_review_requests.rb new file mode 100644 index 0000000..78a5e5d --- /dev/null +++ b/db/migrate/20220721132854_create_review_requests.rb @@ -0,0 +1,11 @@ +class CreateReviewRequests < ActiveRecord::Migration[7.0] + def change + create_table :review_requests do |t| + t.string :answered + t.references :question, null: false, foreign_key: true + t.references :user, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/migrate/20220721132939_create_review_messages.rb b/db/migrate/20220721132939_create_review_messages.rb new file mode 100644 index 0000000..6116306 --- /dev/null +++ b/db/migrate/20220721132939_create_review_messages.rb @@ -0,0 +1,12 @@ +class CreateReviewMessages < ActiveRecord::Migration[7.0] + def change + create_table :review_messages do |t| + t.string :feedback_type + t.string :content + t.references :question, null: false, foreign_key: true + t.references :user, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 7c0f6bb..66c6ca0 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.0].define(version: 2022_07_21_132556) do +ActiveRecord::Schema[7.0].define(version: 2022_07_21_132939) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -97,6 +97,27 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_21_132556) do t.index ["user_id"], name: "index_questions_on_user_id" end + create_table "review_messages", force: :cascade do |t| + t.string "feedback_type" + t.string "content" + t.bigint "question_id", null: false + t.bigint "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["question_id"], name: "index_review_messages_on_question_id" + t.index ["user_id"], name: "index_review_messages_on_user_id" + end + + create_table "review_requests", force: :cascade do |t| + t.string "answered" + t.bigint "question_id", null: false + t.bigint "user_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["question_id"], name: "index_review_requests_on_question_id" + t.index ["user_id"], name: "index_review_requests_on_user_id" + end + create_table "subjects", force: :cascade do |t| t.string "name" t.bigint "category_id", null: false @@ -125,6 +146,10 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_21_132556) do add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "questions", "subjects" add_foreign_key "questions", "users" + add_foreign_key "review_messages", "questions" + add_foreign_key "review_messages", "users" + add_foreign_key "review_requests", "questions" + add_foreign_key "review_requests", "users" add_foreign_key "subjects", "axes" add_foreign_key "subjects", "categories" end diff --git a/erd.svg b/erd.svg index f6ee7d4..dcd14fb 100644 --- a/erd.svg +++ b/erd.svg @@ -4,206 +4,251 @@ - - + + ProgressTest - -Progress Test - Models + +Progress Test - Models m_ActiveAdmin::Comment - -ActiveAdmin::Comment - -author_id -integer (8) -author_type -string -body -text ∗ -namespace -string ∗ -resource_id -integer (8) -resource_type -string + +ActiveAdmin::Comment + +author_id +integer (8) +author_type +string +body +text ∗ +namespace +string ∗ +resource_id +integer (8) +resource_type +string m_ActiveStorage::Attachment - -ActiveStorage::Attachment - -name -string ∗ -record_type -string ∗ + +ActiveStorage::Attachment + +name +string ∗ +record_type +string ∗ m_ActiveStorage::Blob - -ActiveStorage::Blob - -byte_size -integer (8) ∗ -checksum -string ∗ -content_type -string -filename -string ∗ -key -string ∗ -metadata -text -service_name -string ∗ + +ActiveStorage::Blob + +byte_size +integer (8) ∗ +checksum +string ∗ +content_type +string +filename +string ∗ +key +string ∗ +metadata +text +service_name +string ∗ m_ActiveStorage::Blob->m_ActiveStorage::Attachment - + m_ActiveStorage::Blob->m_ActiveStorage::Blob - + m_ActiveStorage::VariantRecord - -ActiveStorage::VariantRecord - -variation_digest -string ∗ + +ActiveStorage::VariantRecord + +variation_digest +string ∗ m_ActiveStorage::VariantRecord->m_ActiveStorage::Attachment - + m_ActiveStorage::VariantRecord->m_ActiveStorage::Blob - - + + m_Axis - -Axis - -name -string ∗ U + +Axis + +name +string ∗ U - + m_Subject - -Subject - -name -string ∗ U + +Subject + +name +string ∗ U - + m_Axis->m_Subject - - + + m_Category - -Category - -name -string ∗ U + +Category + +name +string ∗ U - + m_Category->m_Subject - - + + m_CkEditorUpload - -CkEditorUpload + +CkEditorUpload m_CkEditorUpload->m_ActiveStorage::Attachment - + m_Question - -Question - -alternatives -jsonb ∗ -authorship -string -authorship_year -string -bloom_taxonomy -string -body -text -check_type -string -difficulty -string -explanation -text -instruction -text -intention -text -references -text -status -string ∗ -support -text + +Question + +alternatives +jsonb ∗ +authorship +string +authorship_year +string +bloom_taxonomy +string +body +text +check_type +string +difficulty +string +explanation +text +instruction +text +intention +text +references +text +status +string ∗ +support +text + + + +m_ReviewMessage + +ReviewMessage + +content +string ∗ +feedback_type +string + + + +m_Question->m_ReviewMessage + + + + + +m_ReviewRequest + +ReviewRequest + +answered +string + + + +m_Question->m_ReviewRequest + + - + m_Subject->m_Question - - + + - + m_User - -User - -email -string ∗ U -encrypted_password -string ∗ -name -string ∗ -remember_created_at -datetime (6,0) -reset_password_sent_at -datetime (6,0) -reset_password_token -string + +User + +email +string ∗ U +encrypted_password +string ∗ +name +string ∗ +remember_created_at +datetime (6,0) +reset_password_sent_at +datetime (6,0) +reset_password_token +string - + m_User->m_Question - - + + + + + +m_User->m_ReviewMessage + + + + + +m_User->m_ReviewRequest + + + diff --git a/spec/factories/review_messages.rb b/spec/factories/review_messages.rb new file mode 100644 index 0000000..da03c2a --- /dev/null +++ b/spec/factories/review_messages.rb @@ -0,0 +1,30 @@ +# == Schema Information +# +# Table name: review_messages +# +# id :bigint not null, primary key +# content :string +# feedback_type :string +# created_at :datetime not null +# updated_at :datetime not null +# question_id :bigint not null +# user_id :bigint not null +# +# Indexes +# +# index_review_messages_on_question_id (question_id) +# index_review_messages_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (question_id => questions.id) +# fk_rails_... (user_id => users.id) +# +FactoryBot.define do + factory :review_message do + feedback_type { "MyString" } + content { "MyString" } + question { nil } + user { nil } + end +end diff --git a/spec/factories/review_requests.rb b/spec/factories/review_requests.rb new file mode 100644 index 0000000..c79c077 --- /dev/null +++ b/spec/factories/review_requests.rb @@ -0,0 +1,28 @@ +# == Schema Information +# +# Table name: review_requests +# +# id :bigint not null, primary key +# answered :string +# created_at :datetime not null +# updated_at :datetime not null +# question_id :bigint not null +# user_id :bigint not null +# +# Indexes +# +# index_review_requests_on_question_id (question_id) +# index_review_requests_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (question_id => questions.id) +# fk_rails_... (user_id => users.id) +# +FactoryBot.define do + factory :review_request do + answered { "MyString" } + question { nil } + user { nil } + end +end diff --git a/spec/models/review_message_spec.rb b/spec/models/review_message_spec.rb new file mode 100644 index 0000000..78c5fab --- /dev/null +++ b/spec/models/review_message_spec.rb @@ -0,0 +1,30 @@ +# == Schema Information +# +# Table name: review_messages +# +# id :bigint not null, primary key +# content :string +# feedback_type :string +# created_at :datetime not null +# updated_at :datetime not null +# question_id :bigint not null +# user_id :bigint not null +# +# Indexes +# +# index_review_messages_on_question_id (question_id) +# index_review_messages_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (question_id => questions.id) +# fk_rails_... (user_id => users.id) +# +require 'rails_helper' + +RSpec.describe ReviewMessage, type: :model do + describe "associations" do + it { is_expected.to(belong_to(:user)) } + it { is_expected.to(belong_to(:question)) } + end +end diff --git a/spec/models/review_request_spec.rb b/spec/models/review_request_spec.rb new file mode 100644 index 0000000..7cd001b --- /dev/null +++ b/spec/models/review_request_spec.rb @@ -0,0 +1,29 @@ +# == Schema Information +# +# Table name: review_requests +# +# id :bigint not null, primary key +# answered :string +# created_at :datetime not null +# updated_at :datetime not null +# question_id :bigint not null +# user_id :bigint not null +# +# Indexes +# +# index_review_requests_on_question_id (question_id) +# index_review_requests_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (question_id => questions.id) +# fk_rails_... (user_id => users.id) +# +require 'rails_helper' + +RSpec.describe ReviewRequest, type: :model do + describe "associations" do + it { is_expected.to(belong_to(:user)) } + it { is_expected.to(belong_to(:question)) } + end +end