Ensure puzzle uniqueness per contestant validation error is shown
All checks were successful
CI / scan_ruby (push) Successful in 17s
CI / scan_js (push) Successful in 12s
CI / lint (push) Successful in 13s
CI / test (push) Successful in 33s

This commit is contained in:
sto 2025-06-27 08:59:27 +02:00
parent 9862f0c74b
commit b6da55723d
3 changed files with 6 additions and 1 deletions

View File

@ -36,7 +36,8 @@ class Completion < ApplicationRecord
before_save :add_time_seconds before_save :add_time_seconds
validates :display_time_from_start, presence: true, format: { with: /\A(((\d\d|\d):\d\d|\d\d|\d):\d\d|\d\d|\d)\z/ } validates :display_time_from_start, presence: true, format: { with: /\A(((\d\d|\d):\d\d|\d\d|\d):\d\d|\d\d|\d)\z/ }
validates :puzzle_id, uniqueness: { scope: :contestant } validates :contestant_id, uniqueness: { scope: :puzzle }, if: -> { contest.puzzles.size == 1 }
validates :puzzle_id, uniqueness: { scope: :contestant }, if: -> { contest.puzzles.size > 1 }
def add_time_seconds def add_time_seconds
arr = display_time_from_start.split(":") arr = display_time_from_start.split(":")

View File

@ -82,6 +82,8 @@ en:
models: models:
completion: completion:
attributes: attributes:
contestant_id:
taken: "This contestant has already completed the puzzle"
display_time_from_start: display_time_from_start:
blank: Mandatory blank: Mandatory
invalid: "Allowed formats: xx:xx:xx, x:xx:xx, xx:xx, x:xx, xx" invalid: "Allowed formats: xx:xx:xx, x:xx:xx, xx:xx, x:xx, xx"

View File

@ -53,6 +53,8 @@ fr:
models: models:
completion: completion:
attributes: attributes:
contestant_id:
taken: "Ce.tte participant.e a déjà complété le puzzle"
display_time_from_start: display_time_from_start:
blank: Obligatoire blank: Obligatoire
invalid: "Formats autorisés: xx:xx:xx, x:xx:xx, xx:xx, x:xx, xx" invalid: "Formats autorisés: xx:xx:xx, x:xx:xx, xx:xx, x:xx, xx"