diff --git a/lib/project_copier.rb b/lib/project_copier.rb index 11c8f254a..a4bbc5ed0 100644 --- a/lib/project_copier.rb +++ b/lib/project_copier.rb @@ -4,13 +4,13 @@ class ProjectCopier EXCLUDE_ATTRIBUTES = %i[classifications_count launched_row_order beta_row_order].freeze INCLUDE_ASSOCIATIONS = [ :tutorials, - :field_guides, :pages, :tags, :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) @@ -22,7 +22,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 @@ -35,9 +35,14 @@ def copy # to keep the translations system working with these copied resources setup_associated_primary_language_translations(copied_project) - # 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 diff --git a/spec/lib/project_copier_spec.rb b/spec/lib/project_copier_spec.rb index 51e85d1c5..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 @@ -39,6 +41,14 @@ expect(copied_project.configuration['source_project_id']).to be(project.id) end + it 'creates Talk roles for the new project and its owner' do + allow(TalkAdminCreateWorker).to receive(:perform_async) + copied_project + expect(TalkAdminCreateWorker) + .to have_received(:perform_async) + .with(be_kind_of(Integer)) + 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 @@ -84,6 +94,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