From 93189d3ecdd05d33f42379943d3cc8fff3a439dc Mon Sep 17 00:00:00 2001 From: taitus Date: Mon, 14 Oct 2024 15:24:29 +0200 Subject: [PATCH] Allow use embedded_video_component in legislation proposals Since the PR "Do not use third-party cookies in embedded videos #5548", the logic from "embed_videos_helper" was extracted to the "embedded_video_component" and the "videoable" model concern. However, during this refactor, the "regex" method, which uses record.class:: to handle video embeds, was left inaccessible for Legislation Proposals. This commit fixes the issue by including the concern in the Legislation Proposal model. --- app/models/legislation/proposal.rb | 1 + spec/models/legislation/proposal_spec.rb | 12 +++++++++ spec/system/legislation/proposals_spec.rb | 30 +++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index d1765e503..63dc9221b 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -10,6 +10,7 @@ class Legislation::Proposal < ApplicationRecord include Followable include Communitable include Documentable + include Videoable include Notifiable include Imageable include Randomizable diff --git a/spec/models/legislation/proposal_spec.rb b/spec/models/legislation/proposal_spec.rb index ab8f4473d..9d533591f 100644 --- a/spec/models/legislation/proposal_spec.rb +++ b/spec/models/legislation/proposal_spec.rb @@ -27,6 +27,18 @@ describe Legislation::Proposal do expect(proposal).not_to be_valid end + describe "#video_url" do + it "is not valid when URL is not from Youtube or Vimeo" do + proposal.video_url = "https://twitter.com" + expect(proposal).not_to be_valid + end + + it "is valid when URL is from Youtube or Vimeo" do + proposal.video_url = "https://vimeo.com/112681885" + expect(proposal).to be_valid + end + end + describe "#hot_score" do let(:now) { Time.current } diff --git a/spec/system/legislation/proposals_spec.rb b/spec/system/legislation/proposals_spec.rb index afcbf7ef4..c71e4c322 100644 --- a/spec/system/legislation/proposals_spec.rb +++ b/spec/system/legislation/proposals_spec.rb @@ -304,4 +304,34 @@ describe "Legislation Proposals" do expect(page).not_to have_field("Scope of operation") end + + context "Embedded video" do + scenario "Show YouTube video" do + proposal = create(:legislation_proposal, video_url: "http://www.youtube.com/watch?v=a7UFm6ErMPU") + + visit legislation_process_proposal_path(proposal.process, proposal) + + within "#js-embedded-video" do + expect(page).to have_css "iframe[src='https://www.youtube-nocookie.com/embed/a7UFm6ErMPU']" + end + end + + scenario "Show Vimeo video" do + proposal = create(:legislation_proposal, video_url: "https://vimeo.com/7232823") + + visit legislation_process_proposal_path(proposal.process, proposal) + + within "#js-embedded-video" do + expect(page).to have_css "iframe[src='https://player.vimeo.com/video/7232823?dnt=1']" + end + end + + scenario "Dont show video" do + proposal = create(:legislation_proposal, video_url: nil) + + visit legislation_process_proposal_path(proposal.process, proposal) + + expect(page).not_to have_css "#js-embedded-video" + end + end end