From 2b8f842752d75b80721b688466872a7373120dc2 Mon Sep 17 00:00:00 2001 From: Emiliano Frascaro Date: Tue, 2 Jun 2026 19:10:07 +0200 Subject: [PATCH] Dirette: nasconde partite programmate nel passato. La pagina /live mostrava tutte le partite da inizio giornata; ora solo con orario futuro. Co-authored-by: Cursor --- backend/app/models/match.rb | 4 ++-- backend/spec/models/match_scheduling_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 backend/spec/models/match_scheduling_spec.rb diff --git a/backend/app/models/match.rb b/backend/app/models/match.rb index 60f6049..c64be5e 100644 --- a/backend/app/models/match.rb +++ b/backend/app/models/match.rb @@ -7,9 +7,9 @@ class Match < ApplicationRecord validates :opponent_name, presence: true validates :sets_to_win, numericality: { greater_than: 0, less_than: 6 } - # Partite con data/ora: da inizio giornata (Europe/Rome) in poi — allineato alla pagina Partite. + # Partite ancora da giocare in diretta (orario nel futuro). scope :scheduled_for_live, -> { - where.not(scheduled_at: nil).where("scheduled_at >= ?", Time.zone.now.beginning_of_day) + where.not(scheduled_at: nil).where("scheduled_at >= ?", Time.zone.now) } scope :scheduled_upcoming, -> { scheduled_for_live } diff --git a/backend/spec/models/match_scheduling_spec.rb b/backend/spec/models/match_scheduling_spec.rb new file mode 100644 index 0000000..d8597b4 --- /dev/null +++ b/backend/spec/models/match_scheduling_spec.rb @@ -0,0 +1,16 @@ +require "rails_helper" + +RSpec.describe Match, "scheduling scopes" do + let!(:club) do + Club.create!(name: "Sched Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") + end + let!(:team) { club.teams.create!(name: "U16", sport: "volleyball") } + + it "scheduled_for_live esclude partite già passate oggi" do + past = team.matches.create!(opponent_name: "Past", scheduled_at: 2.hours.ago, sets_to_win: 3) + future = team.matches.create!(opponent_name: "Future", scheduled_at: 2.hours.from_now, sets_to_win: 3) + + expect(described_class.scheduled_for_live).to include(future) + expect(described_class.scheduled_for_live).not_to include(past) + end +end