2011-05-26 06:16:01 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2011 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')
|
|
|
|
|
|
|
|
describe "user asset accesses" do
|
|
|
|
before(:each) do
|
|
|
|
Setting.set('enable_page_views', 'db')
|
show the correct date/time for the student access report
The report was displaying the AssetUserAccess updated_at, which isn't
always the time of the last access -- #display_name re-saves the record,
for example.
Now AssetUserAccess keeps the last access time in a dedicated
last_access field. Turns out the table already had this column, but it
was unused. So now we're using it.
fixes #6679
test plan:
* As a student, access some course content -- look at assignments,
quizzes, pages, the syllabus, etc
* As a teacher, go to the student roster, select the student, and
click to view the student access report.
* Verify that all the last access times are correct (and not just set
to the current time).
Change-Id: Icef3073e777d191c281a21e8d160ec08201be374
Reviewed-on: https://gerrit.instructure.com/8880
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
2012-02-22 06:40:06 +08:00
|
|
|
|
2011-05-26 06:16:01 +08:00
|
|
|
username = "nobody@example.com"
|
|
|
|
password = "asdfasdf"
|
|
|
|
u = user_with_pseudonym :active_user => true,
|
|
|
|
:username => username,
|
|
|
|
:password => password
|
|
|
|
u.save!
|
|
|
|
@e = course_with_teacher :active_course => true,
|
|
|
|
:user => u,
|
|
|
|
:active_enrollment => true
|
|
|
|
@e.save!
|
|
|
|
@teacher = u
|
|
|
|
user_session(@user, @pseudonym)
|
show the correct date/time for the student access report
The report was displaying the AssetUserAccess updated_at, which isn't
always the time of the last access -- #display_name re-saves the record,
for example.
Now AssetUserAccess keeps the last access time in a dedicated
last_access field. Turns out the table already had this column, but it
was unused. So now we're using it.
fixes #6679
test plan:
* As a student, access some course content -- look at assignments,
quizzes, pages, the syllabus, etc
* As a teacher, go to the student roster, select the student, and
click to view the student access report.
* Verify that all the last access times are correct (and not just set
to the current time).
Change-Id: Icef3073e777d191c281a21e8d160ec08201be374
Reviewed-on: https://gerrit.instructure.com/8880
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
2012-02-22 06:40:06 +08:00
|
|
|
|
2011-05-26 06:16:01 +08:00
|
|
|
user_model
|
|
|
|
@student = @user
|
|
|
|
@course.enroll_student(@student).accept
|
|
|
|
end
|
show the correct date/time for the student access report
The report was displaying the AssetUserAccess updated_at, which isn't
always the time of the last access -- #display_name re-saves the record,
for example.
Now AssetUserAccess keeps the last access time in a dedicated
last_access field. Turns out the table already had this column, but it
was unused. So now we're using it.
fixes #6679
test plan:
* As a student, access some course content -- look at assignments,
quizzes, pages, the syllabus, etc
* As a teacher, go to the student roster, select the student, and
click to view the student access report.
* Verify that all the last access times are correct (and not just set
to the current time).
Change-Id: Icef3073e777d191c281a21e8d160ec08201be374
Reviewed-on: https://gerrit.instructure.com/8880
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
2012-02-22 06:40:06 +08:00
|
|
|
|
|
|
|
include ApplicationHelper
|
|
|
|
|
2011-05-26 06:16:01 +08:00
|
|
|
it "should record and show user asset accesses" do
|
show the correct date/time for the student access report
The report was displaying the AssetUserAccess updated_at, which isn't
always the time of the last access -- #display_name re-saves the record,
for example.
Now AssetUserAccess keeps the last access time in a dedicated
last_access field. Turns out the table already had this column, but it
was unused. So now we're using it.
fixes #6679
test plan:
* As a student, access some course content -- look at assignments,
quizzes, pages, the syllabus, etc
* As a teacher, go to the student roster, select the student, and
click to view the student access report.
* Verify that all the last access times are correct (and not just set
to the current time).
Change-Id: Icef3073e777d191c281a21e8d160ec08201be374
Reviewed-on: https://gerrit.instructure.com/8880
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
2012-02-22 06:40:06 +08:00
|
|
|
now = Time.now.utc
|
|
|
|
Time.stubs(:now).returns(now)
|
|
|
|
|
2011-05-26 06:16:01 +08:00
|
|
|
assignment = @course.assignments.create(:title => 'Assignment 1')
|
|
|
|
assignment.workflow_state = 'active'
|
|
|
|
assignment.save!
|
show the correct date/time for the student access report
The report was displaying the AssetUserAccess updated_at, which isn't
always the time of the last access -- #display_name re-saves the record,
for example.
Now AssetUserAccess keeps the last access time in a dedicated
last_access field. Turns out the table already had this column, but it
was unused. So now we're using it.
fixes #6679
test plan:
* As a student, access some course content -- look at assignments,
quizzes, pages, the syllabus, etc
* As a teacher, go to the student roster, select the student, and
click to view the student access report.
* Verify that all the last access times are correct (and not just set
to the current time).
Change-Id: Icef3073e777d191c281a21e8d160ec08201be374
Reviewed-on: https://gerrit.instructure.com/8880
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
2012-02-22 06:40:06 +08:00
|
|
|
|
2011-05-26 06:16:01 +08:00
|
|
|
user_session(@student)
|
|
|
|
get "/courses/#{@course.id}/assignments/#{assignment.id}"
|
|
|
|
response.should be_success
|
show the correct date/time for the student access report
The report was displaying the AssetUserAccess updated_at, which isn't
always the time of the last access -- #display_name re-saves the record,
for example.
Now AssetUserAccess keeps the last access time in a dedicated
last_access field. Turns out the table already had this column, but it
was unused. So now we're using it.
fixes #6679
test plan:
* As a student, access some course content -- look at assignments,
quizzes, pages, the syllabus, etc
* As a teacher, go to the student roster, select the student, and
click to view the student access report.
* Verify that all the last access times are correct (and not just set
to the current time).
Change-Id: Icef3073e777d191c281a21e8d160ec08201be374
Reviewed-on: https://gerrit.instructure.com/8880
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
2012-02-22 06:40:06 +08:00
|
|
|
|
2011-05-26 06:16:01 +08:00
|
|
|
user_session(@teacher)
|
|
|
|
get "/courses/#{@course.id}/users/#{@student.id}/usage"
|
|
|
|
response.should be_success
|
|
|
|
html = Nokogiri::HTML(response.body)
|
|
|
|
html.css('#usage_report .access.assignment').length.should == 1
|
|
|
|
html.css('#usage_report .access.assignment .readable_name').text.strip.should == 'Assignment 1'
|
|
|
|
html.css('#usage_report .access.assignment .view_score').text.strip.should == '1'
|
show the correct date/time for the student access report
The report was displaying the AssetUserAccess updated_at, which isn't
always the time of the last access -- #display_name re-saves the record,
for example.
Now AssetUserAccess keeps the last access time in a dedicated
last_access field. Turns out the table already had this column, but it
was unused. So now we're using it.
fixes #6679
test plan:
* As a student, access some course content -- look at assignments,
quizzes, pages, the syllabus, etc
* As a teacher, go to the student roster, select the student, and
click to view the student access report.
* Verify that all the last access times are correct (and not just set
to the current time).
Change-Id: Icef3073e777d191c281a21e8d160ec08201be374
Reviewed-on: https://gerrit.instructure.com/8880
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
2012-02-22 06:40:06 +08:00
|
|
|
html.css('#usage_report .access.assignment .last_viewed').text.strip.should == datetime_string(now)
|
2012-02-25 02:28:26 +08:00
|
|
|
AssetUserAccess.first(:conditions => { :user_id => @student.id }).last_access.to_i.should == now.to_i
|
show the correct date/time for the student access report
The report was displaying the AssetUserAccess updated_at, which isn't
always the time of the last access -- #display_name re-saves the record,
for example.
Now AssetUserAccess keeps the last access time in a dedicated
last_access field. Turns out the table already had this column, but it
was unused. So now we're using it.
fixes #6679
test plan:
* As a student, access some course content -- look at assignments,
quizzes, pages, the syllabus, etc
* As a teacher, go to the student roster, select the student, and
click to view the student access report.
* Verify that all the last access times are correct (and not just set
to the current time).
Change-Id: Icef3073e777d191c281a21e8d160ec08201be374
Reviewed-on: https://gerrit.instructure.com/8880
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
2012-02-22 06:40:06 +08:00
|
|
|
|
|
|
|
now2 = now + 1.hour
|
|
|
|
Time.stubs(:now).returns(now2)
|
|
|
|
|
|
|
|
# make sure that we're not using the uodated_at time as the time of the access
|
|
|
|
AssetUserAccess.update_all({ :updated_at => now2 + 5.hours }, { :user_id => @student.id })
|
|
|
|
|
2011-05-26 06:16:01 +08:00
|
|
|
user_session(@student)
|
|
|
|
get "/courses/#{@course.id}/assignments/#{assignment.id}"
|
|
|
|
response.should be_success
|
show the correct date/time for the student access report
The report was displaying the AssetUserAccess updated_at, which isn't
always the time of the last access -- #display_name re-saves the record,
for example.
Now AssetUserAccess keeps the last access time in a dedicated
last_access field. Turns out the table already had this column, but it
was unused. So now we're using it.
fixes #6679
test plan:
* As a student, access some course content -- look at assignments,
quizzes, pages, the syllabus, etc
* As a teacher, go to the student roster, select the student, and
click to view the student access report.
* Verify that all the last access times are correct (and not just set
to the current time).
Change-Id: Icef3073e777d191c281a21e8d160ec08201be374
Reviewed-on: https://gerrit.instructure.com/8880
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
2012-02-22 06:40:06 +08:00
|
|
|
|
2011-05-26 06:16:01 +08:00
|
|
|
user_session(@teacher)
|
|
|
|
get "/courses/#{@course.id}/users/#{@student.id}/usage"
|
|
|
|
response.should be_success
|
|
|
|
html = Nokogiri::HTML(response.body)
|
|
|
|
html.css('#usage_report .access.assignment').length.should == 1
|
|
|
|
html.css('#usage_report .access.assignment .readable_name').text.strip.should == 'Assignment 1'
|
|
|
|
html.css('#usage_report .access.assignment .view_score').text.strip.should == '2'
|
show the correct date/time for the student access report
The report was displaying the AssetUserAccess updated_at, which isn't
always the time of the last access -- #display_name re-saves the record,
for example.
Now AssetUserAccess keeps the last access time in a dedicated
last_access field. Turns out the table already had this column, but it
was unused. So now we're using it.
fixes #6679
test plan:
* As a student, access some course content -- look at assignments,
quizzes, pages, the syllabus, etc
* As a teacher, go to the student roster, select the student, and
click to view the student access report.
* Verify that all the last access times are correct (and not just set
to the current time).
Change-Id: Icef3073e777d191c281a21e8d160ec08201be374
Reviewed-on: https://gerrit.instructure.com/8880
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
2012-02-22 06:40:06 +08:00
|
|
|
html.css('#usage_report .access.assignment .last_viewed').text.strip.should == datetime_string(now2)
|
2012-02-25 02:28:26 +08:00
|
|
|
AssetUserAccess.first(:conditions => { :user_id => @student.id }).last_access.to_i.should == now2.to_i
|
2011-05-26 06:16:01 +08:00
|
|
|
end
|
|
|
|
end
|