Implement missing & remaining pieces propagation + cleaner forms
All checks were successful
CI / scan_ruby (push) Successful in 18s
CI / scan_js (push) Successful in 14s
CI / lint (push) Successful in 13s
CI / test (push) Successful in 34s

This commit is contained in:
sto
2025-11-10 12:26:48 +01:00
parent 6549124c08
commit f4136ea58a
15 changed files with 175 additions and 38 deletions

View File

@@ -9,6 +9,7 @@
# name :string not null
# remaining_pieces :integer
# start_time :datetime not null
# submitted :boolean
# created_at :datetime not null
# updated_at :datetime not null
# contest_id :integer not null
@@ -32,7 +33,10 @@ class Offline < ApplicationRecord
generates_token_for :token
before_save :clean_pieces
validates :name, presence: true
validates :remaining_pieces, presence: true, if: -> { submitted && !completed }
validates :start_time, presence: true
validate :end_image_is_present
@@ -56,10 +60,7 @@ class Offline < ApplicationRecord
end
def end_image_is_present
logger = Logger.new(STDOUT)
logger.info(self.missing_pieces)
logger.info(self.missing_pieces.present?)
if self.completed && self.images.length < 2
if self.submitted && self.images.length < 2
errors.add(:end_image, I18n.t("activerecord.errors.models.offline.attributes.end_image.blank"))
end
end
@@ -69,4 +70,12 @@ class Offline < ApplicationRecord
errors.add(:images, I18n.t("activerecord.errors.models.offline.attributes.start_image.blank"))
end
end
def clean_pieces
if self.completed
self.remaining_pieces = nil
else
self.missing_pieces = nil
end
end
end