models and fixtures and seeds
This commit is contained in:
parent
0fc8ec99b3
commit
a998b2adf2
@ -17,7 +17,8 @@ RUN apt-get update \
|
|||||||
&& mkdir -p /usr/app \
|
&& mkdir -p /usr/app \
|
||||||
&& ln -s /usr/bin/nodejs /usr/bin/node \
|
&& ln -s /usr/bin/nodejs /usr/bin/node \
|
||||||
&& echo "alias ll='ls -Ahl'" >> /root/.bashrc \
|
&& echo "alias ll='ls -Ahl'" >> /root/.bashrc \
|
||||||
&& echo "alias la='ls -ahl'" >> /root/.bashrc
|
&& echo "alias la='ls -ahl'" >> /root/.bashrc \
|
||||||
|
&& echo "export HISTCONTROL=ignoredups" >> /root/.bashrc
|
||||||
|
|
||||||
# install current Ruby
|
# install current Ruby
|
||||||
RUN curl -L --progress https://github.com/postmodern/ruby-install/archive/v0.6.0.tar.gz | tar xz \
|
RUN curl -L --progress https://github.com/postmodern/ruby-install/archive/v0.6.0.tar.gz | tar xz \
|
||||||
|
@ -10,6 +10,7 @@ This application manages quizzes intended to be used as pre-interview skill asse
|
|||||||
* honor RuboCop
|
* honor RuboCop
|
||||||
* keep tests green
|
* keep tests green
|
||||||
* pull --rebase !always `git config --global pull.rebase true`
|
* pull --rebase !always `git config --global pull.rebase true`
|
||||||
|
* place all required dev seed data in fixtures for rails db:fixtures:load
|
||||||
|
|
||||||
# Docker
|
# Docker
|
||||||
|
|
||||||
|
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
|
63
db/migrate/20160726193255_db_init.rb
Normal file
63
db/migrate/20160726193255_db_init.rb
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
class DbInit < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
create_table :candidates do |t|
|
||||||
|
t.string :test_hash, null: false
|
||||||
|
t.string :name
|
||||||
|
t.string :email
|
||||||
|
t.string :experience
|
||||||
|
t.integer :recruiter_id
|
||||||
|
t.boolean :completed, null: false, default: false
|
||||||
|
t.boolean :reminded, null: false, default: false
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :candidates, :test_hash, unique: true
|
||||||
|
add_index :candidates, :recruiter_id
|
||||||
|
|
||||||
|
create_table :questions do |t|
|
||||||
|
t.integer :quiz_id
|
||||||
|
t.text :question
|
||||||
|
t.string :category
|
||||||
|
t.string :input_type
|
||||||
|
t.text :input_options
|
||||||
|
t.string :sort, null: false, default: 0
|
||||||
|
t.boolean :active, null: false, default: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :questions, :quiz_id
|
||||||
|
add_index :questions, :sort
|
||||||
|
add_index :questions, :active
|
||||||
|
|
||||||
|
create_table :answers do |t|
|
||||||
|
t.integer :candidate_id
|
||||||
|
t.integer :question_id
|
||||||
|
t.text :answer
|
||||||
|
t.integer :saved, null: false, default: 0
|
||||||
|
t.boolean :submitted, null: false, default: false
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :answers, :candidate_id
|
||||||
|
add_index :answers, :question_id
|
||||||
|
add_index :answers, :submitted
|
||||||
|
|
||||||
|
create_table :quizzes do |t|
|
||||||
|
t.string :unit
|
||||||
|
t.string :dept
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :users do |t|
|
||||||
|
t.string :name, null: false
|
||||||
|
t.string :email, null: false
|
||||||
|
t.string :password_digest
|
||||||
|
t.string :role, null: false
|
||||||
|
t.boolean :active, null: false, default: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :users, :email, unique: true
|
||||||
|
end
|
||||||
|
end
|
61
db/schema.rb
61
db/schema.rb
@ -10,6 +10,65 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 0) do
|
ActiveRecord::Schema.define(version: 20160726193255) do
|
||||||
|
|
||||||
|
create_table "answers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||||
|
t.integer "candidate_id"
|
||||||
|
t.integer "question_id"
|
||||||
|
t.text "answer", limit: 65535
|
||||||
|
t.integer "saved"
|
||||||
|
t.boolean "submitted"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["candidate_id"], name: "index_answers_on_candidate_id", using: :btree
|
||||||
|
t.index ["question_id"], name: "index_answers_on_question_id", using: :btree
|
||||||
|
t.index ["submitted"], name: "index_answers_on_submitted", using: :btree
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "candidates", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||||
|
t.string "test_hash"
|
||||||
|
t.string "name"
|
||||||
|
t.string "email"
|
||||||
|
t.string "experience"
|
||||||
|
t.integer "recruiter_id"
|
||||||
|
t.boolean "completed"
|
||||||
|
t.boolean "reminded"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["recruiter_id"], name: "index_candidates_on_recruiter_id", using: :btree
|
||||||
|
t.index ["test_hash"], name: "index_candidates_on_test_hash", unique: true, using: :btree
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "questions", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||||
|
t.integer "quiz_id"
|
||||||
|
t.text "question", limit: 65535
|
||||||
|
t.string "category"
|
||||||
|
t.string "input_type"
|
||||||
|
t.text "input_options", limit: 65535
|
||||||
|
t.string "sort"
|
||||||
|
t.boolean "active"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["active"], name: "index_questions_on_active", using: :btree
|
||||||
|
t.index ["quiz_id"], name: "index_questions_on_quiz_id", using: :btree
|
||||||
|
t.index ["sort"], name: "index_questions_on_sort", using: :btree
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "quizzes", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||||
|
t.string "unit"
|
||||||
|
t.string "dept"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.string "email"
|
||||||
|
t.string "password_digest"
|
||||||
|
t.string "role"
|
||||||
|
t.boolean "active"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -5,3 +5,12 @@
|
|||||||
#
|
#
|
||||||
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
|
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
|
||||||
# Character.create(name: 'Luke', movie: movies.first)
|
# Character.create(name: 'Luke', movie: movies.first)
|
||||||
|
|
||||||
|
User.create(
|
||||||
|
name: 'admin',
|
||||||
|
email: 'pdr.admin@mailinator.com',
|
||||||
|
password_digest: BCrypt::Password.create("this is the admin password"),
|
||||||
|
role: 'admin'
|
||||||
|
)
|
||||||
|
|
||||||
|
Quiz.create(unit: 'FED', dept: 'PDR')
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
fed:
|
|
||||||
unit: PDR
|
|
||||||
dept: FED
|
|
@ -1,15 +0,0 @@
|
|||||||
recruiter:
|
|
||||||
name: Sam Recruiter
|
|
||||||
email: pdr.recruiter@mailinator.com
|
|
||||||
role: recruiter
|
|
||||||
|
|
||||||
reviewer:
|
|
||||||
name: Tina Reviewer
|
|
||||||
email: fed.reviewer@mailinator.com
|
|
||||||
role: reviewer
|
|
||||||
|
|
||||||
admin:
|
|
||||||
name: Alan Admin
|
|
||||||
email: alan.admin@mailinator.com
|
|
||||||
role: admin
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
roy1:
|
roy1:
|
||||||
candidate: roy
|
candidate: roy
|
||||||
question: fed1
|
question: fed1
|
@ -1,36 +1,37 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
roy:
|
roy:
|
||||||
# test_hash:
|
|
||||||
name: Roy Cruz
|
name: Roy Cruz
|
||||||
email: roy.cruz@mailinator.com
|
email: roy.cruz@mailinator.com
|
||||||
experience: 0-3
|
experience: 0-3
|
||||||
recruiter: reviewer
|
recruiter: reviewer
|
||||||
completed: false
|
completed: false
|
||||||
reminded: false
|
reminded: false
|
||||||
|
test_hash: NmEjDkOEKY4
|
||||||
|
|
||||||
martha:
|
martha:
|
||||||
# test_hash:
|
|
||||||
name: Martha Watts
|
name: Martha Watts
|
||||||
email: martha.watts@mailinator.com
|
email: martha.watts@mailinator.com
|
||||||
experience: 4-6
|
experience: 4-6
|
||||||
recruiter: reviewer
|
recruiter: reviewer
|
||||||
completed: false
|
completed: false
|
||||||
reminded: false
|
reminded: false
|
||||||
|
test_hash: R67PmfDHGiw
|
||||||
|
|
||||||
dawn:
|
dawn:
|
||||||
# test_hash:
|
|
||||||
name: Dawn Hopkins
|
name: Dawn Hopkins
|
||||||
email: dawn.hopkins@mailinator.com
|
email: dawn.hopkins@mailinator.com
|
||||||
experience: 0-2
|
experience: 0-2
|
||||||
recruiter: reviewer
|
recruiter: reviewer
|
||||||
completed: false
|
completed: false
|
||||||
reminded: true
|
reminded: true
|
||||||
|
test_hash: OvP0ZqGKwJ0
|
||||||
|
|
||||||
richard:
|
richard:
|
||||||
# test_hash:
|
|
||||||
name: Richard Burns
|
name: Richard Burns
|
||||||
email: richard.burns@mailinator.com
|
email: richard.burns@mailinator.com
|
||||||
experience: 15+
|
experience: 15+
|
||||||
recruiter: reviewer
|
recruiter: reviewer
|
||||||
completed: true
|
completed: true
|
||||||
reminded: false
|
reminded: false
|
||||||
|
test_hash: 6NjnourLE6Y
|
@ -1,4 +1,7 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
fed1:
|
fed1:
|
||||||
|
quiz: fed
|
||||||
question: Select an example of media query from below.
|
question: Select an example of media query from below.
|
||||||
category: CSS
|
category: CSS
|
||||||
input_type: radio
|
input_type: radio
|
||||||
@ -7,6 +10,7 @@ fed1:
|
|||||||
active: true
|
active: true
|
||||||
|
|
||||||
fed2:
|
fed2:
|
||||||
|
quiz: fed
|
||||||
question: What are some ways you can improve a site's performance (load time)?
|
question: What are some ways you can improve a site's performance (load time)?
|
||||||
category: Performance
|
category: Performance
|
||||||
input_type: checkbox
|
input_type: checkbox
|
||||||
@ -15,6 +19,7 @@ fed2:
|
|||||||
active: true
|
active: true
|
||||||
|
|
||||||
fed3:
|
fed3:
|
||||||
|
quiz: fed
|
||||||
question: How would you create a widget that would fit in a 250px wide area as well as a 400px wide area?
|
question: How would you create a widget that would fit in a 250px wide area as well as a 400px wide area?
|
||||||
category: CSS
|
category: CSS
|
||||||
input_type: live-coder
|
input_type: live-coder
|
||||||
@ -23,6 +28,7 @@ fed3:
|
|||||||
active: true
|
active: true
|
||||||
|
|
||||||
fed4:
|
fed4:
|
||||||
|
quiz: fed
|
||||||
question: Briefly explain the principles of Progressive Enhancement.
|
question: Briefly explain the principles of Progressive Enhancement.
|
||||||
category: Performance
|
category: Performance
|
||||||
input_type: text
|
input_type: text
|
||||||
@ -31,6 +37,7 @@ fed4:
|
|||||||
active: true
|
active: true
|
||||||
|
|
||||||
fed5:
|
fed5:
|
||||||
|
quiz: fed
|
||||||
question: Which is your favorite grid system?
|
question: Which is your favorite grid system?
|
||||||
category: CSS
|
category: CSS
|
||||||
input_type: radio
|
input_type: radio
|
||||||
@ -39,6 +46,7 @@ fed5:
|
|||||||
active: true
|
active: true
|
||||||
|
|
||||||
fed6:
|
fed6:
|
||||||
|
quiz: fed
|
||||||
question: List one advantage of using IDs over classes. List one disadvantage.
|
question: List one advantage of using IDs over classes. List one disadvantage.
|
||||||
category: CSS
|
category: CSS
|
||||||
input_type: text
|
input_type: text
|
||||||
@ -47,6 +55,7 @@ fed6:
|
|||||||
active: true
|
active: true
|
||||||
|
|
||||||
fed7:
|
fed7:
|
||||||
|
quiz: fed
|
||||||
question: Provide a code example to manipulate the DOM using jQuery/JavaScript to change the classname of a div 'classB' to 'classC', only if the div 'classA' exists in the page?
|
question: Provide a code example to manipulate the DOM using jQuery/JavaScript to change the classname of a div 'classB' to 'classC', only if the div 'classA' exists in the page?
|
||||||
category: Javascript
|
category: Javascript
|
||||||
input_type: live-coder
|
input_type: live-coder
|
||||||
@ -55,6 +64,7 @@ fed7:
|
|||||||
active: true
|
active: true
|
||||||
|
|
||||||
fed8:
|
fed8:
|
||||||
|
quiz: fed
|
||||||
question: Select the HTML from below that would create an input field which restricts the number of characters inside it to 10.
|
question: Select the HTML from below that would create an input field which restricts the number of characters inside it to 10.
|
||||||
category: HTML
|
category: HTML
|
||||||
input_type: radio
|
input_type: radio
|
||||||
@ -63,6 +73,7 @@ fed8:
|
|||||||
active: true
|
active: true
|
||||||
|
|
||||||
fed9:
|
fed9:
|
||||||
|
quiz: fed
|
||||||
question: Grunt or Gulp?
|
question: Grunt or Gulp?
|
||||||
category: Javascript
|
category: Javascript
|
||||||
input_type: radio
|
input_type: radio
|
||||||
@ -71,6 +82,7 @@ fed9:
|
|||||||
active: true
|
active: true
|
||||||
|
|
||||||
fed10:
|
fed10:
|
||||||
|
quiz: fed
|
||||||
question: StarWars or Star Trek?
|
question: StarWars or Star Trek?
|
||||||
category: Performance
|
category: Performance
|
||||||
input_type: checkbox
|
input_type: checkbox
|
5
test/fixtures/quizzes.yml
vendored
Normal file
5
test/fixtures/quizzes.yml
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
fed:
|
||||||
|
unit: PDR
|
||||||
|
dept: FED
|
20
test/fixtures/users.yml
vendored
Normal file
20
test/fixtures/users.yml
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
recruiter:
|
||||||
|
name: Sam Recruiter
|
||||||
|
email: pdr.recruiter@mailinator.com
|
||||||
|
password_digest: <%= BCrypt::Password.create("password", cost: 4) %>
|
||||||
|
role: recruiter
|
||||||
|
|
||||||
|
reviewer:
|
||||||
|
name: Tina Reviewer
|
||||||
|
email: fed.reviewer@mailinator.com
|
||||||
|
password_digest: <%= BCrypt::Password.create("password", cost: 4) %>
|
||||||
|
role: reviewer
|
||||||
|
|
||||||
|
admin:
|
||||||
|
name: Alan Admin
|
||||||
|
email: alan.admin@mailinator.com
|
||||||
|
password_digest: <%= BCrypt::Password.create("password", cost: 4) %>
|
||||||
|
role: admin
|
||||||
|
|
7
test/models/answer_test.rb
Normal file
7
test/models/answer_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class AnswerTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
7
test/models/candidate_test.rb
Normal file
7
test/models/candidate_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class CandidateTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
7
test/models/question_test.rb
Normal file
7
test/models/question_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class QuestionTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
7
test/models/quiz_test.rb
Normal file
7
test/models/quiz_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class QuizTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
7
test/models/user_test.rb
Normal file
7
test/models/user_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class UserTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user