Skip to content

Commit

Permalink
Don't show Best Performance selector if results include nonbinary cat…
Browse files Browse the repository at this point in the history
…egory
  • Loading branch information
moveson committed Oct 30, 2023
1 parent e15839a commit 23e0a32
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
7 changes: 7 additions & 0 deletions app/models/results_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ class ResultsTemplate < ApplicationRecord

validates_presence_of :name, :aggregation_method

# @return [ResultsTemplate]
def self.default
find_by(slug: "simple")
end

# @return [ResultsTemplate]
def dup_with_categories
# This must be done first or relations will be lost
set_category_positions
Expand All @@ -32,6 +34,11 @@ def dup_with_categories
template
end

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

private

def set_category_positions
Expand Down
7 changes: 6 additions & 1 deletion app/presenters/podium_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class PodiumPresenter < BasePresenter
attr_reader :event

delegate :name, :course, :course_name, :organization, :organization_name, :to_param, :multiple_laps?,
:event_group, :ordered_events_within_group, :scheduled_start_time_local, to: :event
:event_group, :ordered_events_within_group, :results_template, :scheduled_start_time_local, to: :event
delegate :available_live, :multiple_events?, to: :event_group
delegate :course_groups, to: :course

Expand All @@ -19,6 +19,11 @@ def categories
template&.results_categories || []
end

# @return [Array<Symbol>]
def sort_methods
results_template.includes_nonbinary? ? [:category] : [:category, :best_performance]
end

# @return [Array<Results::Category>]
def sorted_categories
if performance_sort?
Expand Down
12 changes: 7 additions & 5 deletions app/views/events/podium.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="ost-heading row">
<div class="col">
<div class="ost-title">
<h1><strong><%= [@presenter.name, nil].compact.join(": ") %></strong></h1>
<h1><strong><%= [@presenter.name, nil].compact.join(": ") %></strong></h1>
<ul class="breadcrumb breadcrumb-ost">
<li class="breadcrumb-item"><%= link_to "Organizations", organizations_path %></li>
<li class="breadcrumb-item"><%= link_to @presenter.organization.name, organization_path(@presenter.organization) %></li>
Expand Down Expand Up @@ -35,10 +35,12 @@
</div>
<div class="col text-end">
<div class="btn-group btn-group-ost">
<% [:category, :best_performance].each do |sort_method| %>
<%= link_to sort_method.to_s.titleize,
request.params.merge(sort: sort_method),
class: "btn #{ @presenter.sort_method == sort_method ? 'btn-primary' : 'btn-outline-secondary' }" %>
<% if @presenter.sort_methods.many? %>
<% @presenter.sort_methods.each do |sort_method| %>
<%= link_to sort_method.to_s.titleize,
request.params.merge(sort: sort_method),
class: "btn #{ @presenter.sort_method == sort_method ? 'btn-primary' : 'btn-outline-secondary' }" %>
<% end %>
<% end %>
</div>
</div>
Expand Down
16 changes: 16 additions & 0 deletions spec/models/results_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,20 @@
expect { results_template.save }.to change { ResultsTemplate.count }.by(1)
end
end

describe "#includes_nonbinary?" do
let(:result) { results_template.includes_nonbinary? }

context "when the template includes a nonbinary category" do
let(:results_template) { results_templates(:masters_and_grandmasters_with_nonbinary) }

it { expect(result).to eq(true)}
end

context "when the template does not include a nonbinary category" do
let(:results_template) { results_templates(:masters_and_grandmasters) }

it { expect(result).to eq(false)}
end
end
end

0 comments on commit 23e0a32

Please sign in to comment.