Skip to content

Instantly share code, notes, and snippets.

@tcocca
Forked from technicalpickles/factories.rb
Created August 27, 2009 20:04
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 tcocca/176515 to your computer and use it in GitHub Desktop.
Save tcocca/176515 to your computer and use it in GitHub Desktop.
Factory.define :application do |factory|
factory.attachment(:sample, "public/samples/sample.doc", "application/msword")
end
require 'action_controller/test_process'
Factory.class_eval do
def attachment(name, path, content_type = nil)
path_with_rails_root = "#{RAILS_ROOT}/#{path}"
uploaded_file = if content_type
ActionController::TestUploadedFile.new(path_with_rails_root, content_type)
else
ActionController::TestUploadedFile.new(path_with_rails_root)
end
add_attribute name, uploaded_file
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment