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