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 Copier: tweaks to initialization #4270

Merged
merged 8 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
12 changes: 11 additions & 1 deletion lib/project_copier.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
class ProjectCopier
attr_reader :project_to_copy, :user

EXCLUDE_ATTRIBUTES = %i[classifications_count launched_row_order beta_row_order].freeze
EXCLUDE_ATTRIBUTES = %i[
classifications_count
classifiers_count
launch_date
completeness
activity
lock_version
launched_row_order
beta_row_order
].freeze

lcjohnso marked this conversation as resolved.
Show resolved Hide resolved
INCLUDE_ASSOCIATIONS = [
:tutorials,
:pages,
Expand Down
17 changes: 17 additions & 0 deletions spec/lib/project_copier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@
expect(copied_project.configuration['source_project_id']).to be(project.id)
end

it 'sets the value of each excluded attribute to their default' do
# N.B, to be updated once ProjectCopier::EXCLUDE_ATTRIBUTES values are updated aswell
default_values = [0, 0, nil, 0.0, 0, 0]
# excluding launched_row_order and beta_row_order as they are primary keys and don't have a fixed default value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but I dont think launched_row_order and beta_row_order are primary keys.

I think for projects the only primary key is id. BUT I do think launched_row_order and beta_row_order are indexes of project. (See: here and here )

excluded_attributes = ProjectCopier::EXCLUDE_ATTRIBUTES.reject { |attr| [:launched_row_order, :beta_row_order].include?(attr) }
excluded_attributes.each_with_index do |key, i|
expect(copied_project[key]).to be(default_values[i])
end
end

it 'checks the type of excluded primary keys' do
ranked_attributes = %i[launched_row_order beta_row_order]
ranked_attributes.each do |value|
expect(copied_project[value]).to be_kind_of(Integer)
end
end

it 'creates Talk roles for the new project and its owner' do
allow(TalkAdminCreateWorker).to receive(:perform_async)
copied_project
Expand Down
Loading