- ©2016 All Rights Reserved - Perficient Digital
+ ©2016-<%= Time.now.year %> All Rights Reserved - Perficient Digital
|
<%= image_tag(attachments["perficientdigital-logo.jpg"].url, alt:"Perficient Digital") %>
diff --git a/app/views/reviewer_mailer/new_comment.html.inky b/app/views/reviewer_mailer/new_comment.html.inky
new file mode 100644
index 0000000..b37e27b
--- /dev/null
+++ b/app/views/reviewer_mailer/new_comment.html.inky
@@ -0,0 +1,13 @@
+
+
+
+ <%= @comment.user.name %> wrote a comment for quiz <%= @comment.test_hash %>
+
+
+
+ <%= @comment.message %>
+
+
+ You can view and reply here: <%= link_to nil, admin_result_url(@comment.test_hash) %>.
+
+
diff --git a/app/views/reviewer_mailer/new_comment.text.erb b/app/views/reviewer_mailer/new_comment.text.erb
new file mode 100644
index 0000000..c109f9e
--- /dev/null
+++ b/app/views/reviewer_mailer/new_comment.text.erb
@@ -0,0 +1,9 @@
+SKILLS ASSESSMENT RESULT COMMENT
+
+<%= @comment.user.name %> wrote a comment for quiz <%= @comment.test_hash %>
+
+--- --- --- ---
+<%= @comment.message %>
+--- --- --- ---
+
+You can view and reply here: <%= admin_result_url(@comment.test_hash) %>.
diff --git a/config/routes.rb b/config/routes.rb
index e7a7558..c806362 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -52,6 +52,9 @@ Rails.application.routes.draw do
get "/admin/results", to: "admin/result#index", as: :admin_results
get "/admin/result/:test_hash", to: "admin/result#view", as: :admin_result
+ post "/admin/comment/:test_hash/:id", to: "admin/comment#update", as: :admin_update_comment
+ post "/admin/comment/:test_hash", to: "admin/comment#create", as: :admin_create_comment
+
get "admin/vote/:test_hash/up", to: "admin/vote#up", as: :admin_up_vote, defaults: { format: 'json' }
get "admin/vote/:test_hash/down", to: "admin/vote#down", as: :admin_down_vote, defaults: { format: 'json' }
get "admin/vote/:test_hash/approve", to: "admin/vote#approve", as: :admin_approve_vote, defaults: { format: 'json' }
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/controllers/admin/comment_controller_test.rb b/test/controllers/admin/comment_controller_test.rb
new file mode 100644
index 0000000..9b9a8fb
--- /dev/null
+++ b/test/controllers/admin/comment_controller_test.rb
@@ -0,0 +1,90 @@
+# frozen_string_literal: true
+require 'test_helper'
+
+module Admin
+ class CommentControllerTest < ActionDispatch::IntegrationTest
+ include ActiveJob::TestHelper
+
+ test "should post update" do
+ auth_manager
+ comment = quiz_comments(:com5)
+ post admin_update_comment_url(test_hash: comment.test_hash, id: comment.id),
+ params: { quiz_comment: { message: 'updated comment' } }
+
+ assert_redirected_to admin_result_url(test_hash: comment.test_hash)
+ assert flash[:success]
+ refute_equal comment.message, QuizComment.find_by(id: comment.id).message
+ end
+
+ test "should require message to update" do
+ auth_manager
+ comment = quiz_comments(:com5)
+ post admin_update_comment_url(test_hash: comment.test_hash, id: comment.id),
+ params: { quiz_comment: { message: '' } }
+
+ assert_redirected_to admin_result_url(test_hash: comment.test_hash)
+ assert flash[:error]
+ assert_equal comment.message, QuizComment.find_by(id: comment.id).message
+ end
+
+ test "should post create" do
+ auth_reviewer
+ candidate = candidates(:stacy)
+
+ assert_difference("QuizComment.count") do
+ post admin_create_comment_url(test_hash: candidate.test_hash),
+ params: { quiz_comment: { message: 'this is a test comment' } }
+ end
+
+ assert_redirected_to admin_result_url(test_hash: candidate.test_hash)
+ assert flash[:success]
+ end
+
+ test "should queue emails on create" do
+ auth_reviewer
+ candidate = candidates(:stacy)
+
+ assert_enqueued_jobs 1 do
+ assert_difference("QuizComment.count", 1) do
+ post admin_create_comment_url(test_hash: candidate.test_hash),
+ params: { quiz_comment: { message: 'this is a test comment' } }
+ end
+ end
+ end
+
+ test "should require comment to create" do
+ auth_reviewer
+ candidate = candidates(:stacy)
+
+ assert_difference("QuizComment.count", 0) do
+ post admin_create_comment_url(test_hash: candidate.test_hash),
+ params: { quiz_comment: { message: '' } }
+ end
+
+ assert_redirected_to admin_result_url(test_hash: candidate.test_hash)
+ assert flash[:error]
+ end
+
+ test "should not edit others comments" do
+ auth_reviewer
+ comment = quiz_comments(:com5)
+ post admin_update_comment_url(test_hash: comment.test_hash, id: comment.id),
+ params: { quiz_comment: { message: 'updated comment' } }
+
+ assert_redirected_to admin_login_url
+ assert_equal comment.message, QuizComment.find_by(id: comment.id).message
+ end
+
+ test "can not comment on Gustov" do
+ auth_reviewer
+ candidate = candidates(:gustov)
+
+ assert_difference("QuizComment.count", 0) do
+ post admin_create_comment_url(test_hash: candidate.test_hash),
+ params: { quiz_comment: { message: 'this is a test comment' } }
+ end
+
+ assert_redirected_to admin_login_url
+ end
+ end
+end
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/mailers/previews/reviewer_mailer_preview.rb b/test/mailers/previews/reviewer_mailer_preview.rb
index 1f67524..9a95c1c 100644
--- a/test/mailers/previews/reviewer_mailer_preview.rb
+++ b/test/mailers/previews/reviewer_mailer_preview.rb
@@ -14,4 +14,8 @@ class ReviewerMailerPreview < ActionMailer::Preview
def notify_manager
ReviewerMailer.notify_manager Candidate.find_by(test_hash: 'OvP0ZqGKwJ0').id # Dawn
end
+
+ def new_comment
+ ReviewerMailer.new_comment QuizComment.first
+ end
end
diff --git a/test/mailers/reviewer_mailer_test.rb b/test/mailers/reviewer_mailer_test.rb
index aa2e04f..c656806 100644
--- a/test/mailers/reviewer_mailer_test.rb
+++ b/test/mailers/reviewer_mailer_test.rb
@@ -30,4 +30,14 @@ class ReviewerMailerTest < ActionMailer::TestCase
assert_equal [ENV["default_mail_from"]], mail.from
assert_match candidate.test_hash, mail.body.encoded
end
+
+ test "comment notification" do
+ comment = quiz_comments(:com5)
+ mail = ReviewerMailer.new_comment comment
+ assert_match "Comment", mail.subject
+ assert_match comment.test_hash, mail.subject
+ assert_equal comment.candidate.reviewers.map(&:email), mail.to
+ assert_equal [ENV["default_mail_from"]], mail.from
+ assert_match comment.test_hash, mail.body.encoded
+ end
end
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
diff --git a/test/policies/quiz_comment_policy_test.rb b/test/policies/quiz_comment_policy_test.rb
new file mode 100644
index 0000000..6298093
--- /dev/null
+++ b/test/policies/quiz_comment_policy_test.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+require 'test_helper'
+
+class QuizCommentPolicyTest < PolicyAssertions::Test
+ test 'should require current_user' do
+ assert_raise Pundit::NotAuthorizedError do
+ QuizCommentPolicy.new(nil, User.first).create?
+ end
+ end
+
+ def test_create
+ candidate = candidates(:stacy)
+ comment = QuizComment.new(test_hash: candidate.test_hash)
+
+ assert_permit users(:manager), comment
+ assert_permit users(:reviewer), comment
+
+ refute_permit users(:admin), comment
+ refute_permit users(:recruiter), comment
+ end
+
+ def test_update
+ assert_permit users(:reviewer2), quiz_comments(:com6)
+
+ refute_permit users(:reviewer), quiz_comments(:com6)
+ refute_permit users(:manager), quiz_comments(:com6)
+ refute_permit users(:admin), quiz_comments(:com6)
+ refute_permit users(:recruiter), quiz_comments(:com6)
+ end
+end
|