models and fixtures and seeds
This commit is contained in:
6
app/models/answer.rb
Normal file
6
app/models/answer.rb
Normal file
@ -0,0 +1,6 @@
|
||||
class Answer < ApplicationRecord
|
||||
serialize :answer
|
||||
|
||||
belongs_to :question
|
||||
belongs_to :candidate
|
||||
end
|
20
app/models/candidate.rb
Normal file
20
app/models/candidate.rb
Normal 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
6
app/models/question.rb
Normal 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
3
app/models/quiz.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class Quiz < ApplicationRecord
|
||||
has_many :questions
|
||||
end
|
4
app/models/user.rb
Normal file
4
app/models/user.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class User < ApplicationRecord
|
||||
has_secure_password
|
||||
has_many :candidates, foreign_key: "recruiter_id"
|
||||
end
|
Reference in New Issue
Block a user