diff --git a/spec/controllers/criteria_controller_spec.rb b/spec/controllers/criteria_controller_spec.rb index 1c4ffa38a4..5b198da53f 100644 --- a/spec/controllers/criteria_controller_spec.rb +++ b/spec/controllers/criteria_controller_spec.rb @@ -629,11 +629,15 @@ end context 'without errors' do + let(:custom_rubric_criterion) { nil } + before do get_as instructor, :update, params: { course_id: course.id, id: rubric_criterion.id, - rubric_criterion: { name: 'one', max_mark: 10 } }, + rubric_criterion: custom_rubric_criterion || { + name: 'one', max_mark: rubric_criterion.max_mark * 2 + } }, format: :js end @@ -644,6 +648,39 @@ it 'should render the update template' do expect(subject).to render_template(:update) end + + context 'when levels_attributes is provided' do + let(:custom_rubric_criterion) do + levels_attributes = rubric_criterion.levels.map do |level| + { id: level.id, name: level.name, description: level.description, mark: level.mark / 2.0 } + end + { name: 'one', max_mark: rubric_criterion.max_mark * 2, + levels_attributes: levels_attributes.map.with_index do |value, index| + [index, value] + end.to_h } + end + + it 'should scale the marks in levels_attributes instead of in the original levels' do + original_level_marks = rubric_criterion.levels.map(&:mark) + + rubric_criterion.reload + + updated_level_marks = rubric_criterion.levels.map(&:mark) + + # we divided all marks by 2 and then multipled with 2 again + expect(updated_level_marks).to eq(original_level_marks) + end + end + + it "should scale the criterion's level marks accordingly" do + original_level_marks = rubric_criterion.levels.map(&:mark) + + rubric_criterion.reload + + updated_level_marks = rubric_criterion.levels.map(&:mark) + + expect(updated_level_marks).to eq(original_level_marks.map { |mark| mark * 2.0 }) + end end end end