Allinea stato e titolo replay del tabellone al risultato reale.
Una gara con punteggio non resta più «In programma» solo perché l'orario è futuro, e i replay usano le squadre del match invece della squadra di trasmissione. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -100,8 +100,8 @@ module Public
|
||||
def tournament_public_board_state(match)
|
||||
return :live if tournament_public_live_session(match)
|
||||
return :replay if tournament_public_recording(match)
|
||||
return :ended if match.played? || match.result_status.to_s.start_with?("walkover") || match.home_score.present?
|
||||
return :scheduled if match.scheduled_upcoming?
|
||||
return :ended if match.played? || match.home_score.present?
|
||||
|
||||
:waiting
|
||||
end
|
||||
|
||||
@@ -146,14 +146,22 @@ class Recording < ApplicationRecord
|
||||
end
|
||||
|
||||
def title_or_default
|
||||
title.presence || default_title
|
||||
match = stream_session&.match
|
||||
return title.presence || "Replay" unless match
|
||||
|
||||
generated = match.matchup_label
|
||||
stored = title.to_s.strip
|
||||
return generated if stored.blank?
|
||||
return generated if stale_auto_title?(match, stored)
|
||||
|
||||
stored
|
||||
end
|
||||
|
||||
def default_title
|
||||
match = stream_session&.match
|
||||
return "Replay" unless match
|
||||
|
||||
"#{match.team.name} vs #{match.opponent_name}"
|
||||
match.matchup_label
|
||||
end
|
||||
|
||||
def recorded_at_or_fallback
|
||||
@@ -222,6 +230,18 @@ class Recording < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def stale_auto_title?(match, stored)
|
||||
return false unless match.tournament_match?
|
||||
|
||||
team_name = match.team&.name.to_s
|
||||
return false if team_name.blank?
|
||||
|
||||
[
|
||||
"#{team_name} vs #{match.opponent_name}",
|
||||
"#{team_name} vs #{match.away_display_name}"
|
||||
].include?(stored)
|
||||
end
|
||||
|
||||
def normalize_privacy_status
|
||||
self.privacy_status = "public" if privacy_status == "private"
|
||||
self.privacy_status = "unlisted" if privacy_status.blank?
|
||||
|
||||
@@ -73,7 +73,7 @@ module Recordings
|
||||
|
||||
def default_title
|
||||
match = @session.match
|
||||
"#{match.team.name} vs #{match.opponent_name}"
|
||||
match.matchup_label.presence || "Replay"
|
||||
end
|
||||
|
||||
def privacy_from_session
|
||||
|
||||
@@ -52,8 +52,11 @@
|
||||
<span class="replay-card__play" aria-hidden="true">▶</span>
|
||||
</div>
|
||||
<div class="replay-card__body">
|
||||
<strong class="replay-card__title"><%= rec.title.presence || match.matchup_label %></strong>
|
||||
<p class="replay-card__meta"><%= match.matchup_label %></p>
|
||||
<% phase = [match.tournament_round&.name, match.tournament_group&.name].compact.first %>
|
||||
<strong class="replay-card__title"><%= match.matchup_label %></strong>
|
||||
<p class="replay-card__meta">
|
||||
<%= [phase, rec.recorded_at_or_fallback && l(rec.recorded_at_or_fallback, format: :short)].compact.join(" · ") %>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -31,4 +31,45 @@ RSpec.describe Recording do
|
||||
rec = described_class.create!(stream_session: session, team: team, status: "processing")
|
||||
expect(rec.title_or_default).to eq("Team vs Rival")
|
||||
end
|
||||
|
||||
it "usa le squadre del tabellone al posto della squadra di trasmissione" do
|
||||
load Rails.root.join("db/seeds/plans.rb")
|
||||
Billing::AssignPlan.call(club: club, plan_slug: "premium_full")
|
||||
ClubMembership.create!(user: user, club: club, role: "owner")
|
||||
tournament = Tournaments::Create.call(
|
||||
club: club,
|
||||
attrs: {
|
||||
name: "Memorial",
|
||||
sport_key: "pallavolo",
|
||||
starts_on: Date.current,
|
||||
ends_on: Date.current,
|
||||
format_kind: "free"
|
||||
}
|
||||
)
|
||||
home = tournament.participants.create!(name: "Gamma")
|
||||
away = tournament.participants.create!(name: "Beta")
|
||||
tournament_match = Tournaments::ScheduleMatch.call(
|
||||
tournament: tournament,
|
||||
attrs: {
|
||||
home_participant_id: home.id,
|
||||
away_participant_id: away.id,
|
||||
scheduled_at: 1.hour.from_now
|
||||
}
|
||||
)
|
||||
tournament_session = StreamSession.create!(
|
||||
match: tournament_match,
|
||||
user: user,
|
||||
platform: "matchlivetv",
|
||||
status: "ended",
|
||||
privacy_status: "public"
|
||||
)
|
||||
rec = described_class.create!(
|
||||
stream_session: tournament_session,
|
||||
team: tournament.broadcast_team,
|
||||
status: "ready",
|
||||
title: "#{tournament.broadcast_team.name} vs Beta"
|
||||
)
|
||||
expect(rec.title_or_default).to eq("Gamma vs Beta")
|
||||
expect(rec.default_title).to eq("Gamma vs Beta")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -767,7 +767,7 @@ RSpec.describe "Tournaments", type: :request do
|
||||
session.update_columns(status: "ended", ended_at: Time.current)
|
||||
Recording.create!(
|
||||
stream_session: session, team: tournament.broadcast_team, status: "ready", privacy_status: "public",
|
||||
title: "Replay Alfa-Beta",
|
||||
title: "#{tournament.broadcast_team.name} vs #{away.name}",
|
||||
storage_key: "teams/#{tournament.broadcast_team_id}/sessions/#{session.id}/replay.mp4"
|
||||
)
|
||||
|
||||
@@ -775,9 +775,45 @@ RSpec.describe "Tournaments", type: :request do
|
||||
expect(response.body).to include("Guarda replay")
|
||||
expect(response.body).to include(public_replay_path(session.id))
|
||||
expect(response.body).to include("tournament-live-status--replay")
|
||||
expect(response.body).to include("Replay Alfa-Beta")
|
||||
expect(response.body).to include("#{home.name} vs #{away.name}")
|
||||
expect(response.body).not_to include("#{tournament.broadcast_team.name} vs #{away.name}")
|
||||
|
||||
get public_club_tournaments_path(club)
|
||||
expect(response.body).to include(public_tournament_page_path(tournament.slug))
|
||||
end
|
||||
|
||||
it "marca Terminata una gara con risultato anche se l'orario è ancora futuro" do
|
||||
assign_plan!("premium_full")
|
||||
login!
|
||||
tournament = Tournaments::Create.call(
|
||||
club: club,
|
||||
attrs: {
|
||||
name: "Open Risultato Anticipato",
|
||||
sport_key: "pallavolo",
|
||||
starts_on: Date.current,
|
||||
ends_on: Date.current + 1,
|
||||
format_kind: "free",
|
||||
courts: "Campo 1"
|
||||
}
|
||||
)
|
||||
home = tournament.participants.create!(name: "Alfa")
|
||||
away = tournament.participants.create!(name: "Delta")
|
||||
match = Tournaments::ScheduleMatch.call(
|
||||
tournament: tournament,
|
||||
attrs: {
|
||||
home_participant_id: home.id,
|
||||
away_participant_id: away.id,
|
||||
court: "Campo 1",
|
||||
scheduled_at: 6.hours.from_now
|
||||
}
|
||||
)
|
||||
Tournaments::RecordResult.call(match: match, home_score: 2, away_score: 0, source: "manual")
|
||||
post public_publish_tournament_path(tournament)
|
||||
|
||||
get public_tournament_page_path(tournament.slug, tab: "risultati")
|
||||
expect(response.body).to include("2–0")
|
||||
expect(response.body).to include("tournament-live-status--ended")
|
||||
expect(response.body).to include("Terminata")
|
||||
expect(response.body).not_to include("tournament-live-status--scheduled")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,6 +28,7 @@ RSpec.describe Recordings::FinalizeSession do
|
||||
expect(rec.storage_policy).to eq("retained")
|
||||
expect(rec.expires_at).to be > 29.days.from_now
|
||||
expect(rec.metadata["auto_publish_youtube"]).to eq(false)
|
||||
expect(rec.title).to eq("Team vs Rival")
|
||||
end
|
||||
|
||||
it "skips free plan" do
|
||||
|
||||
Reference in New Issue
Block a user