Skip to content

Commit

Permalink
Begin working through deprecations and activerecord changes
Browse files Browse the repository at this point in the history
  • Loading branch information
moveson committed Dec 22, 2024
1 parent 1f5ac8f commit 8bdeecb
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 57 deletions.
10 changes: 8 additions & 2 deletions app/models/lottery_division.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ def withdrawn_entrants
private

def broadcast_lottery_draw_header
broadcast_replace_to self, :lottery_draw_header, target: "draw_tickets_header_lottery_division_#{id}", partial: "lottery_divisions/draw_tickets_header", locals: { division: self }
broadcast_replace_to self, :lottery_header, target: "lottery_header_lottery_division_#{id}", partial: "lottery_divisions/tickets_progress_bars", locals: { division: self, show_pre_selected: false }
broadcast_replace_to self, :lottery_draw_header,
target: "draw_tickets_header_lottery_division_#{id}",
partial: "lottery_divisions/draw_tickets_header",
locals: { lottery_division: self }
broadcast_replace_to self, :lottery_header,
target: "lottery_header_lottery_division_#{id}",
partial: "lottery_divisions/tickets_progress_bars",
locals: { lottery_division: self, show_pre_selected: false }
end
end
2 changes: 1 addition & 1 deletion app/models/results_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ResultsTemplate < ApplicationRecord
has_many :results_template_categories, -> { order(position: :asc) }, dependent: :destroy
has_many :results_categories, through: :results_template_categories

alias_attribute :categories, :results_categories
alias_method :categories, :results_categories

scope :standard, lambda {
select("results_templates.*, count(results_categories.id) as category_count")
Expand Down
18 changes: 9 additions & 9 deletions app/views/lottery_divisions/_draw_tickets_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<%# locals: (division:) -%>
<%# locals: (lottery_division:) %>

<div id="<%= dom_id(division, :draw_tickets_header) %>" class="min-width-3">
<h2 class="text-center"><strong><%= division.name %></strong></h2>
<div id="<%= dom_id(lottery_division, :draw_tickets_header) %>" class="min-width-3">
<h2 class="text-center"><strong><%= lottery_division.name %></strong></h2>
<hr/>

<div class="d-grid">
<div class="btn-group">
<%= link_to "Draw a Ticket", draw_organization_lottery_path(division.organization, division.lottery, division_id: division.id),
<%= link_to "Draw a Ticket", draw_organization_lottery_path(lottery_division.organization, lottery_division.lottery, division_id: lottery_division.id),
data: { turbo_method: :post },
disabled: division.full? || division.all_entrants_drawn?,
disabled: lottery_division.full? || lottery_division.all_entrants_drawn?,
class: "btn btn-lg btn-success fw-bold w-100" %>
<% if division.entrants.pre_selected.present? %>
<% if lottery_division.entrants.pre_selected.present? %>
<button class="btn btn-lg btn-success fw-bold dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<a class="dropdown-item disabled" href="#">Pre-Selected Entrants</a>
<div class="dropdown-divider"></div>
<% division.entrants.pre_selected.each do |entrant| %>
<%= link_to "Draw #{entrant.full_name}", draw_organization_lottery_lottery_entrant_path(division.organization, division.lottery, entrant),
<% lottery_division.entrants.pre_selected.each do |entrant| %>
<%= link_to "Draw #{entrant.full_name}", draw_organization_lottery_lottery_entrant_path(lottery_division.organization, lottery_division.lottery, entrant),
data: { turbo_method: :post },
disabled: entrant.drawn?,
class: "dropdown-item" %>
Expand All @@ -28,6 +28,6 @@
</div>
</div>

<%= render partial: "lottery_divisions/tickets_progress_bars", locals: { division: division, show_pre_selected: true} %>
<%= render partial: "lottery_divisions/tickets_progress_bars", locals: { lottery_division: lottery_division, show_pre_selected: true} %>

</div>
16 changes: 8 additions & 8 deletions app/views/lottery_divisions/_tickets_progress_bars.html.erb
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
<%# locals: (division:, show_pre_selected:) -%>
<%# locals: (lottery_division:, show_pre_selected:) %>

<div id="<%= dom_id(division, :lottery_header) %>" class="card mt-3">
<div id="<%= dom_id(lottery_division, :lottery_header) %>" class="card mt-3">
<div class="card-body">
<div class="row">
<div class="col-8">
<h6 class="fw-bold">Accepted</h6>
</div>
<div class="col-4">
<h6 class="text-end"><%= "(#{division.accepted_entrants.count}/#{division.maximum_entries})" %></h6>
<h6 class="text-end"><%= "(#{lottery_division.accepted_entrants.count}/#{lottery_division.maximum_entries})" %></h6>
</div>
</div>
<div class="progress">
<%= bootstrap_progress_bar(min_value: 0, max_value: division.maximum_entries, current_value: division.accepted_entrants.count, color: "success") %>
<%= bootstrap_progress_bar(min_value: 0, max_value: lottery_division.maximum_entries, current_value: lottery_division.accepted_entrants.count, color: "success") %>
</div>
<div class="row mt-2">
<div class="col-8">
<h6 class="fw-bold">Wait List</h6>
</div>
<div class="col-4">
<h6 class="text-end"><%= "(#{division.waitlisted_entrants.count}/#{division.maximum_wait_list})" %></h6>
<h6 class="text-end"><%= "(#{lottery_division.waitlisted_entrants.count}/#{lottery_division.maximum_wait_list})" %></h6>
</div>
</div>
<div class="progress">
<%= bootstrap_progress_bar(min_value: 0, max_value: division.maximum_wait_list, current_value: division.waitlisted_entrants.count, color: "warning") %>
<%= bootstrap_progress_bar(min_value: 0, max_value: lottery_division.maximum_wait_list, current_value: lottery_division.waitlisted_entrants.count, color: "warning") %>
</div>
<% if show_pre_selected %>
<div class="row mt-2">
<div class="col-8">
<h6 class="fw-bold">Pre-selected</h6>
</div>
<div class="col-4">
<h6 class="text-end"><%= "(#{division.entrants.pre_selected.drawn.count}/#{division.entrants.pre_selected.count})" %></h6>
<h6 class="text-end"><%= "(#{lottery_division.entrants.pre_selected.drawn.count}/#{lottery_division.entrants.pre_selected.count})" %></h6>
</div>
</div>
<div class="progress">
<%= bootstrap_progress_bar(min_value: 0, max_value: division.entrants.pre_selected.count, current_value: division.entrants.pre_selected.drawn.count, color: "secondary") %>
<%= bootstrap_progress_bar(min_value: 0, max_value: lottery_division.entrants.pre_selected.count, current_value: lottery_division.entrants.pre_selected.drawn.count, color: "secondary") %>
</div>
<% end %>
</div>
Expand Down
1 change: 0 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Application < Rails::Application

config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"
config.active_storage.variant_processor = :mini_magick
config.active_support.remove_deprecated_time_with_zone_name = true

if ::OstConfig.credentials_env?
Rails.application.config.credentials.content_path = ::OstConfig.credentials_content_path
Expand Down
1 change: 0 additions & 1 deletion config/initializers/active_storage.rb

This file was deleted.

6 changes: 4 additions & 2 deletions spec/controllers/concerns/prepared_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
let(:data_params) { {id: 123, attributes: {name: "John Doe", age: 50}} }

it "returns a hash containing the attributes" do
expected = {"name" => "John Doe", "age" => 50}
expected = ActionController::Parameters.new("name" => "John Doe", "age" => 50)
expected.permit!
validate_param("data", expected)
end

Expand All @@ -37,7 +38,8 @@
let(:data_params) { {id: 123, attributes: {name: "John Doe", age: 50, role: "admin"}} }

it "returns a hash containing only the permitted attributes" do
expected = {"name" => "John Doe", "age" => 50}
expected = ActionController::Parameters.new("name" => "John Doe", "age" => 50)
expected.permit!
validate_param("data", expected)
end
end
Expand Down
88 changes: 55 additions & 33 deletions spec/models/split_time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,50 +75,72 @@
end

context "for validations that rely on existing records in the database" do
let(:course) { create(:course) }
let(:start_split) { create(:split, :start, course: course) }
let(:intermediate_split) { create(:split, course: course) }
let(:event) { create(:event, course: course) }
let(:effort) { build(:effort, event: event) }

before { create(:split_time, effort: effort, lap: 1, split: intermediate_split, bitkey: in_bitkey, absolute_time: event.scheduled_start_time + 1.hour) }
let(:existing_split_time) { split_times(:hardrock_2015_tuan_jacobs_cunningham_in_1) }
let(:effort) { existing_split_time.effort }

context "when more than one of a given time_point exists within an effort" do
let(:split_time) { build_stubbed(:split_time, effort: effort, lap: 1, split: intermediate_split, bitkey: in_bitkey, absolute_time: event.scheduled_start_time + 2.hours) }
let(:split_time) do
effort.split_times.new(
lap: existing_split_time.lap,
split: existing_split_time.split,
bitkey: existing_split_time.bitkey,
absolute_time: existing_split_time.absolute_time + 5.minutes,
)
end

it "is invalid" do
expect(split_time).not_to be_valid
expect(split_time.errors[:split_id]).to include("only one of any given time_point permitted within an effort")
end
end

it "allows within an effort one of a given split_id/lap combination for each sub_split" do
build_stubbed(:split_time, effort: effort, split: intermediate_split, bitkey: in_bitkey, lap: 1)
split_time = build_stubbed(:split_time, effort: effort, split: intermediate_split, bitkey: out_bitkey, lap: 1)
expect(split_time).to be_valid
context "when sub_split bitkey is different" do
let(:split_time) do
effort.split_times.new(
lap: existing_split_time.lap,
split: existing_split_time.split,
bitkey: out_bitkey,
absolute_time: existing_split_time.absolute_time + 5.minutes,
)
end

before { split_times(:hardrock_2015_tuan_jacobs_cunningham_out_1).destroy }

it { expect(split_time).to be_valid }
end

it "allows multiple of a given split_id/sub_split/lap combination within different efforts" do
efforts = build_stubbed_list(:effort, 3, event: event)
build_stubbed(:split_time, effort: effort, split: intermediate_split, bitkey: in_bitkey, lap: 1)
split_time_1 = build_stubbed(:split_time, effort: efforts.first, split: intermediate_split, bitkey: in_bitkey, lap: 1)
split_time_2 = build_stubbed(:split_time, effort: efforts.second, split: intermediate_split, bitkey: in_bitkey, lap: 1)
split_time_3 = build_stubbed(:split_time, effort: efforts.third, split: intermediate_split, bitkey: in_bitkey, lap: 1)
expect(split_time_1).to be_valid
expect(split_time_2).to be_valid
expect(split_time_3).to be_valid
end

it "ensures that effort.event.course_id is the same as split.course_id" do
course_1 = build_stubbed(:course)
course_2 = build_stubbed(:course)
event = build_stubbed(:event, course: course_1)
effort = build_stubbed(:effort, event: event)
split = build_stubbed(:split, course: course_2)
split_time = build(:split_time, effort: effort, split: split)
expect(split_time).not_to be_valid
expect(split_time.errors[:effort_id]).to include("the effort.event.course_id does not resolve with the split.course_id")
expect(split_time.errors[:split_id]).to include("the effort.event.course_id does not resolve with the split.course_id")
context "when effort is different" do
let(:other_effort) { efforts(:hardrock_2015_erich_larson) }
let(:split_time) do
other_effort.split_times.new(
lap: existing_split_time.lap,
split: existing_split_time.split,
bitkey: existing_split_time.bitkey,
absolute_time: existing_split_time.absolute_time + 5.minutes,
)
end

before { split_times(:hardrock_2015_erich_larson_cunningham_in_1).destroy }

it { expect(split_time).to be_valid }
end

context "when effort.event.course_id is different from split.course_id" do
let(:split_from_different_course) { splits(:hardrock_cw_cunningham) }
let(:split_time) do
effort.split_times.new(
lap: existing_split_time.lap,
split: split_from_different_course,
bitkey: existing_split_time.bitkey,
absolute_time: existing_split_time.absolute_time + 5.minutes,
)
end

it "is not valid" do
expect(split_time).not_to be_valid
expect(split_time.errors[:effort_id]).to include("the effort.event.course_id does not resolve with the split.course_id")
expect(split_time.errors[:split_id]).to include("the effort.event.course_id does not resolve with the split.course_id")
end
end
end
end
Expand Down

0 comments on commit 8bdeecb

Please sign in to comment.