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

Project copying fixes: Talk roles and field guide images #4258

Merged
merged 5 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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/project_copier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] }
zwolf marked this conversation as resolved.
Show resolved Hide resolved
].freeze

def initialize(project_id, user_id)
Expand All @@ -35,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)
yuenmichelle1 marked this conversation as resolved.
Show resolved Hide resolved

# return the newly copied project
copied_project
end
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/project_copier_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

describe ProjectCopier do
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down