From 30b8a2982cbecb59bb178e19ea78b9a817978551 Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Wed, 18 Oct 2023 12:45:13 -0500 Subject: [PATCH 1/5] Copy field guide images via project copier --- lib/project_copier.rb | 3 ++- spec/lib/project_copier_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/project_copier.rb b/lib/project_copier.rb index 11c8f254a..621280347 100644 --- a/lib/project_copier.rb +++ b/lib/project_copier.rb @@ -10,7 +10,8 @@ class ProjectCopier :tagged_resources, :avatar, :background, - { active_workflows: %i[tutorials attached_images] } + { active_workflows: %i[tutorials attached_images] }, + { field_guides: %i[attached_images] } ].freeze def initialize(project_id, user_id) diff --git a/spec/lib/project_copier_spec.rb b/spec/lib/project_copier_spec.rb index 51e85d1c5..a4853fc90 100644 --- a/spec/lib/project_copier_spec.rb +++ b/spec/lib/project_copier_spec.rb @@ -84,6 +84,12 @@ field_guide = copied_project.field_guides.first expect(field_guide.translations.first.language).to eq(project.primary_language) end + + it 'copies the field guide attached images' do + fg = create(:field_guide, project: project) + fg.attached_images << create(:medium, type: "field_guide_attached_image", linked: fg) + expect(copied_project.field_guides.first.attached_images[0]).to be_valid + end end context 'when a project has a project page' do From 2db3c35032bce79451670e4bc1307fd73018b26b Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Wed, 18 Oct 2023 13:03:10 -0500 Subject: [PATCH 2/5] Create Talk admin roles for copied projects --- lib/project_copier.rb | 3 +++ spec/lib/project_copier_spec.rb | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/project_copier.rb b/lib/project_copier.rb index 621280347..6557774a9 100644 --- a/lib/project_copier.rb +++ b/lib/project_copier.rb @@ -36,6 +36,9 @@ def copy # to keep the translations system working with these copied resources setup_associated_primary_language_translations(copied_project) + # Creates Talk roles via background worker + TalkAdminCreateWorker.perform_async(copied_project.id) + # return the newly copied project copied_project end diff --git a/spec/lib/project_copier_spec.rb b/spec/lib/project_copier_spec.rb index a4853fc90..4c8805808 100644 --- a/spec/lib/project_copier_spec.rb +++ b/spec/lib/project_copier_spec.rb @@ -39,6 +39,13 @@ expect(copied_project.configuration['source_project_id']).to be(project.id) end + it 'creates Talk roles for the new project and its owner' do + expect(TalkAdminCreateWorker) + .to receive(:perform_async) + .with(be_kind_of(Integer)) + copied_project + end + context 'when a project has active_worklfows' do it 'creates a valid workflow copy' do expect(copied_project.active_workflows.first).to be_valid From 90f8a6e7113d293b363ccbc4e1c754cc2c0d2224 Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Wed, 18 Oct 2023 13:12:23 -0500 Subject: [PATCH 3/5] Hound's right --- spec/lib/project_copier_spec.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/lib/project_copier_spec.rb b/spec/lib/project_copier_spec.rb index 4c8805808..4a01ceaf2 100644 --- a/spec/lib/project_copier_spec.rb +++ b/spec/lib/project_copier_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectCopier do @@ -40,10 +42,11 @@ end it 'creates Talk roles for the new project and its owner' do + allow(TalkAdminCreateWorker).to receive(:perform_async) + copied_project expect(TalkAdminCreateWorker) - .to receive(:perform_async) + .to have_received(:perform_async) .with(be_kind_of(Integer)) - copied_project end context 'when a project has active_worklfows' do @@ -94,7 +97,7 @@ it 'copies the field guide attached images' do fg = create(:field_guide, project: project) - fg.attached_images << create(:medium, type: "field_guide_attached_image", linked: fg) + fg.attached_images << create(:medium, type: 'field_guide_attached_image', linked: fg) expect(copied_project.field_guides.first.attached_images[0]).to be_valid end end From 3cbae6cca4c66d09203acd35b5acc3bff9ae74e4 Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Wed, 18 Oct 2023 15:09:41 -0500 Subject: [PATCH 4/5] Move worker call outside transaction --- lib/project_copier.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/project_copier.rb b/lib/project_copier.rb index 6557774a9..d6e377985 100644 --- a/lib/project_copier.rb +++ b/lib/project_copier.rb @@ -23,7 +23,7 @@ def copy # Should this all be wrapped in a transaction? # to ensure we rollback an sub resource creations, # e.g. inband primary lang strings for the associated resources.... - Project.transaction(requires_new: true) do + copied_project = Project.transaction(requires_new: true) do copied_project = copy_project # save the project and create the project versions for use in translation strings @@ -36,12 +36,14 @@ def copy # to keep the translations system working with these copied resources setup_associated_primary_language_translations(copied_project) - # Creates Talk roles via background worker - TalkAdminCreateWorker.perform_async(copied_project.id) - - # return the newly copied project copied_project end + + # Creates Talk roles via background worker + TalkAdminCreateWorker.perform_async(copied_project.id) + + # return the newly copied project + copied_project end private From 7d70b57593d9a028aa060c9468b8099d50440b9e Mon Sep 17 00:00:00 2001 From: Zach Wolfenbarger Date: Wed, 25 Oct 2023 11:57:43 -0500 Subject: [PATCH 5/5] Remove duplicate field_guide assoc --- lib/project_copier.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/project_copier.rb b/lib/project_copier.rb index d6e377985..a4bbc5ed0 100644 --- a/lib/project_copier.rb +++ b/lib/project_copier.rb @@ -4,7 +4,6 @@ class ProjectCopier EXCLUDE_ATTRIBUTES = %i[classifications_count launched_row_order beta_row_order].freeze INCLUDE_ASSOCIATIONS = [ :tutorials, - :field_guides, :pages, :tags, :tagged_resources,