From 9c2b53aa79fca87b8e1a2fa258d8d34ec293cabd Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Fri, 10 Feb 2017 12:03:50 -0600 Subject: [PATCH] init comments --- app/models/candidate.rb | 1 + app/models/quiz_comment.rb | 7 ++ app/models/user.rb | 1 + .../20170210165110_create_quiz_comments.rb | 12 ++++ db/schema.rb | 10 ++- test/fixtures/quiz_comments.yml | 72 +++++++++++++++++++ test/models/quiz_comment_test.rb | 27 +++++++ test/models/reviewer_vote_test.rb | 2 +- 8 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 app/models/quiz_comment.rb create mode 100644 db/migrate/20170210165110_create_quiz_comments.rb create mode 100644 test/fixtures/quiz_comments.yml create mode 100644 test/models/quiz_comment_test.rb diff --git a/app/models/candidate.rb b/app/models/candidate.rb index 7d5b287..af91ff7 100644 --- a/app/models/candidate.rb +++ b/app/models/candidate.rb @@ -6,6 +6,7 @@ class Candidate < ApplicationRecord belongs_to :recruiter, class_name: "User" has_many :votes, class_name: "ReviewerVote" has_many :reviewers, through: :quiz + has_many :quiz_comments, foreign_key: :test_hash, primary_key: :test_hash serialize :email, CryptSerializer diff --git a/app/models/quiz_comment.rb b/app/models/quiz_comment.rb new file mode 100644 index 0000000..8819997 --- /dev/null +++ b/app/models/quiz_comment.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true +class QuizComment < ApplicationRecord + belongs_to :user + belongs_to :candidate, foreign_key: :test_hash, primary_key: :test_hash + + validates :message, presence: true +end diff --git a/app/models/user.rb b/app/models/user.rb index 773cb1f..6179a94 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,6 +5,7 @@ class User < ApplicationRecord has_many :reviewer_to_quizzes has_many :quizzes, through: :reviewer_to_quizzes has_many :votes, class_name: 'ReviewerVote' + has_many :quiz_comments has_many :reviewees, through: :quizzes, source: :candidates diff --git a/db/migrate/20170210165110_create_quiz_comments.rb b/db/migrate/20170210165110_create_quiz_comments.rb new file mode 100644 index 0000000..caae162 --- /dev/null +++ b/db/migrate/20170210165110_create_quiz_comments.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true +class CreateQuizComments < ActiveRecord::Migration[5.0] + def change + create_table :quiz_comments do |t| + t.integer :user_id + t.string :test_hash + t.text :message + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 5e5c4cc..ae6704d 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.define(version: 20170208212526) do +ActiveRecord::Schema.define(version: 20170210165110) do create_table "answers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.integer "candidate_id" @@ -60,6 +60,14 @@ ActiveRecord::Schema.define(version: 20170208212526) do t.index ["sort"], name: "index_questions_on_sort", using: :btree end + create_table "quiz_comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| + t.integer "user_id" + t.string "test_hash" + t.text "message", limit: 65535 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "quizzes", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.string "unit" t.string "dept" diff --git a/test/fixtures/quiz_comments.yml b/test/fixtures/quiz_comments.yml new file mode 100644 index 0000000..68a7938 --- /dev/null +++ b/test/fixtures/quiz_comments.yml @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +com1: + test_hash: BkSkpapJnkz2N #wade + user: reviewer + message: Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Etiam porta sem malesuada magna mollis euismod. Aenean lacinia bibendum nulla sed consectetur. Maecenas faucibus mollis interdum. + +com2: + test_hash: BkSkpapJnkz2N #wade + user: reviewer + message: Donec sed odio dui. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Curabitur blandit tempus porttitor. Nullam quis risus eget urna mollis ornare vel eu leo. Nullam id dolor id nibh ultricies vehicula ut id elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. + +com3: + test_hash: BkSkpapJnkz2N #wade + user: reviewer2 + message: Cras mattis consectetur purus sit amet fermentum. Donec sed odio dui. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. + +com4: + test_hash: iC5FdWJxcyySBmpOpU #jorge + user: manager + message: Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed posuere consectetur est at lobortis. + +com5: + test_hash: egPomAuVDeCEp #henry + user: manager + message: no. + +com6: + test_hash: egPomAuVDeCEp #henry + user: reviewer2 + message: fine. + +com7: + test_hash: iC5FdWJxcyySBmpOpU #jorge + user: reviewer + message: Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. + +com8: + test_hash: egPomAuVDeCEp #henry + user: manager + message: no. + +com9: + test_hash: rLSoizA3ATMNSCx #elsie + user: reviewer + message: Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Donec ullamcorper nulla non metus auctor fringilla. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Etiam porta sem malesuada magna mollis euismod. Vestibulum id ligula porta felis euismod semper. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Maecenas faucibus mollis interdum. + +com10: + test_hash: rLSoizA3ATMNSCx #elsie + user: reviewer2 + message: Ornare Tellus Nullam Mattis + +com11: + test_hash: rLSoizA3ATMNSCx #elsie + user: reviewer2 + message: Nibh Ultricies Purus + +com12: + test_hash: rLSoizA3ATMNSCx #elsie + user: reviewer + message: Donec id elit non mi porta gravida at eget metus. + +com13: + test_hash: rLSoizA3ATMNSCx #elsie + user: manager + message: Donec id elit non mi porta gravida at eget metus. + +com14: + test_hash: rLSoizA3ATMNSCx #elsie + user: reviewer2 + message: Ultricies Vulputate Bibendum Parturient + diff --git a/test/models/quiz_comment_test.rb b/test/models/quiz_comment_test.rb new file mode 100644 index 0000000..90e3ec8 --- /dev/null +++ b/test/models/quiz_comment_test.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true +require 'test_helper' + +class QuizCommentTest < ActiveSupport::TestCase + test "the truth" do + assert QuizComment + end + + test "user to comments association" do + manager = users(:manager) + + assert_equal 4, manager.quiz_comments.size + end + + test "candidate to comments association" do + candidate = candidates(:elsie) + + assert_equal 6, candidate.quiz_comments.size + end + + test 'comment to user' do + comment = quiz_comments(:com1) + + assert_match 'Wade', comment.candidate.name + assert_match 'Tina', comment.user.name + end +end diff --git a/test/models/reviewer_vote_test.rb b/test/models/reviewer_vote_test.rb index 5f73233..d5a9ef3 100644 --- a/test/models/reviewer_vote_test.rb +++ b/test/models/reviewer_vote_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class ReviewerVoteTest < ActiveSupport::TestCase test "the truth" do - assert ReviewerVoteTest + assert ReviewerVote end test "richard has 3 votes" do