1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-02 21:24:25 +00:00

Upgraded to rails 8.0.2, moved from dalli to solid cache, moved from delayed_job to solid queue, and add solid cable. deploy/rails-dev-run.sh no longer needs to chmod. Fixed finished_at callback for matches. Migrated from Devise to built in rails auth. Added view tests for the bracket page testing that all bout numbers render for all matches in each bracket type.

This commit is contained in:
2025-04-08 17:54:42 -04:00
parent 9c25a6cc39
commit 2d433b680a
118 changed files with 4921 additions and 1341 deletions

View File

@@ -6,9 +6,8 @@ class Match < ApplicationRecord
has_many :schools, :through => :wrestlers
validate :score_validation, :win_type_validation, :bracket_position_validation, :overtime_type_validation
# Callback to update finished_at when finished changes
# for some reason saved_change_to_finished? does not work on before_save like it does for after_update
before_save :update_finished_at, if: -> { will_save_change_to_attribute?(:finished) }
# Callback to update finished_at when a match is finished
before_save :update_finished_at
after_update :after_finished_actions, if: -> {
saved_change_to_finished? ||
@@ -312,6 +311,12 @@ class Match < ApplicationRecord
private
def update_finished_at
self.finished_at = finished == 1 ? Time.current.utc : nil
# Get the changes that will be persisted
changes = changes_to_save
# Check if finished is changing from 0 to 1 or if it's already 1 but has no timestamp
if (changes['finished'] && changes['finished'][1] == 1) || (finished == 1 && finished_at.nil?)
self.finished_at = Time.current.utc
end
end
end

View File

@@ -36,13 +36,9 @@ class School < ApplicationRecord
end
def calculate_score
if Rails.env.production?
self.delay(:job_owner_id => self.tournament.id, :job_owner_type => "Calculate team score for #{self.name}").calculate_score_raw
else
calculate_score_raw
end
end
# Use perform_later which will execute based on centralized adapter config
CalculateSchoolScoreJob.perform_later(self)
end
def calculate_score_raw
newScore = total_points_scored_by_wrestlers - total_points_deducted

View File

@@ -14,16 +14,6 @@ class Tournament < ApplicationRecord
attr_accessor :import_text
def deferred_jobs
Delayed::Job.where(job_owner_id: self.id)
end
def clear_errored_deferred_jobs
Delayed::Job.where(job_owner_id: self.id, last_error: ! nil).each do |job|
job.destroy
end
end
def self.search_date_name(pattern)
if pattern.blank? # blank? covers both nil and empty string
all
@@ -87,11 +77,8 @@ class Tournament < ApplicationRecord
end
def total_rounds
if self.matches.count > 0
self.matches.sort_by{|m| m.round}.last.round
else
0
end
# Assuming this is line 147 that's causing the error
matches.maximum(:round) || 0 # Return 0 if no matches or max round is nil
end
def assign_mats(mats_to_assign)
@@ -259,5 +246,26 @@ class Tournament < ApplicationRecord
def create_backup()
TournamentBackupService.new(self, "Manual backup").create_backup
end
def confirm_all_weights_have_original_seeds
error_string = wrestlers_with_higher_seed_than_bracket_size_error
error_string += wrestlers_with_duplicate_original_seed_error
error_string += wrestlers_with_out_of_order_seed_error
return error_string.blank?
end
def confirm_each_weight_class_has_correct_number_of_wrestlers
error_string = pool_to_bracket_number_of_wrestlers_error
error_string += modified_sixteen_man_number_of_wrestlers_error
error_string += double_elim_number_of_wrestlers_error
return error_string.blank?
end
private
def connection_adapter
ActiveRecord::Base.connection.adapter_name
end
end

View File

@@ -1,12 +1,56 @@
class User < ApplicationRecord
attr_accessor :reset_token
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
has_many :tournaments
has_many :delegated_tournament_permissions, class_name: "TournamentDelegate"
has_many :delegated_school_permissions, class_name: "SchoolDelegate"
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Replace Devise with has_secure_password
has_secure_password
# Add validations that were handled by Devise
validates :email, presence: true, uniqueness: { case_sensitive: false }
validates :password, length: { minimum: 6 }, allow_nil: true
# These are the Devise modules we were using:
# devise :database_authenticatable, :registerable,
# :recoverable, :rememberable, :trackable, :validatable
# Returns the hash digest of the given string
def self.digest(string)
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
BCrypt::Password.create(string, cost: cost)
end
# Returns a random token
def self.new_token
SecureRandom.urlsafe_base64
end
# Sets the password reset attributes
def create_reset_digest
self.reset_token = User.new_token
update_columns(reset_digest: User.digest(reset_token), reset_sent_at: Time.zone.now)
end
# Sends password reset email
def send_password_reset_email
UserMailer.password_reset(self).deliver_now
end
# Returns true if a password reset has expired
def password_reset_expired?
reset_sent_at < 2.hours.ago
end
# Returns true if the given token matches the digest
def authenticated?(attribute, token)
digest = send("#{attribute}_digest")
return false if digest.nil?
BCrypt::Password.new(digest).is_password?(token)
end
def delegated_tournaments
tournaments_delegated = []