Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue-4364] add attached_images association to workflow copier #4369

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
yuenmichelle1 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading