-
-
Save simi/1051037 to your computer and use it in GitHub Desktop.
Paperclip factory_girl macro working with Rails 3.1rc4
This file contains 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 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_dispatch/testing/test_process' | |
Factory.class_eval do | |
def attachment(name, path, content_type = nil) | |
path_with_rails_root = Rails.root.join(path) | |
uploaded_file = if content_type | |
Rack::Test::UploadedFile.new(path_with_rails_root, content_type) | |
else | |
Rack::Test::UploadedFile.new(path_with_rails_root) | |
end | |
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
Thanks. I hadn't seen that.