Compare commits

..
1 Commits
Author SHA1 Message Date
eminuxandCursor 2db6541c91 Fix 500 in cancellazione partita con recording collegato.
Distruggendo la sessione ora si elimina anche il recording, evitando la violazione FK su recordings.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-11 08:09:34 +02:00
2 changed files with 38 additions and 1 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ class StreamSession < ApplicationRecord
has_many :attempted_concurrency_violations, class_name: "StreamConcurrencyViolation",
foreign_key: :attempted_session_id, dependent: :nullify, inverse_of: :attempted_session
has_one :score_state, dependent: :destroy
has_one :recording
has_one :recording, dependent: :destroy
has_many :device_states, dependent: :destroy
validates :platform, inclusion: { in: PLATFORMS }
@@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe "Public match destroy with recording", type: :request do
let!(:user) { User.create!(email: "match-del@test.it", name: "Del", password: "Password123", role: "coach") }
let!(:club) { Club.create!(name: "Del Club", sport: "pallavolo", primary_color: "#e53935", secondary_color: "#ffffff") }
let!(:team) { club.teams.create!(name: "U14", sport: "pallavolo") }
let!(:match) { team.matches.create!(opponent_name: "Rival", sport: "pallavolo") }
let!(:session) do
StreamSession.create!(match: match, user: user, platform: "matchlivetv", status: "ended", ended_at: 1.hour.ago)
end
let!(:recording) do
Recording.create!(
stream_session: session,
team: team,
status: "ready",
storage_backend: "local",
storage_policy: "retained",
privacy_status: "unlisted"
)
end
before do
ClubMembership.create!(user: user, club: club, role: "owner")
UserTeam.create!(user: user, team: team, role: "member", staff_kind: "transmission")
post public_login_path, params: { email: user.email, password: "Password123" }
end
it "cancella la partita anche se esiste un recording collegato alla sessione" do
expect do
delete public_team_match_path(team, match)
end.to change(Match, :count).by(-1)
.and change(StreamSession, :count).by(-1)
.and change(Recording, :count).by(-1)
expect(response).to redirect_to(public_team_matches_path(team))
end
end