...

/

Building Our Quizzes

Building Our Quizzes

We’ll start building the quizzes now.

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) do
Keyword.merge([title: "Simple Arithmetic"], overrides)
end
def build_quiz(quiz_overrides \\ []) do
quiz_overrides
|> quiz_fields
|> Quiz.new
end
def build_question(overrides \\ [ ]) do
overrides
|> template_fields
|> Template.new
|> Question.new
end
  • 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 into quiz_fields, and pipe that into Quiz.new. ...