diff --git a/app/models/completion.rb b/app/models/completion.rb index 8468002..9bbf682 100644 --- a/app/models/completion.rb +++ b/app/models/completion.rb @@ -36,7 +36,8 @@ class Completion < ApplicationRecord 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 :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 arr = display_time_from_start.split(":") diff --git a/config/locales/en.yml b/config/locales/en.yml index dd2c423..52e467f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -82,6 +82,8 @@ en: models: completion: attributes: + contestant_id: + taken: "This contestant has already completed the puzzle" display_time_from_start: blank: Mandatory invalid: "Allowed formats: xx:xx:xx, x:xx:xx, xx:xx, x:xx, xx" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index bf55770..35f15f5 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -53,6 +53,8 @@ fr: models: completion: attributes: + contestant_id: + taken: "Ce.tte participant.e a déjà complété le puzzle" display_time_from_start: blank: Obligatoire invalid: "Formats autorisés: xx:xx:xx, x:xx:xx, xx:xx, x:xx, xx"