Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Factory.define :multiple_choice_item, :class => MultipleChoiceItem do |mc_item|
mc_item.association :site
mc_item.text Yardstick::DummyData::LOREM
mc_item.item_type "MultipleChoiceItem"
mc_item.max_choices 1
mc_item.shuffle_choices false
choices = [
"Mauris euismod lor nisi, cursus eget laoreet eget laoreet mauris sit amet feugiat. Nullam non blandit urna. Sed et ultricies quam.",
"Duis dolor nisi, cursus eget laoreet eget, pellentesque vitae era non blandit urna sed et ultricies quam.",
"Vestibulum bibendum, metus in vehicula imperdiet",
"Nunc vel sollicitudin nibh. Aenean pretium, nibh eu dapibus euismod, mi arcu."
]
mc_item.choices do |mc|
correct = (0..3).map.rand
(0..3).map do |n|
mc.association(:item_choice, {
:item => mc.instance_values["instance"],
:text => choices[n],
:position => n,
:value => n == correct ? 1 : 0
})
end
end
end
Factory.define :exam do |e|
e.sequence(:name) { |n| "Exam #{n}" }
e.category { |category| category.association(:exam_category) }
e.exam_type Exam::OPEN
e.active true
e.exam_items do |ex|
(0..3).map do |n|
exam_obj = ex.instance_values["instance"]
item = Factory(:multiple_choice_item, :site => exam_obj.category.site)
ex.association(:exam_item, {
:item => item,
:exam => exam_obj,
:position => n
})
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.