Skip to content

Commit

Permalink
Merge pull request #40751 from code-dot-org/copy-level-with-lcd
Browse files Browse the repository at this point in the history
When clone_with_suffix for level copy the level_concept_difficulty too
  • Loading branch information
dmcavoy committed May 27, 2021
2 parents eca8322 + cad9269 commit 829b035
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 39 deletions.
39 changes: 0 additions & 39 deletions bin/curriculum/copy_level_concept_difficulties_between_years.rb

This file was deleted.

6 changes: 6 additions & 0 deletions dashboard/app/models/levels/level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,12 @@ def clone_with_suffix(new_suffix, editor_experiment: nil)
end

level.update!(update_params)

# Copy the level_concept_difficulty of the parent level to the new level
new_lcd = level_concept_difficulty.dup
level.level_concept_difficulty = new_lcd
level.save! if level.changed?

level
end

Expand Down
17 changes: 17 additions & 0 deletions dashboard/test/models/level_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,23 @@ def create_maze
assert_equal contained_level_2_copy, level_2_copy.contained_levels.last
end

test 'clone with suffix copies level concept difficulty' do
level_1 = create :level, name: 'level 1'
level_1.assign_attributes(
'level_concept_difficulty' => {'sequencing' => 3, 'debugging' => 5}
)

refute_nil level_1.level_concept_difficulty
assert_equal 3, level_1.level_concept_difficulty.sequencing
assert_equal 5, level_1.level_concept_difficulty.debugging

level_1_copy = level_1.clone_with_suffix(' copy')

refute_nil level_1_copy.level_concept_difficulty
assert_equal 3, level_1_copy.level_concept_difficulty.sequencing
assert_equal 5, level_1_copy.level_concept_difficulty.debugging
end

test 'clone with suffix sets editor experiment' do
old_level = create :level, name: 'old level'
new_level = old_level.clone_with_suffix(' copy', editor_experiment: 'level-editors')
Expand Down

0 comments on commit 829b035

Please sign in to comment.