Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctrochalakis/469219 to your computer and use it in GitHub Desktop.
Save ctrochalakis/469219 to your computer and use it in GitHub Desktop.
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