Skip to content

Instantly share code, notes, and snippets.

@technicalpickles
Created August 5, 2009 18:57
  • Star 3 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save technicalpickles/162881 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
@flov
Copy link

flov commented Oct 31, 2010

where do you put the factory_attachment.rb in the init directory?

@technicalpickles
Copy link
Author

I don't have the project I originally extracted this from handy, so I'm not sure where exactly I had it.

It doesn't actually matter where it lives, as long as it's required in the factories.rb. You could even just drop it at the top of the file really.

I'll see about gemming this up, which should make it a bit easier :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment