From 9b0602fd9ca506e0d1502951bee9c4383bfd1e96 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Mon, 18 May 2015 17:26:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AD=A6=E7=94=9F=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E4=B8=8B=E8=BD=BDspec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/locales/commons/en.yml | 3 ++- config/locales/commons/zh.yml | 3 ++- spec/factories/attachments.rb | 10 ++++++++ spec/factories/homeworks.rb | 17 ++++++++++++++ spec/factories/users.rb | 8 +++++++ spec/requests/zipdown_request_spec.rb | 34 +++++++++++++++++++++++++++ 6 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 spec/factories/attachments.rb create mode 100644 spec/factories/homeworks.rb diff --git a/config/locales/commons/en.yml b/config/locales/commons/en.yml index 5eb92f07e..c0e29b797 100644 --- a/config/locales/commons/en.yml +++ b/config/locales/commons/en.yml @@ -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" @@ -428,4 +429,4 @@ en: previous: "« Previous" next: "Next »" truncate: "..." - \ No newline at end of file + diff --git a/config/locales/commons/zh.yml b/config/locales/commons/zh.yml index 231c5280a..9ba8cba7a 100644 --- a/config/locales/commons/zh.yml +++ b/config/locales/commons/zh.yml @@ -121,6 +121,7 @@ zh: one: "由于发生了一个错误 %{model} 无法保存" other: "%{count} 个错误使得 %{model} 无法保存" messages: + record_invalid: "校验失败: %{errors}" inclusion: "不包含于列表中" exclusion: "是保留关键字" invalid: "是无效的" @@ -435,4 +436,4 @@ zh: last: "末页 »" previous: "« 上一页" next: "下一页 »" - truncate: "..." \ No newline at end of file + truncate: "..." diff --git a/spec/factories/attachments.rb b/spec/factories/attachments.rb new file mode 100644 index 000000000..da8e787ed --- /dev/null +++ b/spec/factories/attachments.rb @@ -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 diff --git a/spec/factories/homeworks.rb b/spec/factories/homeworks.rb new file mode 100644 index 000000000..208255a8d --- /dev/null +++ b/spec/factories/homeworks.rb @@ -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 diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 2c695b920..4595aacc5 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -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 diff --git a/spec/requests/zipdown_request_spec.rb b/spec/requests/zipdown_request_spec.rb index eb179f104..72831d26f 100644 --- a/spec/requests/zipdown_request_spec.rb +++ b/spec/requests/zipdown_request_spec.rb @@ -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