Don't complain if asset view score is undefined

Closes CNVS-10914

TEST PLAN
---- ----

I'm really not sure how to reproduce it. We need a student to have
accessed a quiz (viewed it) but the view score to also be nil and not 1
(or 0), then try to view the access report for that student.

Anyway, it's just a guard against nil-values, so the spec should be
sufficient.

Change-Id: Id1fbcb3a36745fb289be73f76c78f1d52656a3b7
This commit is contained in:
Ahmad Amireh 2014-02-05 07:32:22 +03:00 committed by Cody Cutrer
parent 69d88c8288
commit 49b7d3e049
2 changed files with 16 additions and 10 deletions

View File

@ -185,10 +185,11 @@ class AssetUserAccess < ActiveRecord::Base
def corrected_view_score
deductible_points = 0
if %w[ quizzes ].include?(self.asset_group_code || '')
if 'quizzes' == self.asset_group_code
deductible_points = self.participate_score || 0
end
self.view_score ||= 0
self.view_score -= deductible_points
end

View File

@ -172,22 +172,27 @@ describe AssetUserAccess do
end
describe '#corrected_view_score' do
let(:access) { AssetUserAccess.new }
it 'should deduct the participation score from the view score for a quiz' do
access.stubs(:view_score).returns(10)
access.stubs(:participate_score).returns(4)
access.stubs(:asset_group_code).returns('quizzes')
subject.view_score = 10
subject.participate_score = 4
subject.asset_group_code = 'quizzes'
access.corrected_view_score.should == 6
subject.corrected_view_score.should == 6
end
it 'should return the normal view score for anything but a quiz' do
access.stubs(:view_score).returns(10)
access.stubs(:participate_score).returns(4)
subject.view_score = 10
subject.participate_score = 4
access.corrected_view_score.should == 10
subject.corrected_view_score.should == 10
end
it 'should not complain if there is no current score' do
subject.view_score = nil
subject.participate_score = 4
subject.stubs(:asset_group_code).returns('quizzes')
subject.corrected_view_score.should == -4
end
end
end