Forked from jeffrafter/factory_girl attachments for paperclip
Created
July 9, 2010 08:12
-
-
Save ctrochalakis/469219 to your computer and use it in GitHub Desktop.
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_controller/test_process' | |
# Paperclip attachments in factories, made easy based on technicalpickles | |
Factory.class_eval do | |
def attach(name, path, content_type = nil) | |
if content_type | |
add_attribute name, ActionController::TestUploadedFile.new("#{RAILS_ROOT}/#{path}", content_type) | |
else | |
add_attribute name, ActionController::TestUploadedFile.new("#{RAILS_ROOT}/#{path}") | |
end | |
end | |
end | |
Factory.sequence :badge do |n| | |
"name#{n}" | |
end | |
Factory.define :badge do |badge| | |
badge.name { Factory.next :badge } | |
badge.active { true } | |
badge.description { "You get this when you are awesome" } | |
badge.tags { "cool awesome" } | |
badge.site { |badge| badge.association(:site) } | |
badge.attach ( "image", "test/fixtures/flower.png", "image/png" ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment