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.
This commit is contained in:
taitus
2024-10-14 15:24:29 +02:00
parent 53688863cd
commit 93189d3ecd
3 changed files with 43 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ class Legislation::Proposal < ApplicationRecord
include Followable include Followable
include Communitable include Communitable
include Documentable include Documentable
include Videoable
include Notifiable include Notifiable
include Imageable include Imageable
include Randomizable include Randomizable

View File

@@ -27,6 +27,18 @@ describe Legislation::Proposal do
expect(proposal).not_to be_valid expect(proposal).not_to be_valid
end 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 describe "#hot_score" do
let(:now) { Time.current } let(:now) { Time.current }

View File

@@ -304,4 +304,34 @@ describe "Legislation Proposals" do
expect(page).not_to have_field("Scope of operation") expect(page).not_to have_field("Scope of operation")
end 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 end