-
-
Save cblunt/628228 to your computer and use it in GitHub Desktop.
Simulate paperclip attachments with FactoryGirl in Rails 3
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
Factory.class_eval do | |
# Default content type is +image/jpg+ | |
def attachment(name, path, content_type = "image/jpg") | |
path_with_rails_root = "#{Rails.root}/#{path}" | |
uploaded_file = fixture_file_upload(path_with_rails_root, content_type) | |
add_attribute name, uploaded_file | |
end | |
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
# Support for Paperclip factories (add this before you load your factory definitions) | |
include ActionDispatch::TestProcess |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment