Skip to content

Commit d06cf7b

Browse files
committed
Round pointsPossible variable substitution if a whole number
Fixes PLAT-1498 Test Plan: With the test tool, create a new assignment with 100 points possible. The value posted to the tool for the points_possible variable expansion should be "100" not "100.0". A assignment with 100.5 points possible should post as "100.5". Change-Id: I5eaf29817a7a71626f1407cda4c75a3853c816d3 Reviewed-on: https://gerrit.instructure.com/79297 Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Reviewed-by: Brad Humphrey <brad@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Karl Lloyd <karl@instructure.com>
1 parent f263d05 commit d06cf7b

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

lib/lti/variable_expander.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def expand_variables!(var_hash)
401401
ASSIGNMENT_GUARD
402402

403403
register_expansion 'Canvas.assignment.pointsPossible', [],
404-
-> { @assignment.points_possible },
404+
-> { TextHelper.round_if_whole(@assignment.points_possible) },
405405
ASSIGNMENT_GUARD
406406
# @deprecated in favor of ISO8601
407407
register_expansion 'Canvas.assignment.unlockAt', [],

spec/lib/lti/variable_expander_spec.rb

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,27 @@ module Lti
376376
expect(exp_hash[:test]).to eq 'Buy as many ducks as you can'
377377
end
378378

379-
it 'has substitution for $Canvas.assignment.pointsPossible' do
380-
assignment.stubs(:points_possible).returns(10)
381-
exp_hash = {test: '$Canvas.assignment.pointsPossible'}
382-
subject.expand_variables!(exp_hash)
383-
expect(exp_hash[:test]).to eq 10
379+
describe "$Canvas.assignment.pointsPossible" do
380+
it 'has substitution for $Canvas.assignment.pointsPossible' do
381+
assignment.stubs(:points_possible).returns(10.0)
382+
exp_hash = {test: '$Canvas.assignment.pointsPossible'}
383+
subject.expand_variables!(exp_hash)
384+
expect(exp_hash[:test]).to eq 10
385+
end
386+
387+
it 'does not round if not whole' do
388+
assignment.stubs(:points_possible).returns(9.5)
389+
exp_hash = {test: '$Canvas.assignment.pointsPossible'}
390+
subject.expand_variables!(exp_hash)
391+
expect(exp_hash[:test].to_s).to eq "9.5"
392+
end
393+
394+
it 'rounds if whole' do
395+
assignment.stubs(:points_possible).returns(9.0)
396+
exp_hash = {test: '$Canvas.assignment.pointsPossible'}
397+
subject.expand_variables!(exp_hash)
398+
expect(exp_hash[:test].to_s).to eq "9"
399+
end
384400
end
385401

386402
it 'has substitution for $Canvas.assignment.unlockAt' do

spec/models/lti/lti_integration_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def tool_setup(for_student=true)
418418
expect(hash['ext_ims_lis_basic_outcome_url']).to eq "/my/other/test/url"
419419
expect(hash['ext_outcome_data_values_accepted']).to eq 'url,text'
420420
expect(hash['custom_canvas_assignment_title']).to eq @assignment.title
421-
expect(hash['custom_canvas_assignment_points_possible']).to eq @assignment.points_possible.to_s
421+
expect(hash['custom_canvas_assignment_points_possible']).to eq "5"
422422
expect(hash['custom_canvas_assignment_id']).to eq @assignment.id.to_s
423423
end
424424

@@ -429,7 +429,7 @@ def tool_setup(for_student=true)
429429
expect(hash['ext_ims_lis_basic_outcome_url']).to eq "/my/other/test/url"
430430
expect(hash['ext_outcome_data_values_accepted']).to eq 'url,text'
431431
expect(hash['custom_canvas_assignment_title']).to eq @assignment.title
432-
expect(hash['custom_canvas_assignment_points_possible']).to eq @assignment.points_possible.to_s
432+
expect(hash['custom_canvas_assignment_points_possible']).to eq "5"
433433
end
434434
end
435435

0 commit comments

Comments
 (0)