2020-10-27 00:51:19 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-28 12:02:05 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2012 - 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/>.
|
|
|
|
|
2012-01-18 06:41:25 +08:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
|
|
|
|
|
|
describe ContentZipper do
|
|
|
|
# Note that EportfoliosController#export,
|
|
|
|
# SubmissionsController#submission_zip, and FoldersController#download are
|
|
|
|
# all ALMOST exactly the same code, copied and pasted with slight changes.
|
|
|
|
#
|
|
|
|
# This really needs to get refactored at some point.
|
|
|
|
def grab_zip
|
|
|
|
expect { yield }.to change(Delayed::Job, :count).by(1)
|
2018-08-01 01:25:10 +08:00
|
|
|
expect(response).to be_successful
|
2012-01-18 06:41:25 +08:00
|
|
|
attachment_id = json_parse['attachment']['id']
|
2014-10-14 02:51:52 +08:00
|
|
|
expect(attachment_id).to be_present
|
2012-01-18 06:41:25 +08:00
|
|
|
|
|
|
|
a = Attachment.find attachment_id
|
2014-10-14 02:51:52 +08:00
|
|
|
expect(a).to be_to_be_zipped
|
2012-01-18 06:41:25 +08:00
|
|
|
|
|
|
|
# a second query should just return status
|
|
|
|
expect { yield }.to change(Delayed::Job, :count).by(0)
|
2018-08-01 01:25:10 +08:00
|
|
|
expect(response).to be_successful
|
2014-10-14 02:51:52 +08:00
|
|
|
expect(json_parse['attachment']['id']).to eq a.id
|
2012-01-18 06:41:25 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "submission zips" do
|
2016-08-27 06:20:06 +08:00
|
|
|
before(:once) do
|
|
|
|
course_with_teacher(:active_all => true)
|
2019-02-09 04:41:30 +08:00
|
|
|
@course.enrollments.where(:user_id => @teacher).update_all(:updated_at => 5.minutes.ago)
|
2012-01-18 06:41:25 +08:00
|
|
|
submission_model(:course => @course)
|
2019-02-09 04:41:30 +08:00
|
|
|
Submission.where(:id => @submission).update_all(:submitted_at => 5.minutes.ago)
|
2016-08-27 06:20:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
before(:each) do
|
|
|
|
user_session(@teacher)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should schedule a job on the first request, and then respond with progress updates" do
|
2012-01-18 06:41:25 +08:00
|
|
|
grab_zip { get "/courses/#{@course.id}/assignments/#{@assignment.id}/submissions.json?zip=1&compile=1" }
|
|
|
|
end
|
2016-08-27 06:20:06 +08:00
|
|
|
|
|
|
|
it "should recreate the submission zip if the anonymous grading setting changes" do
|
|
|
|
get "/courses/#{@course.id}/assignments/#{@assignment.id}/submissions.json?zip=1&compile=1"
|
|
|
|
att0 = json_parse['attachment']['id']
|
|
|
|
|
2018-06-06 03:45:06 +08:00
|
|
|
@assignment.update!(anonymous_grading: true)
|
2016-08-27 06:20:06 +08:00
|
|
|
get "/courses/#{@course.id}/assignments/#{@assignment.id}/submissions.json?zip=1&compile=1"
|
|
|
|
att1 = json_parse['attachment']['id']
|
|
|
|
|
|
|
|
expect(att0).not_to eq(att1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should recreate the submission zip if the previous one is too old" do
|
|
|
|
att0 = nil
|
|
|
|
Timecop.travel(1.day.ago) do
|
|
|
|
get "/courses/#{@course.id}/assignments/#{@assignment.id}/submissions.json?zip=1&compile=1"
|
|
|
|
att0 = json_parse['attachment']['id']
|
|
|
|
end
|
|
|
|
|
|
|
|
get "/courses/#{@course.id}/assignments/#{@assignment.id}/submissions.json?zip=1&compile=1"
|
|
|
|
att1 = json_parse['attachment']['id']
|
|
|
|
|
|
|
|
expect(att0).not_to eq(att1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should recreate the submission zip if a submission has been made since its creation" do
|
|
|
|
att0 = nil
|
|
|
|
Timecop.travel(1.minute.ago) do
|
|
|
|
get "/courses/#{@course.id}/assignments/#{@assignment.id}/submissions.json?zip=1&compile=1"
|
|
|
|
att0 = json_parse['attachment']['id']
|
|
|
|
end
|
|
|
|
|
|
|
|
submission_model(:course => @course)
|
|
|
|
get "/courses/#{@course.id}/assignments/#{@assignment.id}/submissions.json?zip=1&compile=1"
|
|
|
|
att1 = json_parse['attachment']['id']
|
|
|
|
|
|
|
|
expect(att0).not_to eq(att1)
|
|
|
|
end
|
2019-02-09 04:41:30 +08:00
|
|
|
|
|
|
|
it "should not recreate the submission zip if nothing has changed" do
|
|
|
|
att0 = nil
|
|
|
|
Timecop.travel(1.minute.ago) do
|
|
|
|
get "/courses/#{@course.id}/assignments/#{@assignment.id}/submissions.json?zip=1&compile=1"
|
|
|
|
att0 = json_parse['attachment']['id']
|
|
|
|
end
|
|
|
|
|
|
|
|
get "/courses/#{@course.id}/assignments/#{@assignment.id}/submissions.json?zip=1&compile=1"
|
|
|
|
att1 = json_parse['attachment']['id']
|
|
|
|
|
|
|
|
expect(att0).to eq(att1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should recreate the submission zip if the user's enrollments have been changed" do
|
|
|
|
att0 = nil
|
|
|
|
Timecop.travel(1.minute.ago) do
|
|
|
|
get "/courses/#{@course.id}/assignments/#{@assignment.id}/submissions.json?zip=1&compile=1"
|
|
|
|
att0 = json_parse['attachment']['id']
|
|
|
|
end
|
|
|
|
section = @course.course_sections.create!
|
|
|
|
@course.enroll_user(@teacher, 'TeacherEnrollment', :section => section,
|
|
|
|
:enrollment_state => 'active', :allow_multiple_enrollments => true)
|
|
|
|
|
|
|
|
get "/courses/#{@course.id}/assignments/#{@assignment.id}/submissions.json?zip=1&compile=1"
|
|
|
|
att1 = json_parse['attachment']['id']
|
|
|
|
|
|
|
|
expect(att0).not_to eq(att1)
|
|
|
|
end
|
2012-01-18 06:41:25 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "eportfolio zips" do
|
|
|
|
it "should schedule a job on the first request, and then respond with progress updates" do
|
|
|
|
eportfolio_model
|
|
|
|
user_session(@user)
|
|
|
|
grab_zip { get "/eportfolios/#{@eportfolio.id}/export.json?compile=1" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|