From b45155d376f38698dfeb720f437241555434843f Mon Sep 17 00:00:00 2001 From: tooyosi Date: Mon, 29 Jul 2024 21:02:04 +0100 Subject: [PATCH 1/4] [issue-4364] add attached_images association to workflow copier --- lib/workflow_copier.rb | 6 +++++- spec/lib/workflow_copier_spec.rb | 5 +++++ 2 files changed, 10 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..4e0e3fa58 100644 --- a/spec/lib/workflow_copier_spec.rb +++ b/spec/lib/workflow_copier_spec.rb @@ -6,6 +6,7 @@ let(:workflow) do create(:workflow, classifications_count: 100, retired_set_member_subjects_count: 10, real_set_member_subjects_count: 10, finished_at: Time.now.utc, completeness: 100.0, &:publish!) end + let(:media) { create(:medium, type: 'workflow_attached_image', linked: workflow) } let(:target_project) { create(:project) } let(:copier) { target_project.user } let(:copied_workflow) { described_class.copy(workflow, target_project.id) } @@ -38,6 +39,10 @@ end end + it 'copies the attached_images' do + expect(copied_workflow.attached_images).to eq(workflow.attached_images) + end + it 'sets the workflow to inactive to avoid releasing these on live projects' do expect(copied_workflow.active).to be(false) end From 3bba8583e6a1cbb00bc8d6c32f8560d973df1cc5 Mon Sep 17 00:00:00 2001 From: tooyosi Date: Thu, 1 Aug 2024 17:08:08 +0100 Subject: [PATCH 2/4] [issue-4364] move meda creation into attached_images test case --- spec/lib/workflow_copier_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/lib/workflow_copier_spec.rb b/spec/lib/workflow_copier_spec.rb index 4e0e3fa58..f1a1c53d2 100644 --- a/spec/lib/workflow_copier_spec.rb +++ b/spec/lib/workflow_copier_spec.rb @@ -6,7 +6,6 @@ let(:workflow) do create(:workflow, classifications_count: 100, retired_set_member_subjects_count: 10, real_set_member_subjects_count: 10, finished_at: Time.now.utc, completeness: 100.0, &:publish!) end - let(:media) { create(:medium, type: 'workflow_attached_image', linked: workflow) } let(:target_project) { create(:project) } let(:copier) { target_project.user } let(:copied_workflow) { described_class.copy(workflow, target_project.id) } @@ -39,8 +38,9 @@ end end - it 'copies the attached_images' do - expect(copied_workflow.attached_images).to eq(workflow.attached_images) + it 'copies the attached_images', focus: true do + create(:medium, type: 'workflow_attached_image', linked: workflow) + expect(copied_workflow.attached_images.count).to eq(workflow.attached_images.count) end it 'sets the workflow to inactive to avoid releasing these on live projects' do From a78d803fc6b24839c207549049e8d588066fab23 Mon Sep 17 00:00:00 2001 From: tooyosi Date: Thu, 1 Aug 2024 17:08:58 +0100 Subject: [PATCH 3/4] [issue-4364] move media creation into attached_images test case - remove focused test --- spec/lib/workflow_copier_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/workflow_copier_spec.rb b/spec/lib/workflow_copier_spec.rb index f1a1c53d2..4b07135b8 100644 --- a/spec/lib/workflow_copier_spec.rb +++ b/spec/lib/workflow_copier_spec.rb @@ -38,7 +38,7 @@ end end - it 'copies the attached_images', focus: true do + 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) end From 158c815fb293a94a36b4320bd07348269cf9867e Mon Sep 17 00:00:00 2001 From: tooyosi Date: Thu, 1 Aug 2024 17:44:42 +0100 Subject: [PATCH 4/4] [issue-4364] validate attached image on copied workflow --- spec/lib/workflow_copier_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/lib/workflow_copier_spec.rb b/spec/lib/workflow_copier_spec.rb index 4b07135b8..76b38e082 100644 --- a/spec/lib/workflow_copier_spec.rb +++ b/spec/lib/workflow_copier_spec.rb @@ -41,6 +41,7 @@ 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