aboutsummaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-07-02 16:19:35 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-07-12 19:17:19 +0200
commit0d88de6e77c3e00398d152cd430a617b80f4c821 (patch)
tree6c282ff4c1b49d6ca26baf6ea8389a60c6a2387c /db
parentUsers can view descriptions of question groups (diff)
downloadrecruiting-webapp-0d88de6e77c3e00398d152cd430a617b80f4c821.tar.gz
recruiting-webapp-0d88de6e77c3e00398d152cd430a617b80f4c821.tar.bz2
recruiting-webapp-0d88de6e77c3e00398d152cd430a617b80f4c821.zip
Multiple choice questions
Diffstat (limited to 'db')
-rw-r--r--db/fixtures/questions.yml2
-rw-r--r--db/schema.rb33
-rw-r--r--db/seeds.rb17
3 files changed, 44 insertions, 8 deletions
diff --git a/db/fixtures/questions.yml b/db/fixtures/questions.yml
index 1023dec..f7ed080 100644
--- a/db/fixtures/questions.yml
+++ b/db/fixtures/questions.yml
@@ -48,7 +48,7 @@ ebuild_q6:
title: src_install
documentation: handbook
question_category: ebuild
- question_group: ebuild_proup1
+ question_group: ebuild_group1
content: "src_install() {
dobin tree
doman man/tree.1
diff --git a/db/schema.rb b/db/schema.rb
index 57b11ad..146ba07 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100709083952) do
+ActiveRecord::Schema.define(:version => 20100709164217) do
create_table "answers", :force => true do |t|
t.text "content"
@@ -19,10 +19,12 @@ ActiveRecord::Schema.define(:version => 20100709083952) do
t.datetime "updated_at"
t.integer "question_id"
t.integer "owner_id"
+ t.string "type"
end
add_index "answers", ["owner_id"], :name => "index_answers_on_owner_id"
add_index "answers", ["question_id"], :name => "index_answers_on_question_id"
+ add_index "answers", ["type"], :name => "index_answers_on_type"
create_table "comments", :force => true do |t|
t.text "content"
@@ -35,6 +37,16 @@ ActiveRecord::Schema.define(:version => 20100709083952) do
add_index "comments", ["answer_id"], :name => "index_comments_on_answer_id"
add_index "comments", ["owner_id"], :name => "index_comments_on_owner_id"
+ create_table "options", :force => true do |t|
+ t.string "content"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "option_owner_id"
+ t.string "option_owner_type"
+ end
+
+ add_index "options", ["option_owner_type", "option_owner_id"], :name => "index_options_on_option_owner_type_and_option_owner_id"
+
create_table "project_acceptances", :force => true do |t|
t.string "accepting_nick"
t.boolean "accepted", :default => false
@@ -51,6 +63,24 @@ ActiveRecord::Schema.define(:version => 20100709083952) do
t.datetime "updated_at"
end
+ create_table "question_content_multiple_choices", :force => true do |t|
+ t.text "content"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "question_id"
+ end
+
+ add_index "question_content_multiple_choices", ["question_id"], :name => "index_question_content_multiple_choices_on_question_id"
+
+ create_table "question_content_texts", :force => true do |t|
+ t.text "content"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "question_id"
+ end
+
+ add_index "question_content_texts", ["question_id"], :name => "index_question_content_texts_on_question_id"
+
create_table "question_groups", :force => true do |t|
t.string "name", :null => false
t.text "description", :null => false
@@ -60,7 +90,6 @@ ActiveRecord::Schema.define(:version => 20100709083952) do
create_table "questions", :force => true do |t|
t.string "title"
- t.text "content"
t.string "documentation"
t.boolean "approved", :default => false
t.datetime "created_at"
diff --git a/db/seeds.rb b/db/seeds.rb
index 2b57ef6..cc36215 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -5,20 +5,24 @@
class SeedHelper
attr_accessor :objects
def initialize
- @objects ={}
+ @objects = {}
end
# Read data from file
# in each item replace values of fields given in replace_with_objects with objects
# and create!
- def read_yaml(file, klass, replace_with_objects)
+ def read_yaml(file, klass, replace_with_objects, &block)
for item_array in YAML::load_file(file)
name = item_array[0]
hash = item_array[1]
for field in replace_with_objects
hash[field] = @objects[hash[field]]
end
- @objects[name] = klass.create! hash
+ if block.nil?
+ @objects[name] = klass.create! hash
+ else
+ yield(name, hash, @objects, klass)
+ end
end
end
@@ -51,8 +55,11 @@ seeder.objects['non'] = QuestionCategory.create! :name => 'Non-ebuild staf
# Question groups
seeder.objects['ebuild_group1'] = QuestionGroup.create! :name => 'ebuild_group1', :description => 'src_install implementations to comment on'
-# Questions - load from YAML file
-seeder.read_yaml 'db/fixtures/questions.yml', Question, ['question_category', 'question_group']
+# Questions with text content - load from YAML file
+seeder.read_yaml('db/fixtures/questions.yml', Question, ['question_category', 'question_group']) do |name, hash, objects, klass|
+ objects[name] = klass.create! (hash - {'content' => nil})
+ objects["#{name}-content"] = QuestionContentText.create! :question => objects[name], :content => hash['content']
+end
# Users - load from YAML file
seeder.read_yaml 'db/fixtures/users.yml', User, 'mentor'