Skip to content

Commit

Permalink
test(rubric-criterion-denominator): level scaling on update
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavrao145 committed Nov 28, 2024
1 parent 383ebba commit ad5c103
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion spec/controllers/criteria_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit ad5c103

Please sign in to comment.