Merge pull request #5742 from consuldemocracy/legislation-proposals-videos

Fix crash in legislation proposals with videos
This commit is contained in:
Javi Martín
2024-10-15 10:34:29 +02:00
committed by GitHub
3 changed files with 43 additions and 0 deletions

View File

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

View File

@@ -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 }

View File

@@ -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