新增学生作业下载spec
This commit is contained in:
parent
1226f74750
commit
9b0602fd9c
|
@ -113,6 +113,7 @@ en:
|
|||
one: "1 error prohibited this %{model} from being saved"
|
||||
other: "%{count} errors prohibited this %{model} from being saved"
|
||||
messages:
|
||||
record_invalid: "validate error: %{errors}"
|
||||
inclusion: "is not included in the list"
|
||||
exclusion: "is reserved"
|
||||
invalid: "is invalid"
|
||||
|
|
|
@ -121,6 +121,7 @@ zh:
|
|||
one: "由于发生了一个错误 %{model} 无法保存"
|
||||
other: "%{count} 个错误使得 %{model} 无法保存"
|
||||
messages:
|
||||
record_invalid: "校验失败: %{errors}"
|
||||
inclusion: "不包含于列表中"
|
||||
exclusion: "是保留关键字"
|
||||
invalid: "是无效的"
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#coding=utf-8
|
||||
#
|
||||
FactoryGirl.define do
|
||||
factory :attachment do
|
||||
filename "11.gif"
|
||||
filesize 296833
|
||||
digest "8a74e086d7716f89bc4fbac0606589c7"
|
||||
disk_directory "2015/05"
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
#coding=utf-8
|
||||
#
|
||||
#:author_id, :budget, :deadline, :name, :description, :homework_type, :password
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :homework, class: Bid do
|
||||
name "test homework"
|
||||
budget 0
|
||||
deadline {(Time.now+1.days).strftime('%Y-%m-%d')}
|
||||
description "description"
|
||||
homework_type 3
|
||||
reward_type 3
|
||||
end
|
||||
|
||||
factory :homework_attach, class: HomeworkAttach do
|
||||
end
|
||||
end
|
|
@ -6,4 +6,12 @@ FactoryGirl.define do
|
|||
password "foobar111"
|
||||
password_confirmation "foobar111"
|
||||
end
|
||||
|
||||
factory :student, class: User do
|
||||
login "student"
|
||||
mail "student@example.com"
|
||||
password "foobar111"
|
||||
password_confirmation "foobar111"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,6 +1,40 @@
|
|||
require 'rails_helper'
|
||||
require 'shared_account_spec'
|
||||
|
||||
# "attachments"=>{"1"=>{"filename"=>"11.gif", "description"=>"", "is_public_checkbox"=>"1", "token"=>"33731.8a74e086d7716f89bc4fbac0606589c7"}}
|
||||
RSpec.describe "作业打包下载", :type => :request do
|
||||
let(:student){FactoryGirl.create(:student)}
|
||||
describe "单独下载某学生作业" do
|
||||
include_context "create user"
|
||||
before {
|
||||
FactoryGirl.create(:user)
|
||||
shared_login
|
||||
@homework = FactoryGirl.create(:homework, author_id: current_user.id)
|
||||
|
||||
@attch = HomeworkAttach.new
|
||||
@attch.bid_id = @homework.id
|
||||
@attch.user_id = student.id
|
||||
@attachment = Attachment.new(:file => File.open(File.join(Rails.root, "spec/fixtures/test.jpg")))
|
||||
@attachment.author = User.current
|
||||
@attachment.container_type = 'HomeworkAttach'
|
||||
@attachment.container_id = @attch.id
|
||||
@attachment.filename = "test.jpg"
|
||||
@attachment.save
|
||||
params = {"1"=>{"filename" => "test.jpg", "description" =>"",
|
||||
"is_public_checkbox"=>"1",
|
||||
"token" => "#{@attachment.id}.#{@attachment.digest}" }
|
||||
}
|
||||
@attch.save_attachments(params)
|
||||
@attch.name = "test.jpg"
|
||||
@attch.save!
|
||||
}
|
||||
it "正常下载" do
|
||||
uu = current_user
|
||||
allow(uu).to receive(:admin?).and_return(true)
|
||||
allow(User).to receive(:current).and_return(uu)
|
||||
get zipdown_download_user_homework_path, {homework:@attch.id}
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.content_type).to eq(Mime::Type.new("applcation/zip",:zip))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue