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

Project Copier: tweaks to initialization #4270

merged 8 commits into from
Mar 12, 2024

Conversation

lcjohnso
Copy link
Member

@lcjohnso lcjohnso commented Dec 6, 2023

Add additional fields to EXCLUDE_ATTRIBUTES so that they are not carried over to newly-copied project from original project.

lib/project_copier.rb Show resolved Hide resolved
@Tooyosi Tooyosi marked this pull request as ready for review March 11, 2024 15:29
@Tooyosi Tooyosi requested a review from yuenmichelle1 March 11, 2024 15:29
Copy link
Collaborator

@yuenmichelle1 yuenmichelle1 left a comment

Choose a reason for hiding this comment

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

Hey Toyosi!

I like your idea of checking that the new copied projects have excluded attributes as whatever the defaults are, but I think the original project also had these attributes as defaults. (View factory here to see what attributes were set for the original project).
Because of that, I don't think we are truly testing that these attributes are actually not being copied over.

I think a better test would be to set the excluded attributes of the original project and then check that the copied project's excluded attributes does not equal that of the original project. (Then we don't have to add the secondary test about launched_row_order and beta_row_order)

Maybe something like:

it 'does not copy over excluded attributes' do
  project_with_excluded_keys = create(:full_project, classifications_count: 3, classifiers_count: 2, launch_date: Date.yesterday, completeness: 0.5, activity: 1, lock_version: 8)

   other_copied_project = described_class.new(project_with_excluded_keys.id, copyist.id).copy

    ProjectCopier::EXCLUDE_ATTRIBUTES.each do |attr|
        expect(other_copied_project[attr]).not_to eq(project_with_excluded_keys[attr])
    end
end



Side note:
If you did want to check that the new copied project has defaults set in addition to above test, I would suggest using a hash as opposed to a default_values array so we don't have to use an index to keep track of what attribute we're comparing.

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 )

@Tooyosi
Copy link
Contributor

Tooyosi commented Mar 12, 2024

Hey Toyosi!

I like your idea of checking that the new copied projects have excluded attributes as whatever the defaults are, but I think the original project also had these attributes as defaults. (View factory here to see what attributes were set for the original project). Because of that, I don't think we are truly testing that these attributes are actually not being copied over.

I think a better test would be to set the excluded attributes of the original project and then check that the copied project's excluded attributes does not equal that of the original project. (Then we don't have to add the secondary test about launched_row_order and beta_row_order)

Maybe something like:

it 'does not copy over excluded attributes' do
  project_with_excluded_keys = create(:full_project, classifications_count: 3, classifiers_count: 2, launch_date: Date.yesterday, completeness: 0.5, activity: 1, lock_version: 8)

   other_copied_project = described_class.new(project_with_excluded_keys.id, copyist.id).copy

    ProjectCopier::EXCLUDE_ATTRIBUTES.each do |attr|
        expect(other_copied_project[attr]).not_to eq(project_with_excluded_keys[attr])
    end
end

Side note: If you did want to check that the new copied project has defaults set in addition to above test, I would suggest using a hash as opposed to a default_values array so we don't have to use an index to keep track of what attribute we're comparing.

Thanks, this makes alot of sense. I initially thought to compare the attributes between both projects but felt to compare with the defaults. But this works well especially with the launched_row_order and beta_row_order indexes

@yuenmichelle1
Copy link
Collaborator

Thanks, this makes alot of sense. I initially thought to compare the attributes between both projects but felt to compare with the defaults. But this works well especially with the launched_row_order and beta_row_order indexes

Awesome! Glad it made sense :) @Tooyosi Whenever you are ready, feel free to re-request my review and I'll take a look at it.

@Tooyosi Tooyosi requested a review from yuenmichelle1 March 12, 2024 15:45
Copy link
Collaborator

@yuenmichelle1 yuenmichelle1 left a comment

Choose a reason for hiding this comment

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

LGTM 🎉 👍

@Tooyosi Tooyosi merged commit 23605b0 into master Mar 12, 2024
8 checks passed
@Tooyosi Tooyosi deleted the proj-cp-initialize branch March 12, 2024 18:18
@Tooyosi Tooyosi restored the proj-cp-initialize branch March 27, 2024 04:38
@Tooyosi Tooyosi deleted the proj-cp-initialize branch March 27, 2024 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants