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