Skip to content

Instantly share code, notes, and snippets.

@ilpoldo
Forked from kris/factories.rb
Created February 21, 2010 22:54
Show Gist options
  • Save ilpoldo/310593 to your computer and use it in GitHub Desktop.
Save ilpoldo/310593 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)
full_path = File.expand_path(path,RAILS_ROOT)
uploaded_file = ActionController::TestUploadedFile.new(full_path, content_type)
add_attribute name, uploaded_file
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment