From d27bc293709a26e1559ffb1b6da2d6b6fb2a0976 Mon Sep 17 00:00:00 2001 From: Oluwatoyosi Oyegoke <34948675+Tooyosi@users.noreply.github.com> Date: Thu, 1 Aug 2024 18:15:36 +0100 Subject: [PATCH] [issue-4364] add attached_images association to workflow copier (#4369) * [issue-4364] add attached_images association to workflow copier * [issue-4364] move meda creation into attached_images test case * [issue-4364] move media creation into attached_images test case - remove focused test * [issue-4364] validate attached image on copied workflow --- lib/workflow_copier.rb | 6 +++++- spec/lib/workflow_copier_spec.rb | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/workflow_copier.rb b/lib/workflow_copier.rb index 931326b79..7ab5d79bd 100644 --- a/lib/workflow_copier.rb +++ b/lib/workflow_copier.rb @@ -10,13 +10,17 @@ class WorkflowCopier finished_at ].freeze + INCLUDE_ASSOCIATIONS = [ + :attached_images + ].freeze + def self.copy_by_id(workflow_id, target_project_id) source_workflow = Workflow.find(workflow_id) copy(source_workflow, target_project_id) end def self.copy(source_workflow, target_project_id) - copied_workflow = source_workflow.deep_clone(except: EXCLUDE_ATTRIBUTES) + copied_workflow = source_workflow.deep_clone(except: EXCLUDE_ATTRIBUTES, include: INCLUDE_ASSOCIATIONS) copied_workflow.project_id = target_project_id copied_workflow.active = false copied_workflow.display_name = "#{copied_workflow.display_name} (copy: #{Time.now.utc})" diff --git a/spec/lib/workflow_copier_spec.rb b/spec/lib/workflow_copier_spec.rb index 8e52e765e..76b38e082 100644 --- a/spec/lib/workflow_copier_spec.rb +++ b/spec/lib/workflow_copier_spec.rb @@ -38,6 +38,12 @@ end end + it 'copies the attached_images' do + create(:medium, type: 'workflow_attached_image', linked: workflow) + expect(copied_workflow.attached_images.count).to eq(workflow.attached_images.count) + expect(copied_workflow.attached_images[0]).to be_valid + end + it 'sets the workflow to inactive to avoid releasing these on live projects' do expect(copied_workflow.active).to be(false) end