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

When clone_with_suffix for level copy the level_concept_difficulty too #40751

Merged
merged 9 commits into from May 27, 2021

Conversation

dmcavoy
Copy link
Contributor

@dmcavoy dmcavoy commented May 25, 2021

When we clone_with_suffix on a level (which is what we use when we do a script copy) well will now also copy the level concept difficulty over. This will help with making sure that we don't lose level_concept_difficulty tagging between years of courses.

I also removed the one-off script we used to do this copy this year since we should no longer need it.

Links

https://codedotorg.atlassian.net/browse/PLAT-1075

Testing story

Added a test to make sure the level concept difficulty is copied to the new level

@dmcavoy dmcavoy changed the title Copy level with lcd When clone_with_suffix for level copy the level_concept_difficulty too May 26, 2021
@dmcavoy dmcavoy requested a review from a team May 26, 2021 18:30
Co-authored-by: Elijah Hamovitz <elijahhamovitz@gmail.com>
@dmcavoy dmcavoy requested a review from Hamms May 26, 2021 19:29
@dmcavoy
Copy link
Contributor Author

dmcavoy commented May 26, 2021

@Hamms I don't think your suggestion works because it looks like assign_attributes only works on properties. The test fails with error. I'm going to put it back to how it was

@Hamms
Copy link
Contributor

Hamms commented May 26, 2021

Oh, I think you need to use a string rather than a symbol. See

# Rails won't natively assign one-to-one association attributes for
# us, even though we've specified accepts_nested_attributes_for above.
# So, we must do it manually.
def assign_attributes(new_attributes)
attributes = new_attributes.stringify_keys
concept_difficulty_attributes = attributes.delete('level_concept_difficulty')
if concept_difficulty_attributes
assign_nested_attributes_for_one_to_one_association(
:level_concept_difficulty,
concept_difficulty_attributes
)
end
super(attributes)
end

@dmcavoy
Copy link
Contributor Author

dmcavoy commented May 27, 2021

That looks like it works for something written like this:

    level.assign_attributes(
      'level_concept_difficulty' => {'debugging' => 5}
    )

Which I think is harder to get to here. So I'm going to merge it as is.

@dmcavoy dmcavoy merged commit 829b035 into staging May 27, 2021
@dmcavoy dmcavoy deleted the copy-level-with-lcd branch May 27, 2021 00:58
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.

None yet

2 participants