Building Our Quizzes
We’ll start building the quizzes now.
We'll cover the following...
With the templates out of the way, the hard work is mostly done.
Building quizzes
We can focus on building quizzes now, which is nearly trivial at this point. We’ll add the following code to /test/support/quiz_builders.exs
:
Press + to interact
def quiz_fields(overrides) doKeyword.merge([title: "Simple Arithmetic"], overrides)enddef build_quiz(quiz_overrides \\ []) doquiz_overrides|> quiz_fields|> Quiz.newenddef build_question(overrides \\ [ ]) dooverrides|> template_fields|> Template.new|> Question.newend
-
Our
quiz_fields
function returns some default attributes and merges in overrides. -
Then all
build_quiz
has to do is take the overrides, pipe them intoquiz_fields
, and pipe that intoQuiz.new
. ...