Skip to content

Instantly share code, notes, and snippets.

@cblunt
Forked from technicalpickles/factories.rb
Created October 15, 2010 14:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cblunt/628228 to your computer and use it in GitHub Desktop.
Save cblunt/628228 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