i18n functionality in content_zipper for submission rendering

fixes #5121

Change-Id: I438f5203de4f297930fc43d53554c0e9107f9f52
Reviewed-on: https://gerrit.instructure.com/5439
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
This commit is contained in:
Brian Palmer 2011-09-06 10:49:00 -06:00
parent fe85551af6
commit 10870a8ee8
3 changed files with 49 additions and 3 deletions

View File

@ -22,6 +22,7 @@ require 'tmpdir'
require 'set'
class ContentZipper
def initialize
@logger = Rails.logger
end
@ -41,7 +42,13 @@ class ContentZipper
send(*args)
end
end
# we evaluate some ERB templates from under app/views/ while generating assignment zips
include I18nUtilities
def t(*a, &b)
I18n.t(*a, &b)
end
def self.process_attachment(*args)
ContentZipper.new.process_attachment(*args)
end

View File

@ -18,10 +18,10 @@
def submission_model(opts={})
assignment_model
@student = opts[:user] || User.create!(:name => "new student")
@student = opts.delete(:user) || User.create!(:name => "new student")
@enrollment = @course.enroll_student(@student)
@assignment.reload # it caches the course pre-student enrollment
@submission = @assignment.submit_homework(@student, :url => "http://www.instructure.com/")
@submission = @assignment.submit_homework(@student, (opts.presence || { :url => "http://www.instructure.com/" }))
end
def assignment_valid_attributes

View File

@ -19,6 +19,45 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe ContentZipper do
describe "zip_assignment" do
it "should zip up online_url submissions" do
course_with_student(:active_all => true)
submission_model
attachment = Attachment.new(:display_name => 'my_download.zip')
attachment.user_id = @user.id
attachment.workflow_state = 'to_be_zipped'
attachment.context = @assignment
attachment.save!
ContentZipper.process_attachment(attachment)
attachment.reload
attachment.workflow_state.should == 'zipped'
Zip::ZipFile.foreach(attachment.full_filename) do |f|
if f.file?
f.get_input_stream.read.should match(%r{This submission was a url, we're taking you to the url link now.})
f.get_input_stream.read.should be_include("http://www.instructure.com/")
end
end
end
it "should zip up online_text_entry submissions" do
course_with_student(:active_all => true)
submission_model(:body => "hai this is my answer")
attachment = Attachment.new(:display_name => 'my_download.zip')
attachment.user_id = @user.id
attachment.workflow_state = 'to_be_zipped'
attachment.context = @assignment
attachment.save!
ContentZipper.process_attachment(attachment)
attachment.reload
attachment.workflow_state.should == 'zipped'
Zip::ZipFile.foreach(attachment.full_filename) do |f|
if f.file?
f.get_input_stream.read.should be_include("hai this is my answer")
end
end
end
end
describe "zip_folder" do
it "should only zip up files/folders the user has access to" do
course_with_student(:active_all => true)