Skip to content

Commit

Permalink
Remove results_ prefix from relations; get specs passing
Browse files Browse the repository at this point in the history
  • Loading branch information
moveson committed Dec 22, 2024
1 parent 8bdeecb commit 0a5f40c
Show file tree
Hide file tree
Showing 29 changed files with 171 additions and 175 deletions.
21 changes: 11 additions & 10 deletions app/controllers/event_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class EventGroupsController < ApplicationController
# GET /event_groups
def index
scoped_event_groups = policy_scope(EventGroup)
.search(params[:search])
.by_group_start_time
.preload(:events)
.paginate(page: params[:page], per_page: 25)
.search(params[:search])
.by_group_start_time
.preload(:events)
.paginate(page: params[:page], per_page: 25)
@presenter = EventGroupsCollectionPresenter.new(scoped_event_groups, params, current_user)
session[:return_to] = event_groups_path
end
Expand Down Expand Up @@ -113,9 +113,9 @@ def setup_summary
# GET /event_groups/1/efforts
def efforts
@efforts = policy_scope(@event_group.efforts)
.order(prepared_params[:sort] || :bib_number, :last_name, :first_name)
.where(prepared_params[:filter])
.finish_info_subquery
.order(prepared_params[:sort] || :bib_number, :last_name, :first_name)
.where(prepared_params[:filter])
.finish_info_subquery

render partial: "event_groups/finish_line_effort", locals: { efforts: @efforts }
end
Expand Down Expand Up @@ -437,9 +437,10 @@ def delete_duplicate_raw_times

private

def bib_assignment_hash(params_hash)
params_hash.select { |key, _| key.include?("bib_for") }
.transform_keys { |key| key.delete("^0-9").to_i }
def bib_assignment_hash(event_group_params)
event_group_params.to_unsafe_h
.select { |key, _| key.include?("bib_for") }
.transform_keys { |key| key.delete("^0-9").to_i }
end

def redirect_if_no_events
Expand Down
4 changes: 2 additions & 2 deletions app/madmin/resources/results_category_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class ResultsCategoryResource < Madmin::Resource

# Associations
attribute :organization
attribute :results_template_categories
attribute :results_templates
attribute :template_categories
attribute :templates

# Uncomment this to customize the display name of records in the admin area.
def self.display_name(record)
Expand Down
4 changes: 2 additions & 2 deletions app/madmin/resources/results_template_category_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class ResultsTemplateCategoryResource < Madmin::Resource
attribute :fixed_position

# Associations
attribute :results_template
attribute :results_category
attribute :template
attribute :category

# Uncomment this to customize the display name of records in the admin area.
def self.display_name(record)
Expand Down
4 changes: 2 additions & 2 deletions app/madmin/resources/results_template_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class ResultsTemplateResource < Madmin::Resource
# Associations
attribute :slugs
attribute :organization
attribute :results_template_categories
attribute :results_categories
attribute :template_categories
attribute :categories

# Uncomment this to customize the display name of records in the admin area.
def self.display_name(record)
Expand Down
4 changes: 2 additions & 2 deletions app/models/results_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class ResultsCategory < ApplicationRecord
friendly_id :organization_genders_ages, use: [:sequentially_slugged, :history]

belongs_to :organization, optional: true
has_many :results_template_categories, dependent: :destroy
has_many :results_templates, through: :results_template_categories
has_many :template_categories, dependent: :destroy, class_name: "ResultsTemplateCategory"
has_many :templates, through: :template_categories, class_name: "ResultsTemplate"

validates_presence_of :name
validates_uniqueness_of :name, scope: :organization
Expand Down
16 changes: 7 additions & 9 deletions app/models/results_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ class ResultsTemplate < ApplicationRecord
friendly_id :name, use: [:slugged, :history]

belongs_to :organization, optional: true
has_many :results_template_categories, -> { order(position: :asc) }, dependent: :destroy
has_many :results_categories, through: :results_template_categories

alias_method :categories, :results_categories
has_many :template_categories, -> { order(position: :asc) }, dependent: :destroy, class_name: "ResultsTemplateCategory"
has_many :categories, through: :template_categories, class_name: "ResultsCategory"

scope :standard, lambda {
select("results_templates.*, count(results_categories.id) as category_count")
.joins(:results_categories).where(organization: nil).group(:id).order("category_count")
.joins(:categories).where(organization: nil).group(:id).order("category_count")
}

validates_presence_of :name, :aggregation_method
Expand All @@ -30,21 +28,21 @@ def dup_with_categories
set_category_positions

template = dup
template.results_categories = results_categories.map(&:dup)
template.categories = categories.map(&:dup)
template
end

# @return [Boolean]
def includes_nonbinary?
results_categories.where(nonbinary: true).exists?
categories.where(nonbinary: true).exists?
end

private

def set_category_positions
indexed_rtcs = results_template_categories.index_by(&:results_category_id)
indexed_rtcs = template_categories.index_by(&:results_category_id)

results_categories.each do |rc|
categories.each do |rc|
rtc = indexed_rtcs[rc.id]
rc.position = rtc.position
rc.fixed_position = rtc.fixed_position
Expand Down
12 changes: 6 additions & 6 deletions app/models/results_template_category.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# frozen_string_literal: true

class ResultsTemplateCategory < ApplicationRecord
belongs_to :results_template, optional: false
belongs_to :results_category, optional: false
belongs_to :template, optional: false, class_name: "ResultsTemplate", foreign_key: :results_template_id
belongs_to :category, optional: false, class_name: "ResultsCategory", foreign_key: :results_category_id

acts_as_list scope: :results_template
validates_presence_of :results_category, :results_template
acts_as_list scope: :template
validates_presence_of :category, :template

def category_description
results_category.description
category.description
end

def category_name
results_category.name
category.name
end
end
2 changes: 1 addition & 1 deletion app/presenters/event_series_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class EventSeriesPresenter < BasePresenter
attr_reader :event_series

delegate :name, :organization, :scoring_method, to: :event_series
delegate :results_categories, to: :completed_template
delegate :categories, to: :completed_template

def initialize(event_series, view_context)
@event_series = event_series || []
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/podium_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(event, view_context, template:)

# @return [Array<Results::Category>]
def categories
template&.results_categories || []
template&.categories || []
end

# @return [Array<Symbol>]
Expand Down
2 changes: 1 addition & 1 deletion app/services/results/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def point_system
end

def categories
template.results_categories
template.categories
end

def fill(category)
Expand Down
4 changes: 2 additions & 2 deletions app/views/courses/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

<header class="ost-header">
<div class="container">
<%= render "organizations/organization_heading", presenter: @presenter %>
<%= render partial: "organizations/organization_heading", locals: { presenter: @presenter } %>
<!-- Navigation -->
<%= render "organizations/organization_tabs", presenter: @presenter %>
<%= render partial: "organizations/organization_tabs", locals: { presenter: @presenter } %>
</div>
</header>

Expand Down
2 changes: 1 addition & 1 deletion app/views/courses/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<% end %>
<% else %>
<% if @presenter.events.present? %>
<%= render "events/events", presenter: @presenter, events: @presenter.events, show_grouping_button: false %>
<%= render "events/events", events: @presenter.events %>
<% else %>
<h4>No events have been held on this course.</h4>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/efforts/_effort_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%# locals: (view_object:) -%>
<%# locals: (view_object:, title: nil) -%>

<header class="ost-header">
<div class="container">
Expand Down
2 changes: 1 addition & 1 deletion app/views/efforts/_entrant_for_roster.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%# locals: (effort:, multiple_events, :started_efforts_present:) -%>
<%# locals: (effort:, multiple_events:, started_efforts_present:) -%>

<tr id="<%= dom_id effort, :roster_row %>"
data-controller="highlight"
Expand Down
4 changes: 2 additions & 2 deletions app/views/event_groups/_setup_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%# locals: (presenter:, breadcrumbs:) -%>
<%# locals: (presenter:, breadcrumbs: []) -%>

<header class="ost-header">
<div class="container">
Expand All @@ -25,7 +25,7 @@
</div>
<div class="container w-75">
<div class="ost-heading">
<%= render "event_groups/setup_widget", presenter: presenter %>
<%= render partial: "event_groups/setup_widget", locals: { presenter: presenter } %>
</div>
</div>
</header>
4 changes: 2 additions & 2 deletions app/views/event_groups/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<% "OpenSplitTime: New Event Group" %>
<% end %>

<%= render "shared/mode_widget", event_group: @presenter.event_group %>
<%= render "setup_header", presenter: @presenter %>
<%= render partial: "shared/mode_widget", locals: { event_group: @presenter.event_group } %>
<%= render partial: "setup_header", locals: { presenter: @presenter } %>

<article class="ost-article container">
<h4>We will first need some basic information about your Event Group</h4>
Expand Down
2 changes: 1 addition & 1 deletion app/views/event_series/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<hr/>

<table class="table table-sm table-striped podium">
<% @presenter.results_categories.each do |category| %>
<% @presenter.categories.each do |category| %>
<% if category.invalid_efforts? %>
<%= render 'invalid_results_category', category: category %>
<% else %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/_course_setup_splits.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%# locals: (event:, splits:, aid_stations_by_split_id) -%>
<%# locals: (event:, splits:, aid_stations_by_split_id:) -%>

<table id="<%= dom_id(event, :course_setup_splits) %>"
class="table table-hover"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<%# locals: (count:, event_group:) -%>

<% count ||= nil %>
<%# locals: (event_group:, count: nil) -%>

<button id="force_pull_times_button"
class="btn btn-danger d-none"
Expand Down
4 changes: 1 addition & 3 deletions app/views/live/event_groups/_pull_times_button.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<%# locals: (count:, event_group:) -%>

<% count ||= nil %>
<%# locals: (event_group:, count: nil) -%>

<button id="pull_times_button"
class="btn btn-primary"
Expand Down
5 changes: 3 additions & 2 deletions app/views/live/event_groups/live_entry.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@
data-controller="live-entry--pull-times"
data-live-entry--pull-times-event-group-id-value="<%= @event_group.id %>"
>
<%= render "pull_times_button", event_group: @event_group %>
<%= render "force_pull_times_button", event_group: @event_group %>
<%= render partial: "pull_times_button", locals: { event_group: @event_group } %>
<%= render partial: "force_pull_times_button", locals: { event_group: @event_group } %>

<div class="btn-group" role="group">
<button id="js-delete-all-time-rows" class="btn btn-danger">Discard All</button>
<button id="js-delete-all-warning" class="btn btn-danger" disabled>Cannot Be Undone</button>
Expand Down
2 changes: 1 addition & 1 deletion app/views/lotteries/draw_tickets.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<%= turbo_stream_from division, :lottery_draws, class: "d-none" %>
<%= turbo_stream_from division, :lottery_draw_header, class: "d-none" %>
<div class="col-12 col-md-6 col-lg-4 col-xl">
<%= render "lottery_divisions/draw_tickets_header", division: division %>
<%= render partial: "lottery_divisions/draw_tickets_header", locals: { lottery_division: division } %>
<hr/>
<div id="<%= dom_id(division, :lottery_draws) %>">
<%= render partial: "lottery_draws/lottery_draw_admin", collection: division.draws.with_entrant_and_ticket.most_recent_first, as: :lottery_draw %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/lotteries/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<%= turbo_stream_from division, :lottery_header, class: "d-none" %>
<div class="col-12 col-md-6 col-lg-4 col-xl pb-3">
<h5 class="fw-bold"><%= division.name %></h5>
<%= render partial: "lottery_divisions/tickets_progress_bars", locals: { division: division, show_pre_selected: false } %>
<%= render partial: "lottery_divisions/tickets_progress_bars", locals: { lottery_division: division, show_pre_selected: false } %>
</div>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/organizations/_organization_tabs.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%# locals: (presenter) -%>
<%# locals: (presenter:) -%>

<ul class="nav nav-tabs nav-tabs-ost">
<%= content_tag :li, class: "nav-item #{'active' if presenter.controller_name == 'organizations'}" do %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/organizations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

<header class="ost-header">
<div class="container">
<%= render "organizations/organization_heading", presenter: @presenter %>
<%= render partial: "organizations/organization_heading", locals: { presenter: @presenter } %>
<!-- Navigation -->
<%= render "organizations/organization_tabs", presenter: @presenter %>
<%= render partial: "organizations/organization_tabs", locals: { presenter: @presenter } %>
</div>
</header>

Expand Down
4 changes: 2 additions & 2 deletions app/views/results_templates/_categories_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<h5><%= "#{template.podium_size ? pluralize(template.podium_size, 'Participant') : 'Unlimited Participants'} Per Category" %></h5>
<table>
<tbody>
<% template.results_template_categories.includes(:results_category).each do |rtc| %>
<% template.template_categories.includes(:category).each do |rtc| %>
<tr>
<td class="text-danger"><%= "#{'*' if rtc.fixed_position}" %></td>
<td><%= "#{rtc.position}." %></td>
<td><%= "#{rtc.category_name} (#{rtc.category_description})" %></td>
</tr>
<% end %>

<% if template.results_template_categories.any?(&:fixed_position?) %>
<% if template.template_categories.any?(&:fixed_position?) %>
<tr>
<td colspan="3" class="text-danger">* Position is fixed</td>
</tr>
Expand Down
Loading

0 comments on commit 0a5f40c

Please sign in to comment.