CarrierWave:当文件类型在test:unit的黑名单中时,没有触发错误

时间:2012-07-30 11:42:54

标签: ruby upload carrierwave

def upload_fixture_file filename, content_type
    ActionDispatch::Http::UploadedFile.new({
      :filename => filename,
      :content_type => content_type,
      :tempfile => File.new("#{Rails.root}/test/fixtures/files/" + filename)
                                           })
end

test "should deny exe file upload" do
  file = upload_fixture_file 'SkypeSetup.exe', "application/exe"
  assert_no_difference 'Upload.count' do
    post :create, :upload => { :case_id=> cases(:fred_and_oliver_open).id, :file     => file, :reviewed => :false, :user_id =>   users(:fred).id }
  end
end

运行上面的测试会导致“Upload.count”没有改变0.在我的应用程序中我得到了预期的“发生了错误:文件您不能上传”exe“文件,允许的类型:[”jpg “,”jpeg“,”gif“,”png“,”pdf“,”doc“,”docs“,”rtf“,”ods“,”bmp“,”odt“]”

为什么会这样? 谢谢

0 个答案:

没有答案