parent
372e86507e
commit
2233d73c39
@ -2,6 +2,8 @@
|
||||
class Quiz < ApplicationRecord
|
||||
has_many :questions, -> { order(:sort) }
|
||||
has_many :candidates
|
||||
has_many :reviewer_to_quizzes
|
||||
has_many :reviewers, through: :reviewer_to_quizzes, source: :user
|
||||
|
||||
validates :name, presence: true, uniqueness: true
|
||||
validates :dept, presence: true
|
||||
|
5
app/models/reviewer_to_quiz.rb
Normal file
5
app/models/reviewer_to_quiz.rb
Normal file
@ -0,0 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
class ReviewerToQuiz < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :quiz
|
||||
end
|
@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
class User < ApplicationRecord
|
||||
has_secure_password
|
||||
has_many :candidates, foreign_key: "recruiter_id"
|
||||
has_many :candidates, foreign_key: :recruiter_id
|
||||
has_many :reviewer_to_quizzes
|
||||
has_many :quizzes, through: :reviewer_to_quizzes
|
||||
|
||||
validates :email, presence: true, uniqueness: true
|
||||
validates :name, presence: true
|
||||
|
12
db/migrate/20160915164450_create_reviewer_to_quizzes.rb
Normal file
12
db/migrate/20160915164450_create_reviewer_to_quizzes.rb
Normal file
@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
class CreateReviewerToQuizzes < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :reviewer_to_quizzes do |t|
|
||||
t.integer :user_id, null: false
|
||||
t.integer :quiz_id, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :reviewer_to_quizzes, :quiz_id
|
||||
end
|
||||
end
|
10
db/schema.rb
10
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: 20160826200610) do
|
||||
ActiveRecord::Schema.define(version: 20160915164450) do
|
||||
|
||||
create_table "answers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||
t.integer "candidate_id"
|
||||
@ -65,6 +65,14 @@ ActiveRecord::Schema.define(version: 20160826200610) do
|
||||
t.string "name"
|
||||
end
|
||||
|
||||
create_table "reviewer_to_quizzes", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||
t.integer "user_id", null: false
|
||||
t.integer "quiz_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["quiz_id"], name: "index_reviewer_to_quizzes_on_quiz_id", using: :btree
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||
t.string "name"
|
||||
t.string "email"
|
||||
|
9
test/fixtures/reviewer_to_quizzes.yml
vendored
Normal file
9
test/fixtures/reviewer_to_quizzes.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
user: reviewer
|
||||
quiz: fed
|
||||
|
||||
two:
|
||||
user: reviewer2
|
||||
quiz: fed
|
6
test/fixtures/users.yml
vendored
6
test/fixtures/users.yml
vendored
@ -12,6 +12,12 @@ reviewer:
|
||||
password_digest: <%= BCrypt::Password.create("password", cost: 4) %>
|
||||
role: reviewer
|
||||
|
||||
reviewer2:
|
||||
name: David Reviewer
|
||||
email: david.reviewer@mailinator.com
|
||||
password_digest: <%= BCrypt::Password.create("password", cost: 4) %>
|
||||
role: reviewer
|
||||
|
||||
admin:
|
||||
name: Alan Admin
|
||||
email: alan.admin@mailinator.com
|
||||
|
8
test/models/reviewer_to_quiz_test.rb
Normal file
8
test/models/reviewer_to_quiz_test.rb
Normal file
@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
require 'test_helper'
|
||||
|
||||
class ReviewerToQuizTest < ActiveSupport::TestCase
|
||||
test "the truth" do
|
||||
assert ReviewerToQuiz
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user