Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

technicalpickles commented Nov 1, 2010

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