Skip to content

Commit

Permalink
Exclude hardcoded bib numbers from automatic bib number assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
moveson committed Jul 4, 2024
1 parent d90ad3e commit fe72034
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/models/effort.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 1 addition & 1 deletion app/services/compute_bib_assignments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) : []

Expand Down
23 changes: 22 additions & 1 deletion spec/services/compute_bib_assignments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,35 @@
effort_1.id => 1,
effort_2.id => 2,
effort_3.id => 100,
effort_4.id => 101
effort_4.id => 101,
}
end

it "computes bibs of prior year finishers starting at 1 and other bibs alphabetically starting at 100" do
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

0 comments on commit fe72034

Please sign in to comment.