mardi 6 juin 2017

Testing File Creation in Rails

My App saves Files to the Filesystem via an base64 encoded API. Here is my (simplified) controller:

def create
  file = "name.pdf"
  folder = "downloads"

  FileUtils::mkdir_p folder

  f = File.open File.join(folder, file), "wb"
  if f.write Base64.decode64(params[:file])
  f.close
end

Now I want to test for an actual file creation. How do I check whether there is a file or not?

Thanks for your input!

Aucun commentaire:

Enregistrer un commentaire