• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / backend / e0330f2cf38b2d8af12bffd20f4cac2158d607fc-PR-1236

31 Mar 2025 09:12AM UTC coverage: 19.982% (-73.6%) from 93.607%
e0330f2cf38b2d8af12bffd20f4cac2158d607fc-PR-1236

Pull #1236

github

RichDom2185
Redate migrations to maintain total ordering
Pull Request #1236: Added Exam mode

12 of 57 new or added lines in 8 files covered. (21.05%)

2430 existing lines in 97 files now uncovered.

671 of 3358 relevant lines covered (19.98%)

3.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/lib/cadet/assessments/question.ex
1
defmodule Cadet.Assessments.Question do
2
  @moduledoc """
3
  Questions model contains domain logic for questions management
4
  including programming and multiple choice questions.
5
  """
6
  use Cadet, :model
7

8
  alias Cadet.Assessments.{Assessment, Library, QuestionType}
9
  alias Cadet.Assessments.QuestionTypes.{MCQQuestion, ProgrammingQuestion, VotingQuestion}
10

11
  @type t :: %__MODULE__{}
12

13
  schema "questions" do
60✔
14
    field(:display_order, :integer)
15
    field(:question, :map)
16
    field(:type, QuestionType)
17
    field(:max_xp, :integer)
18
    field(:show_solution, :boolean, default: false)
19
    field(:blocking, :boolean, default: false)
20
    field(:answer, :map, virtual: true)
21
    embeds_one(:library, Library, on_replace: :update)
22
    embeds_one(:grading_library, Library, on_replace: :update)
23
    belongs_to(:assessment, Assessment)
24
    timestamps()
25
  end
26

27
  @required_fields ~w(question type assessment_id)a
28
  @optional_fields ~w(display_order max_xp show_solution blocking)a
29
  @required_embeds ~w(library)a
30

31
  def changeset(question, params) do
32
    question
33
    |> cast(params, @required_fields ++ @optional_fields)
34
    |> add_belongs_to_id_from_model(:assessment, params)
35
    |> cast_embed(:library)
36
    |> cast_embed(:grading_library)
37
    |> validate_required(@required_fields ++ @required_embeds)
38
    |> validate_question_content()
UNCOV
39
    |> foreign_key_constraint(:assessment_id)
×
40
  end
41

42
  defp validate_question_content(changeset) do
UNCOV
43
    validate_arbitrary_embedded_struct_by_type(changeset, :question, %{
×
44
      mcq: MCQQuestion,
45
      programming: ProgrammingQuestion,
46
      voting: VotingQuestion
47
    })
48
  end
49
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc