Skip to content

Commit

Permalink
[issue-4364] add attached_images association to workflow copier (#4369)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
Tooyosi authored Aug 1, 2024
1 parent c01f49b commit d27bc29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/workflow_copier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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})"
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/workflow_copier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d27bc29

Please sign in to comment.