diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2010-07-08 13:14:35 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2010-07-12 19:17:19 +0200 |
commit | 1aa5c8ff43a7435ddfe9c3d1578de45b94cad85a (patch) | |
tree | e4a63f85795c2a98efe84adc56f747a131884c89 /db | |
parent | Recruits get feedback on their answers (diff) | |
download | recruiting-webapp-1aa5c8ff43a7435ddfe9c3d1578de45b94cad85a.tar.gz recruiting-webapp-1aa5c8ff43a7435ddfe9c3d1578de45b94cad85a.tar.bz2 recruiting-webapp-1aa5c8ff43a7435ddfe9c3d1578de45b94cad85a.zip |
Add an example multiple choice question to seed
Diffstat (limited to 'db')
-rw-r--r-- | db/fixtures/questions-multichoice.yml | 6 | ||||
-rw-r--r-- | db/seeds.rb | 10 |
2 files changed, 16 insertions, 0 deletions
diff --git a/db/fixtures/questions-multichoice.yml b/db/fixtures/questions-multichoice.yml new file mode 100644 index 0000000..58fe2b9 --- /dev/null +++ b/db/fixtures/questions-multichoice.yml @@ -0,0 +1,6 @@ +multichoice_q1: + title: Fake multiple choice + documentation: Fake + question_category: ebuild + content: Some question + options: Option 1; Option 2; Option 3 diff --git a/db/seeds.rb b/db/seeds.rb index cc36215..c15d38b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -61,6 +61,16 @@ seeder.read_yaml('db/fixtures/questions.yml', Question, ['question_category', 'q objects["#{name}-content"] = QuestionContentText.create! :question => objects[name], :content => hash['content'] end +# Questions with multiple choice content - load from YAML file +seeder.read_yaml('db/fixtures/questions-multichoice.yml', Question, ['question_category', 'question_group']) do |name, hash, objects, klass| + objects[name] = klass.create!(hash - {'options' => nil, 'content' => nil}) + objects["#{name}-content"] = QuestionContentMultipleChoice.create! :question => objects[name], :content => hash['content'] + for opt in hash['options'].split(';') + opt.strip! + Option.create! :content => opt, :option_owner => objects["#{name}-content"] + end +end + # Users - load from YAML file seeder.read_yaml 'db/fixtures/users.yml', User, 'mentor' |