diff --git a/backend/app/models/stream_session.rb b/backend/app/models/stream_session.rb index b0a638e..67187e7 100644 --- a/backend/app/models/stream_session.rb +++ b/backend/app/models/stream_session.rb @@ -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 } diff --git a/backend/spec/requests/public/match_destroy_spec.rb b/backend/spec/requests/public/match_destroy_spec.rb new file mode 100644 index 0000000..a27576a --- /dev/null +++ b/backend/spec/requests/public/match_destroy_spec.rb @@ -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