models and fixtures and seeds

This commit is contained in:
Mark Moser
2016-07-26 17:00:00 -05:00
parent 0fc8ec99b3
commit a998b2adf2
22 changed files with 254 additions and 25 deletions

6
app/models/answer.rb Normal file
View File

@ -0,0 +1,6 @@
class Answer < ApplicationRecord
serialize :answer
belongs_to :question
belongs_to :candidate
end

20
app/models/candidate.rb Normal file
View File

@ -0,0 +1,20 @@
class Candidate < ApplicationRecord
has_many :answers
belongs_to :recruiter, class_name: "User"
before_create :generate_test_hash
validates_presence_of :recruiter_id
validates_presence_of :test_hash
validates_uniqueness_of :test_hash
private
def generate_test_hash
loop do
self[:test_hash] = SecureRandom.urlsafe_base64(8)
break unless Candidate.exists?(test_hash: self[:test_hash])
end
end
end

6
app/models/question.rb Normal file
View File

@ -0,0 +1,6 @@
class Question < ApplicationRecord
serialize :input_options, Array
has_many :answers
belongs_to :quiz
end

3
app/models/quiz.rb Normal file
View File

@ -0,0 +1,3 @@
class Quiz < ApplicationRecord
has_many :questions
end

4
app/models/user.rb Normal file
View File

@ -0,0 +1,4 @@
class User < ApplicationRecord
has_secure_password
has_many :candidates, foreign_key: "recruiter_id"
end