From fe72034d86c5ccf54f89a8ac6291dcfc0f0bc1e2 Mon Sep 17 00:00:00 2001 From: moveson Date: Thu, 4 Jul 2024 14:21:22 -0600 Subject: [PATCH] Exclude hardcoded bib numbers from automatic bib number assignments --- app/models/effort.rb | 1 + app/services/compute_bib_assignments.rb | 2 +- spec/services/compute_bib_assignments_spec.rb | 23 ++++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/models/effort.rb b/app/models/effort.rb index 64616adc9..8f1a4f011 100644 --- a/app/models/effort.rb +++ b/app/models/effort.rb @@ -73,6 +73,7 @@ class Effort < ApplicationRecord after_update_commit :broadcast_update pg_search_scope :search_bib, against: :bib_number, using: { tsearch: { any_word: true } } + scope :bib_not_hardcoded, -> { where(bib_number_hardcoded: [false, nil]) } scope :bib_number_among, -> (param) { param.present? ? search_bib(param) : all } scope :on_course, -> (course) { includes(:event).where(events: { course_id: course.id }) } scope :unreconciled, -> { where(person_id: nil) } diff --git a/app/services/compute_bib_assignments.rb b/app/services/compute_bib_assignments.rb index 61f87b309..e58d94db6 100644 --- a/app/services/compute_bib_assignments.rb +++ b/app/services/compute_bib_assignments.rb @@ -35,7 +35,7 @@ def perform attr_reader :event, :strategy, :result def compute_for_hardrock - efforts = event.efforts.select(:id, :person_id, :first_name, :last_name).to_a + efforts = event.efforts.bib_not_hardcoded.select(:id, :person_id, :first_name, :last_name).to_a prior_hardrock = event.organization.events.where("scheduled_start_time < ?", event.scheduled_start_time).order(scheduled_start_time: :desc).first ordered_prior_person_ids = prior_hardrock ? prior_hardrock.efforts.finished.ranked_order.pluck(:person_id) : [] diff --git a/spec/services/compute_bib_assignments_spec.rb b/spec/services/compute_bib_assignments_spec.rb index 1e727f9e9..1a3b2bf5a 100644 --- a/spec/services/compute_bib_assignments_spec.rb +++ b/spec/services/compute_bib_assignments_spec.rb @@ -49,7 +49,7 @@ effort_1.id => 1, effort_2.id => 2, effort_3.id => 100, - effort_4.id => 101 + effort_4.id => 101, } end @@ -57,6 +57,27 @@ expect(result).to eq(expected_result) end end + + context "when an entrant has a hardcoded bib number" do + let(:prior_event) { events(:hardrock_2015) } + + before do + event.efforts.ranked_order.last(15).each(&:destroy) + effort_1.update(bib_number: "85", bib_number_hardcoded: true) + end + + let(:expected_result) do + { + effort_2.id => 100, + effort_3.id => 101, + effort_4.id => 102, + } + end + + it "ignores hardcoded bib numbers" do + expect(result).to eq(expected_result) + end + end end end end