Skip to content

Instantly share code, notes, and snippets.

@bullfight
Forked from cblunt/factories.rb
Created September 13, 2011 13:14
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 bullfight/1213779 to your computer and use it in GitHub Desktop.
Save bullfight/1213779 to your computer and use it in GitHub Desktop.
Simulate paperclip attachments with FactoryGirl in Rails 3
Factory.define :application do |factory|
factory.attachment :sample, "public/samples/sample.doc", "application/msword"
end
Factory.class_eval do
# Default content type is +image/jpg+
def attachment(name, path, content_type = "image/jpg")
path_with_rails_root = "#{Rails.root}/#{path}"
uploaded_file = fixture_file_upload(path_with_rails_root, content_type)
add_attribute name, uploaded_file
end
end
# Support for Paperclip factories (add this before you load your factory definitions)
include ActionDispatch::TestProcess
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment