Skip to content

Commit

Permalink
Copy all media when project remixed (#483)
Browse files Browse the repository at this point in the history
## Status

closes
RaspberryPiFoundation/digital-editor-issues#386

## What's changed?

- Remixes copy audio and video files as well as images
  • Loading branch information
loiswells97 authored Jan 30, 2025
1 parent 4800547 commit 14f2f03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/concepts/project/operations/create_remix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def create_remix(original_project, params, user_id, remix_origin)
remix.images.attach(image.blob)
end

original_project.videos.each do |video|
remix.videos.attach(video.blob)
end

original_project.audio.each do |audio_file|
remix.audio.attach(audio_file.blob)
end

params[:components].each do |x|
remix.components.build(x.slice(:name, :extension, :content))
end
Expand Down
18 changes: 14 additions & 4 deletions spec/concepts/project/create_remix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

let(:remix_origin) { 'editor.com' }
let(:user_id) { 'e0675b6c-dc48-4cd6-8c04-0f7ac05af51a' }
let!(:original_project) { create(:project, :with_components, :with_attached_image) }
let!(:original_project) { create(:project, :with_components, :with_attached_image, :with_attached_video, :with_attached_audio) }
let(:remix_params) do
component = original_project.components.first
{
Expand Down Expand Up @@ -79,11 +79,21 @@
expect(remixed_project.images.length).to eq(original_project.images.length)
end

it 'creates a new attachment' do
expect { create_remix }.to change(ActiveStorage::Attachment, :count).by(1)
it 'links remix to attached videos' do
remixed_project = create_remix[:project]
expect(remixed_project.videos.length).to eq(original_project.videos.length)
end

it 'links remix to attached audio' do
remixed_project = create_remix[:project]
expect(remixed_project.audio.length).to eq(original_project.audio.length)
end

it 'creates new attachments' do
expect { create_remix }.to change(ActiveStorage::Attachment, :count).by(3)
end

it 'does not create a new image' do
it 'does not create new media' do
expect { create_remix }.not_to change(ActiveStorage::Blob, :count)
end

Expand Down

0 comments on commit 14f2f03

Please sign in to comment.