Skip to content

Commit

Permalink
refactor(assessments-factory)
Browse files Browse the repository at this point in the history
Change assessments factory to give unique question weights when creating questions

This is to assist in live feedback tests as weights are needed to order the questions
  • Loading branch information
syoopie committed Sep 3, 2024
1 parent aded180 commit 371d7d9
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions spec/factories/course_assessment_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
FactoryBot.define do
sequence(:course_assessment_assessment_name) { |n| "Assessment #{n}" }
sequence(:course_assessment_assessment_description) { |n| "Awesome description #{n}" }
sequence(:question_weight)
factory :course_assessment_assessment, class: Course::Assessment, aliases: [:assessment],
parent: :course_lesson_plan_item do
transient do
Expand Down Expand Up @@ -44,74 +45,74 @@

trait :with_mcq_question do
after(:build) do |assessment, evaluator|
evaluator.question_count.downto(1).each do |i|
evaluator.question_count.times do
question = build(:course_assessment_question_multiple_response, :multiple_choice)
assessment.question_assessments.build(question: question.acting_as, weight: i)
assessment.question_assessments.build(question: question.acting_as, weight: generate(:question_weight))
end
end
end

trait :with_mrq_question do
after(:build) do |assessment, evaluator|
evaluator.question_count.downto(1).each do |i|
evaluator.question_count.times do
question = build(:course_assessment_question_multiple_response)
assessment.question_assessments.build(question: question.acting_as, weight: i)
assessment.question_assessments.build(question: question.acting_as, weight: generate(:question_weight))
end
end
end

trait :with_programming_question do
after(:build) do |assessment, evaluator|
evaluator.question_count.downto(1).each do |i|
evaluator.question_count.times do
question = build(:course_assessment_question_programming, :auto_gradable, template_package: true)
assessment.question_assessments.build(question: question.acting_as, weight: i)
assessment.question_assessments.build(question: question.acting_as, weight: generate(:question_weight))
end
end
end

trait :with_programming_codaveri_question do
after(:build) do |assessment, evaluator|
evaluator.question_count.downto(1).each do |i|
evaluator.question_count.times do
question = build(:course_assessment_question_programming, :auto_gradable, template_package: true,
is_codaveri: true)
assessment.question_assessments.build(question: question.acting_as, weight: i)
assessment.question_assessments.build(question: question.acting_as, weight: generate(:question_weight))
end
end
end

trait :with_programming_file_submission_question do
after(:build) do |assessment, evaluator|
evaluator.question_count.downto(1).each do |i|
evaluator.question_count.times do
question = build(:course_assessment_question_programming,
:auto_gradable, :multiple_file_submission)
assessment.question_assessments.build(question: question.acting_as, weight: i)
assessment.question_assessments.build(question: question.acting_as, weight: generate(:question_weight))
end
end
end

trait :with_text_response_question do
after(:build) do |assessment, evaluator|
evaluator.question_count.downto(1).each do |i|
evaluator.question_count.times do
question = build(:course_assessment_question_text_response, :allow_multiple_attachments)
assessment.question_assessments.build(question: question.acting_as, weight: i)
assessment.question_assessments.build(question: question.acting_as, weight: generate(:question_weight))
end
end
end

trait :with_file_upload_question do
after(:build) do |assessment, evaluator|
evaluator.question_count.downto(1).each do |i|
evaluator.question_count.times do
question = build(:course_assessment_question_text_response, :file_upload_question)
assessment.question_assessments.build(question: question.acting_as, weight: i)
assessment.question_assessments.build(question: question.acting_as, weight: generate(:question_weight))
end
end
end

trait :with_forum_post_response_question do
after(:build) do |assessment, evaluator|
evaluator.question_count.downto(1).each do |i|
evaluator.question_count.times do
question = build(:course_assessment_question_forum_post_response)
assessment.question_assessments.build(question: question.acting_as, weight: i)
assessment.question_assessments.build(question: question.acting_as, weight: generate(:question_weight))
end
end
end
Expand Down

0 comments on commit 371d7d9

Please sign in to comment.