handle missing assignment date values for variable subs

fixes PLAT-1272

test plan:

use the $Canvas.assignment.(dueAt|lockAt|unlockAt).iso8601 
varaible expansions

set up an assignment with blank values for all the dates

you should not get a 500 on an lti launch for the assignment

Change-Id: I7e4ffab74ea8b2aef6ba921c372ada9260805da0
Reviewed-on: https://gerrit.instructure.com/65354
Tested-by: Jenkins
Reviewed-by: Brad Horrocks <bhorrocks@instructure.com>
QA-Review: August Thornton <august@instructure.com>
Product-Review: Nathan Mills <nathanm@instructure.com>
This commit is contained in:
Nathan Mills 2015-10-19 11:05:17 -06:00
parent a8926f93cf
commit f4a2787ec1
2 changed files with 45 additions and 21 deletions

View File

@ -306,15 +306,15 @@ module Lti
register_expansion 'Canvas.assignment.unlockAt.iso8601', [],
-> { @assignment.unlock_at.utc.iso8601 },
ASSIGNMENT_GUARD
-> {@assignment && @assignment.unlock_at.present?}
register_expansion 'Canvas.assignment.lockAt.iso8601', [],
-> { @assignment.lock_at.utc.iso8601 },
ASSIGNMENT_GUARD
-> {@assignment && @assignment.lock_at.present?}
register_expansion 'Canvas.assignment.dueAt.iso8601', [],
-> { @assignment.due_at.utc.iso8601 },
ASSIGNMENT_GUARD
-> {@assignment && @assignment.due_at.present?}
register_expansion 'LtiLink.custom.url', [],
-> { @controller.show_lti_tool_settings_url(@tool_setting_link_id) },

View File

@ -380,27 +380,51 @@ module Lti
subject.expand_variables!(exp_hash)
expect(exp_hash[:test]).to eq right_now.to_s
end
context 'iso8601' do
it 'has substitution for $Canvas.assignment.unlockAt.iso8601' do
assignment.stubs(:unlock_at).returns(right_now)
exp_hash = {test: '$Canvas.assignment.unlockAt.iso8601'}
subject.expand_variables!(exp_hash)
expect(exp_hash[:test]).to eq right_now.utc.iso8601.to_s
end
it 'has substitution for $Canvas.assignment.lockAt.iso8601' do
assignment.stubs(:lock_at).returns(right_now)
exp_hash = {test: '$Canvas.assignment.lockAt.iso8601'}
subject.expand_variables!(exp_hash)
expect(exp_hash[:test]).to eq right_now.utc.iso8601.to_s
end
it 'has substitution for $Canvas.assignment.dueAt.iso8601' do
assignment.stubs(:due_at).returns(right_now)
exp_hash = {test: '$Canvas.assignment.dueAt.iso8601'}
subject.expand_variables!(exp_hash)
expect(exp_hash[:test]).to eq right_now.utc.iso8601.to_s
end
it 'handles a nil unlock_at' do
assignment.stubs(:unlock_at).returns(nil)
exp_hash = {test: '$Canvas.assignment.unlockAt.iso8601'}
subject.expand_variables!(exp_hash)
expect(exp_hash[:test]).to eq "$Canvas.assignment.unlockAt.iso8601"
end
it 'handles a nil lock_at' do
assignment.stubs(:lock_at).returns(nil)
exp_hash = {test: '$Canvas.assignment.lockAt.iso8601'}
subject.expand_variables!(exp_hash)
expect(exp_hash[:test]).to eq "$Canvas.assignment.lockAt.iso8601"
end
it 'handles a nil due_at' do
assignment.stubs(:lock_at).returns(nil)
exp_hash = {test: '$Canvas.assignment.dueAt.iso8601'}
subject.expand_variables!(exp_hash)
expect(exp_hash[:test]).to eq "$Canvas.assignment.dueAt.iso8601"
end
it 'has substitution for $Canvas.assignment.unlockAt.iso8601' do
assignment.stubs(:unlock_at).returns(right_now)
exp_hash = {test: '$Canvas.assignment.unlockAt.iso8601'}
subject.expand_variables!(exp_hash)
expect(exp_hash[:test]).to eq right_now.utc.iso8601.to_s
end
it 'has substitution for $Canvas.assignment.lockAt.iso8601' do
assignment.stubs(:lock_at).returns(right_now)
exp_hash = {test: '$Canvas.assignment.lockAt.iso8601'}
subject.expand_variables!(exp_hash)
expect(exp_hash[:test]).to eq right_now.utc.iso8601.to_s
end
it 'has substitution for $Canvas.assignment.dueAt.iso8601' do
assignment.stubs(:due_at).returns(right_now)
exp_hash = {test: '$Canvas.assignment.dueAt.iso8601'}
subject.expand_variables!(exp_hash)
expect(exp_hash[:test]).to eq right_now.utc.iso8601.to_s
end
end