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

Prevent lesson editor from adding the same level to a script twice #39060

Merged
merged 6 commits into from Feb 19, 2021

Conversation

davidsbailey
Copy link
Member

@davidsbailey davidsbailey commented Feb 16, 2021

Finishes PLAT-612.

It's hard to anticipate whether a level is already in the script or not before updating the lesson, so we use the existing database transaction to check that there are no duplicates after the lesson has been updated, but before the transaction is committed.

Testing story

New unit test verifies that the error case is hit on the server. I also manually verified that the error is visible to the user when adding a duplicate level via the UI:
Screen Shot 2021-02-14 at 6 33 07 AM

Reviewer Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@@ -779,10 +751,36 @@ class LessonsControllerTest < ActionController::TestCase
script_level = section.script_levels.first
assert script_level.assessment
refute script_level.bonus
assert_equal 'progression name', script_level.progression
Copy link
Contributor

@dmcavoy dmcavoy Feb 17, 2021

Choose a reason for hiding this comment

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

Why are you removing this?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch... I've added this back.

Copy link
Contributor

@dmcavoy dmcavoy left a comment

Choose a reason for hiding this comment

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

Looks good! I like how you improved the test while you were there. One question since I think we still use progression.

Comment on lines 121 to 122
h = {}
levels.map(&:key).each {|key| h[key] = (h[key] || 0) + 1}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could use group_by to simplify this logic slightly, like duplicate_keys = levels.map(&:key).group_by {|key| key}.select {|_key, values| values.count > 1}.keys

But I don't think it makes much of a difference so up to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

💡 ! I have looked up how to do "count by" in ruby many times and never thought to use group_by. Thanks for this!

Copy link
Member Author

@davidsbailey davidsbailey left a comment

Choose a reason for hiding this comment

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

Thank you both for the careful review!

@@ -779,10 +751,36 @@ class LessonsControllerTest < ActionController::TestCase
script_level = section.script_levels.first
assert script_level.assessment
refute script_level.bonus
assert_equal 'progression name', script_level.progression
Copy link
Member Author

Choose a reason for hiding this comment

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

good catch... I've added this back.

Comment on lines 121 to 122
h = {}
levels.map(&:key).each {|key| h[key] = (h[key] || 0) + 1}
Copy link
Member Author

Choose a reason for hiding this comment

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

💡 ! I have looked up how to do "count by" in ruby many times and never thought to use group_by. Thanks for this!

@davidsbailey davidsbailey merged commit 54d5e62 into staging Feb 19, 2021
@davidsbailey davidsbailey deleted the no-duplicate-levels branch February 19, 2021 01:40
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

3 participants