Messages to completions conversion
Some checks failed
CI / scan_ruby (push) Failing after 15s
CI / scan_js (push) Successful in 11s
CI / lint (push) Successful in 14s
CI / test (push) Successful in 31s

This commit is contained in:
sto
2025-05-15 08:57:25 +02:00
parent e65d639ca6
commit c4902d85d5
16 changed files with 127 additions and 20 deletions

View File

@@ -29,7 +29,17 @@ class Completion < ApplicationRecord
belongs_to :contestant
belongs_to :puzzle
validates :time_seconds, presence: true
validates_numericality_of :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\z/ }
validates :puzzle_id, uniqueness: { scope: :contestant }
def add_time_seconds
arr = display_time_from_start.split(":")
if arr.size == 3
self.time_seconds = arr[0].to_i * 3600 + arr[1].to_i * 60 + arr[2].to_i
elsif arr.size == 2
self.time_seconds = arr[0].to_i * 60 + arr[1].to_i
end
end
end

View File

@@ -3,6 +3,8 @@
# Table name: messages
#
# id :integer not null, primary key
# author :string
# display_time :string
# text :string not null
# time_seconds :integer not null
# created_at :datetime not null
@@ -20,5 +22,6 @@
class Message < ApplicationRecord
belongs_to :contest
validates :author, presence: true
validates :text, presence: true
end