diff --git a/app/controllers/admin/result_controller.rb b/app/controllers/admin/result_controller.rb index e5c9564..867c922 100644 --- a/app/controllers/admin/result_controller.rb +++ b/app/controllers/admin/result_controller.rb @@ -10,7 +10,9 @@ module Admin # TODO: Limit results to the quizzes current_user has access to def index - @candidates = Candidate.where(completed: true).includes(:recruiter) + @candidates = Candidate.where(completed: true) + .includes(:recruiter) + .order(:review_status, completed_at: :desc) end def view diff --git a/app/controllers/quiz_controller.rb b/app/controllers/quiz_controller.rb index 4f4e35d..6ec5921 100644 --- a/app/controllers/quiz_controller.rb +++ b/app/controllers/quiz_controller.rb @@ -35,7 +35,7 @@ class QuizController < ApplicationController private def complete_and_email - if current_candidate.update_attributes(completed: true) + if current_candidate.update_attributes(completed: true, completed_at: DateTime.current) current_candidate.build_reviews CandidateMailer.submitted(current_candidate).deliver_later RecruiterMailer.candidate_submitted(current_candidate).deliver_later diff --git a/app/views/admin/result/index.html.erb b/app/views/admin/result/index.html.erb index dd05923..96ab9f4 100644 --- a/app/views/admin/result/index.html.erb +++ b/app/views/admin/result/index.html.erb @@ -8,6 +8,7 @@ Test ID Experience Recruiter + Submitted on Interview? @@ -16,6 +17,7 @@ <%= link_to candidate.test_hash, admin_result_path(candidate.test_hash) %> <%= candidate.experience %> years <%= mail_to(candidate.recruiter.email) %> + <%= candidate.completed_at.strftime('%D') unless candidate.completed_at.nil? %> <%= candidate.interview? %> <% end %> diff --git a/db/migrate/20161204220527_add_completed_at.rb b/db/migrate/20161204220527_add_completed_at.rb new file mode 100644 index 0000000..8315b00 --- /dev/null +++ b/db/migrate/20161204220527_add_completed_at.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true +class AddCompletedAt < ActiveRecord::Migration[5.0] + def change + add_column :candidates, :completed_at, :datetime, after: :completed + + Candidate.reset_column_information + Candidate.where(completed: true).each do |candidate| + candidate.completed_at = candidate.updated_at + candidate.save + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 912be6d..dc15ecc 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: 20161120175737) do +ActiveRecord::Schema.define(version: 20161204220527) do create_table "answers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.integer "candidate_id" @@ -32,6 +32,7 @@ ActiveRecord::Schema.define(version: 20161120175737) do t.string "experience" t.integer "recruiter_id" t.boolean "completed" + t.datetime "completed_at" t.boolean "reminded" t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -77,11 +78,11 @@ ActiveRecord::Schema.define(version: 20161120175737) do create_table "reviewer_votes", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| t.integer "candidate_id" t.integer "user_id" - t.integer "vote", default: 0, null: false - t.integer "veto", default: 0, null: false + t.integer "vote", default: 0, null: false + t.integer "veto", default: 0, null: false t.datetime "last_reminded" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["candidate_id", "user_id"], name: "index_reviewer_votes_on_candidate_id_and_user_id", unique: true, using: :btree end diff --git a/test/fixtures/candidates.yml b/test/fixtures/candidates.yml index 4def21b..354fc68 100644 --- a/test/fixtures/candidates.yml +++ b/test/fixtures/candidates.yml @@ -57,6 +57,7 @@ richard: # Richard has completed AND submitted the test recruiter: recruiter quiz: fed completed: true + completed_at: <%= DateTime.current %> reminded: false test_hash: 6NjnourLE6Y review_status: 1 @@ -78,6 +79,7 @@ stacy: # Stacy has completed AND submitted the test recruiter: recruiter quiz: fed completed: true + completed_at: <%= DateTime.current %> reminded: false test_hash: s6oFExZliYYFx review_status: 2 @@ -89,6 +91,7 @@ henry: # Henry has completed AND submitted the test recruiter: recruiter quiz: fed completed: true + completed_at: <%= DateTime.current %> reminded: false test_hash: egPomAuVDeCEp @@ -99,6 +102,7 @@ wade: # Wade has completed AND submitted the test recruiter: recruiter quiz: fed completed: true + completed_at: <%= DateTime.current %> reminded: false test_hash: BkSkpapJnkz2N