Skip to content

Instantly share code, notes, and snippets.

@pacoguzman
Forked from technicalpickles/factories.rb
Created June 13, 2010 08:31
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 pacoguzman/436468 to your computer and use it in GitHub Desktop.
Save pacoguzman/436468 to your computer and use it in GitHub Desktop.
Factory.define :application do |factory|
factory.attachment(:sample, "public/samples/sample.doc", "application/msword")
end
# Support for Paperclip factories (add this before you load your factory definitions)
include ActionDispatch::TestProcess
Factory.class_eval do
# Default content type is +image/jpg+
def attachment(name, path, content_type = "image/jpg")
path_with_rails_root = Rails.root.join(path)
uploaded_file = fixture_file_upload(path_with_rails_root, content_type)
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