Created
August 5, 2009 18:57
-
-
Save technicalpickles/162881 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Factory.define :application do |factory| | |
factory.attachment(:sample, "public/samples/sample.doc", "application/msword") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
where do you put the factory_attachment.rb in the init directory?