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 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
13 changes: 9 additions & 4 deletions lib/project_copier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] }
zwolf marked this conversation as resolved.
Show resolved Hide resolved
].freeze

def initialize(project_id, user_id)
Expand All @@ -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
Expand All @@ -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
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
Loading