canvas-lms/spec/models/asset_user_access_spec.rb

316 lines
9.1 KiB
Ruby
Raw Normal View History

#
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe AssetUserAccess do
before :once do
@course = Account.default.courses.create!(:name => 'My Course')
@assignment = @course.assignments.create!(:title => 'My Assignment')
@user = User.create!
@asset = factory_with_protected_attributes(AssetUserAccess, :user => @user, :context => @course, :asset_code => @assignment.asset_string)
@asset.display_name = @assignment.asset_string
@asset.save!
end
it "should update existing records that have bad display names" do
expect(@asset.display_name).to eq "My Assignment"
end
it "should update existing records that have changed display names" do
@assignment.title = 'My changed Assignment'
@assignment.save!
@asset = AssetUserAccess.find(@asset.id)
@asset.log @course, { :level => 'view' }
expect(@asset.display_name).to eq 'My changed Assignment'
end
it "should work for assessment questions" do
question = assessment_question_model(bank: AssessmentQuestionBank.create!(context: @course))
@asset.log question, { :level => 'view' }
expect(@asset.context).to eq @course
end
describe "for_user" do
it "should work with a User object" do
expect(AssetUserAccess.for_user(@user)).to eq [@asset]
end
it "should work with a list of User objects" do
expect(AssetUserAccess.for_user([@user])).to eq [@asset]
end
it "should work with a User id" do
expect(AssetUserAccess.for_user(@user.id)).to eq [@asset]
end
it "should work with a list of User ids" do
expect(AssetUserAccess.for_user([@user.id])).to eq [@asset]
end
it "should with with an empty list" do
expect(AssetUserAccess.for_user([])).to eq []
end
it "should not find unrelated accesses" do
expect(AssetUserAccess.for_user(User.create!)).to eq []
expect(AssetUserAccess.for_user(@user.id + 1)).to eq []
end
end
describe '#log_action' do
let(:scores) { Hash.new }
let(:asset) { AssetUserAccess.new(scores) }
subject { asset }
describe 'when action level is nil' do
describe 'with nil scores' do
describe 'view level' do
before { asset.log_action 'view' }
describe '#view_score' do
subject { super().view_score }
it { is_expected.to eq 1 }
end
describe '#participate_score' do
subject { super().participate_score }
it { is_expected.to be_nil }
end
describe '#action_level' do
subject { super().action_level }
it { is_expected.to eq 'view' }
end
end
describe 'participate level' do
before { asset.log_action 'participate' }
describe '#view_score' do
subject { super().view_score }
it { is_expected.to eq 1 }
end
describe '#participate_score' do
subject { super().participate_score }
it { is_expected.to eq 1 }
end
describe '#action_level' do
subject { super().action_level }
it { is_expected.to eq 'participate' }
end
end
describe 'submit level' do
before { asset.log_action 'submit' }
describe '#view_score' do
subject { super().view_score }
it { is_expected.to be_nil }
end
describe '#participate_score' do
subject { super().participate_score }
it { is_expected.to eq 1 }
end
describe '#action_level' do
subject { super().action_level }
it { is_expected.to eq 'participate' }
end
end
end
describe 'with existing scores' do
before { asset.view_score = asset.participate_score = 3 }
describe 'view level' do
before { asset.log_action 'view' }
describe '#view_score' do
subject { super().view_score }
it { is_expected.to eq 4 }
end
describe '#participate_score' do
subject { super().participate_score }
it { is_expected.to eq 3 }
end
describe '#action_level' do
subject { super().action_level }
it { is_expected.to eq 'view' }
end
end
describe 'participate level' do
before { asset.log_action 'participate' }
describe '#view_score' do
subject { super().view_score }
it { is_expected.to eq 4 }
end
describe '#participate_score' do
subject { super().participate_score }
it { is_expected.to eq 4 }
end
describe '#action_level' do
subject { super().action_level }
it { is_expected.to eq 'participate' }
end
end
describe 'submit level' do
before { asset.log_action 'submit' }
describe '#view_score' do
subject { super().view_score }
it { is_expected.to eq 3 }
end
describe '#participate_score' do
subject { super().participate_score }
it { is_expected.to eq 4 }
end
describe '#action_level' do
subject { super().action_level }
it { is_expected.to eq 'participate' }
end
end
end
end
describe 'when action level is view' do
before { asset.action_level = 'view' }
it 'gets overridden by participate' do
asset.log_action 'participate'
expect(asset.action_level).to eq 'participate'
end
it 'gets overridden by submit' do
asset.log_action 'submit'
expect(asset.action_level).to eq 'participate'
end
end
it 'does not overwrite the participate level with view' do
asset.action_level = 'participate'
asset.log_action 'view'
expect(asset.action_level).to eq 'participate'
end
end
describe '#log' do
let(:access) { AssetUserAccess.new }
let(:context) { User.new }
subject { access }
before { access.stubs :save }
describe 'attribute values directly from hash' do
def it_sets_if_nil( attribute, hash_key = nil)
hash_key ||= attribute
access.log(context, { hash_key => 'value' })
expect(access.send(attribute)).to eq 'value'
access.send("#{attribute}=", 'other')
access.log(context, { hash_key => 'value' })
expect(access.send(attribute)).to eq 'other'
end
specify { it_sets_if_nil( :asset_category, :category ) }
specify { it_sets_if_nil( :asset_group_code, :group_code ) }
specify { it_sets_if_nil( :membership_type ) }
end
describe 'interally set or calculated attribute values' do
before { access.log context, { :level => 'view' } }
describe '#context' do
subject { super().context }
it { is_expected.to eq context }
end
describe '#last_access' do
subject { super().last_access }
it { is_expected.not_to be_nil }
end
describe '#view_score' do
subject { super().view_score }
it { is_expected.to eq 1 }
end
describe '#participate_score' do
subject { super().participate_score }
it { is_expected.to be_nil }
end
describe '#action_level' do
subject { super().action_level }
it { is_expected.to eq 'view' }
end
end
end
More accurate Access Report scores for Quizzes This patch makes it that when viewing the Access Report for a course student, their "Times Viewed" column will reflect the number of times the student has browsed the quiz or any of its related resources (like History, or attempt views), but not taken it. While the "Times Participated" column will reflect the number of times the student really took the quiz (1:1 mapping with the number of submissions.) TEST PLAN ---- ---- In both test cases, you'll need: - a course with a student enrolled - one browser session with a teacher logged in viewing the Access Report of the student - one browser session with the student logged CASE: Normal quizzes - Create a quiz with a few questions and unlimited attempts. - Refresh the teacher tab, keep an eye on Times "Viewed" and "Participated" columns - As the student: - Go to the quizzes page - Go to the quiz page - Refresh the teacher tab, and: - ONLY the "Times Viewed" score should be incremented by 1 - As the student: - Push the Take the Quiz - Refresh the teacher tab, and: - ONLY the "Times Participated" score should be incremented by 1 - As the student: - Refresh the quiz page (while taking it) - Refresh the teacher tab, and: - NEITHER score should be incremented CASE: OQAAT quizzes The expected behaviour for OQAAT quizzes is that the entire attempt counts as 1 participation, just like the normal quizzes. Follow the same steps as above, but: - While taking the quiz, and for every question page: - Refresh the teacher tab and make sure that neither score is incremented OBLIGATORY REFERENCES ---------- ---------- - Acceptance criteria @ http://docs.kodoware.com/canvas/cnvs-5294 refs CNVS-5294 Change-Id: I55883b8edbf417edb42b9fd103e08369e0e9e63c Reviewed-on: https://gerrit.instructure.com/26543 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2013-11-22 01:33:04 +08:00
describe '#corrected_view_score' do
it 'should deduct the participation score from the view score for a quiz' do
subject.view_score = 10
subject.participate_score = 4
subject.asset_group_code = 'quizzes'
More accurate Access Report scores for Quizzes This patch makes it that when viewing the Access Report for a course student, their "Times Viewed" column will reflect the number of times the student has browsed the quiz or any of its related resources (like History, or attempt views), but not taken it. While the "Times Participated" column will reflect the number of times the student really took the quiz (1:1 mapping with the number of submissions.) TEST PLAN ---- ---- In both test cases, you'll need: - a course with a student enrolled - one browser session with a teacher logged in viewing the Access Report of the student - one browser session with the student logged CASE: Normal quizzes - Create a quiz with a few questions and unlimited attempts. - Refresh the teacher tab, keep an eye on Times "Viewed" and "Participated" columns - As the student: - Go to the quizzes page - Go to the quiz page - Refresh the teacher tab, and: - ONLY the "Times Viewed" score should be incremented by 1 - As the student: - Push the Take the Quiz - Refresh the teacher tab, and: - ONLY the "Times Participated" score should be incremented by 1 - As the student: - Refresh the quiz page (while taking it) - Refresh the teacher tab, and: - NEITHER score should be incremented CASE: OQAAT quizzes The expected behaviour for OQAAT quizzes is that the entire attempt counts as 1 participation, just like the normal quizzes. Follow the same steps as above, but: - While taking the quiz, and for every question page: - Refresh the teacher tab and make sure that neither score is incremented OBLIGATORY REFERENCES ---------- ---------- - Acceptance criteria @ http://docs.kodoware.com/canvas/cnvs-5294 refs CNVS-5294 Change-Id: I55883b8edbf417edb42b9fd103e08369e0e9e63c Reviewed-on: https://gerrit.instructure.com/26543 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2013-11-22 01:33:04 +08:00
expect(subject.corrected_view_score).to eq 6
More accurate Access Report scores for Quizzes This patch makes it that when viewing the Access Report for a course student, their "Times Viewed" column will reflect the number of times the student has browsed the quiz or any of its related resources (like History, or attempt views), but not taken it. While the "Times Participated" column will reflect the number of times the student really took the quiz (1:1 mapping with the number of submissions.) TEST PLAN ---- ---- In both test cases, you'll need: - a course with a student enrolled - one browser session with a teacher logged in viewing the Access Report of the student - one browser session with the student logged CASE: Normal quizzes - Create a quiz with a few questions and unlimited attempts. - Refresh the teacher tab, keep an eye on Times "Viewed" and "Participated" columns - As the student: - Go to the quizzes page - Go to the quiz page - Refresh the teacher tab, and: - ONLY the "Times Viewed" score should be incremented by 1 - As the student: - Push the Take the Quiz - Refresh the teacher tab, and: - ONLY the "Times Participated" score should be incremented by 1 - As the student: - Refresh the quiz page (while taking it) - Refresh the teacher tab, and: - NEITHER score should be incremented CASE: OQAAT quizzes The expected behaviour for OQAAT quizzes is that the entire attempt counts as 1 participation, just like the normal quizzes. Follow the same steps as above, but: - While taking the quiz, and for every question page: - Refresh the teacher tab and make sure that neither score is incremented OBLIGATORY REFERENCES ---------- ---------- - Acceptance criteria @ http://docs.kodoware.com/canvas/cnvs-5294 refs CNVS-5294 Change-Id: I55883b8edbf417edb42b9fd103e08369e0e9e63c Reviewed-on: https://gerrit.instructure.com/26543 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2013-11-22 01:33:04 +08:00
end
it 'should return the normal view score for anything but a quiz' do
subject.view_score = 10
subject.participate_score = 4
More accurate Access Report scores for Quizzes This patch makes it that when viewing the Access Report for a course student, their "Times Viewed" column will reflect the number of times the student has browsed the quiz or any of its related resources (like History, or attempt views), but not taken it. While the "Times Participated" column will reflect the number of times the student really took the quiz (1:1 mapping with the number of submissions.) TEST PLAN ---- ---- In both test cases, you'll need: - a course with a student enrolled - one browser session with a teacher logged in viewing the Access Report of the student - one browser session with the student logged CASE: Normal quizzes - Create a quiz with a few questions and unlimited attempts. - Refresh the teacher tab, keep an eye on Times "Viewed" and "Participated" columns - As the student: - Go to the quizzes page - Go to the quiz page - Refresh the teacher tab, and: - ONLY the "Times Viewed" score should be incremented by 1 - As the student: - Push the Take the Quiz - Refresh the teacher tab, and: - ONLY the "Times Participated" score should be incremented by 1 - As the student: - Refresh the quiz page (while taking it) - Refresh the teacher tab, and: - NEITHER score should be incremented CASE: OQAAT quizzes The expected behaviour for OQAAT quizzes is that the entire attempt counts as 1 participation, just like the normal quizzes. Follow the same steps as above, but: - While taking the quiz, and for every question page: - Refresh the teacher tab and make sure that neither score is incremented OBLIGATORY REFERENCES ---------- ---------- - Acceptance criteria @ http://docs.kodoware.com/canvas/cnvs-5294 refs CNVS-5294 Change-Id: I55883b8edbf417edb42b9fd103e08369e0e9e63c Reviewed-on: https://gerrit.instructure.com/26543 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2013-11-22 01:33:04 +08:00
expect(subject.corrected_view_score).to eq 10
More accurate Access Report scores for Quizzes This patch makes it that when viewing the Access Report for a course student, their "Times Viewed" column will reflect the number of times the student has browsed the quiz or any of its related resources (like History, or attempt views), but not taken it. While the "Times Participated" column will reflect the number of times the student really took the quiz (1:1 mapping with the number of submissions.) TEST PLAN ---- ---- In both test cases, you'll need: - a course with a student enrolled - one browser session with a teacher logged in viewing the Access Report of the student - one browser session with the student logged CASE: Normal quizzes - Create a quiz with a few questions and unlimited attempts. - Refresh the teacher tab, keep an eye on Times "Viewed" and "Participated" columns - As the student: - Go to the quizzes page - Go to the quiz page - Refresh the teacher tab, and: - ONLY the "Times Viewed" score should be incremented by 1 - As the student: - Push the Take the Quiz - Refresh the teacher tab, and: - ONLY the "Times Participated" score should be incremented by 1 - As the student: - Refresh the quiz page (while taking it) - Refresh the teacher tab, and: - NEITHER score should be incremented CASE: OQAAT quizzes The expected behaviour for OQAAT quizzes is that the entire attempt counts as 1 participation, just like the normal quizzes. Follow the same steps as above, but: - While taking the quiz, and for every question page: - Refresh the teacher tab and make sure that neither score is incremented OBLIGATORY REFERENCES ---------- ---------- - Acceptance criteria @ http://docs.kodoware.com/canvas/cnvs-5294 refs CNVS-5294 Change-Id: I55883b8edbf417edb42b9fd103e08369e0e9e63c Reviewed-on: https://gerrit.instructure.com/26543 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2013-11-22 01:33:04 +08:00
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')
expect(subject.corrected_view_score).to eq -4
end
More accurate Access Report scores for Quizzes This patch makes it that when viewing the Access Report for a course student, their "Times Viewed" column will reflect the number of times the student has browsed the quiz or any of its related resources (like History, or attempt views), but not taken it. While the "Times Participated" column will reflect the number of times the student really took the quiz (1:1 mapping with the number of submissions.) TEST PLAN ---- ---- In both test cases, you'll need: - a course with a student enrolled - one browser session with a teacher logged in viewing the Access Report of the student - one browser session with the student logged CASE: Normal quizzes - Create a quiz with a few questions and unlimited attempts. - Refresh the teacher tab, keep an eye on Times "Viewed" and "Participated" columns - As the student: - Go to the quizzes page - Go to the quiz page - Refresh the teacher tab, and: - ONLY the "Times Viewed" score should be incremented by 1 - As the student: - Push the Take the Quiz - Refresh the teacher tab, and: - ONLY the "Times Participated" score should be incremented by 1 - As the student: - Refresh the quiz page (while taking it) - Refresh the teacher tab, and: - NEITHER score should be incremented CASE: OQAAT quizzes The expected behaviour for OQAAT quizzes is that the entire attempt counts as 1 participation, just like the normal quizzes. Follow the same steps as above, but: - While taking the quiz, and for every question page: - Refresh the teacher tab and make sure that neither score is incremented OBLIGATORY REFERENCES ---------- ---------- - Acceptance criteria @ http://docs.kodoware.com/canvas/cnvs-5294 refs CNVS-5294 Change-Id: I55883b8edbf417edb42b9fd103e08369e0e9e63c Reviewed-on: https://gerrit.instructure.com/26543 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Derek DeVries <ddevries@instructure.com>
2013-11-22 01:33:04 +08:00
end
describe '#icon' do
it 'works for quizzes' do
quiz = @course.quizzes.create!(:title => 'My Quiz')
asset = factory_with_protected_attributes(AssetUserAccess, :user => @user, :context => @course, :asset_code => quiz.asset_string)
asset.log(@course, { category: 'quizzes' })
asset.save!
expect(asset.icon).to eq 'icon-quiz'
end
end
end