require "rails_helper" RSpec.describe Streams::CoverSlateEnsurer do let!(:club) { Club.create!(name: "Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") } let!(:team) { club.teams.create!(name: "Team", sport: "volleyball") } let!(:match) { team.matches.create!(opponent_name: "Opp", sport: "volleyball") } before do load Rails.root.join("db/seeds/plans.rb") Billing::AssignPlan.call(club: club, plan_slug: "premium_full") match.cover_image.attach( io: StringIO.new("img"), filename: "c.png", content_type: "image/png" ) end it "genera in sync se manca cover_slate" do expect(Streams::GenerateCoverSlate).to receive(:call).with(match).and_return(match) described_class.ensure_for!(match) end it "non rigenera se slate pronta su disco" do match.cover_slate.attach( io: StringIO.new("mp4"), filename: "s.mp4", content_type: "video/mp4" ) path = Streams::CoverSlatePaths.expected_path(match) FileUtils.mkdir_p(File.dirname(path)) File.write(path, "fake") expect(Streams::GenerateCoverSlate).not_to receive(:call) described_class.ensure_for!(match) ensure FileUtils.rm_f(path) if defined?(path) && path end end