Add judges codes
Some checks failed
CI / scan_ruby (push) Failing after 18s
CI / scan_js (push) Successful in 15s
CI / lint (push) Successful in 15s
CI / test (push) Failing after 45s

This commit is contained in:
sto
2025-11-20 16:59:30 +01:00
parent b43a801e3c
commit 94e725d20a
15 changed files with 184 additions and 113 deletions

View File

@@ -3,6 +3,7 @@
# Table name: completions
#
# id :integer not null, primary key
# code :string
# completed :boolean
# display_relative_time :string
# display_time_from_start :string
@@ -50,10 +51,11 @@ class Completion < ApplicationRecord
validates :puzzle_id, uniqueness: { scope: :contestant }, if: -> { contest.puzzles.size > 1 }
validates :remaining_pieces, numericality: { only_integer: true }, if: -> { remaining_pieces.present? }
validate :remaining_pieces_is_correct, if: -> { remaining_pieces.present? }
validate :contest_code_is_correct, if: -> { code.present? }
def remaining_pieces_is_correct
if self.remaining_pieces > self.puzzle.pieces
errors.add(:remaining_pieces, "Cannot be greater than the number of pieces for this puzzle")
errors.add(:remaining_pieces, I18n.t("activerecord.errors.models.completion.attributes.remaining_pieces.too_large"))
end
end
@@ -92,4 +94,10 @@ class Completion < ApplicationRecord
self.projected_time = assembled_time + Integer(self.remaining_pieces.to_f / pieces_per_second)
end
end
def contest_code_is_correct
if self.code != self.contest.code
errors.add(:code, I18n.t("activerecord.errors.models.completion.attributes.code.mismatch"))
end
end
end