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
39 changes: 0 additions & 39 deletions bin/curriculum/copy_level_concept_difficulties_between_years.rb

This file was deleted.

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

# Copy the level_concept_difficulty of the parent level to the new level
update_params[:level_concept_difficulty] = level_concept_difficulty.dup

level.update!(update_params)

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