Skip to content

Instantly share code, notes, and snippets.

@abepetrillo
Created May 20, 2016 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abepetrillo/0c2df11df6cf7e1023c637f7204115fb to your computer and use it in GitHub Desktop.
Save abepetrillo/0c2df11df6cf7e1023c637f7204115fb to your computer and use it in GitHub Desktop.
require 'test_helper'
class DocumentsControllerTest < ActionController::TestCase
test "Uploading a file" do
file_path = File.join(Rails.root, 'tmp', SecureRandom.uuid)
File.open(file_path, 'w+b') { |f| f.write "A random file used for testing attachments!" }
file = Rack::Test::UploadedFile.new(file_path, 'text/plain')
post :create, {file: file}
assert_response :success
assert_equal(Document.last.file, 'A random file used for testing attachments!')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment