Skip to content

Instantly share code, notes, and snippets.

@akia
Created March 7, 2009 07:29
Show Gist options
  • Save akia/75261 to your computer and use it in GitHub Desktop.
Save akia/75261 to your computer and use it in GitHub Desktop.
[ruby] upload file
def uploaded_file(tmp_filename, content_type, filename)
t = Tempfile.new(filename)
t.binmode
path = RAILS_ROOT + "/test/fixtures/files/" + tmp_filename
FileUtils.copy_file(path, t.path)
(class << t; self; end).class_eval do
alias local_path path
define_method(:original_filename) { filename }
define_method(:content_type) { content_type }
end
return t
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment