Skip to content

Instantly share code, notes, and snippets.

@ambethia
Forked from technicalpickles/factories.rb
Created September 15, 2009 12:55

Revisions

  1. @technicalpickles technicalpickles revised this gist Aug 5, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion factories.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    Factory.define :application do |factory|
    factory.attachment("public/samples/sample.doc", "application/msword")
    factory.attachment(:sample, "public/samples/sample.doc", "application/msword")
    end
  2. @technicalpickles technicalpickles revised this gist Aug 5, 2009. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions factories.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    Factory.define :application do |factory|
    factory.attachment("public/samples/sample.doc", "application/msword")
    end
  3. @technicalpickles technicalpickles renamed this gist Aug 5, 2009. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @technicalpickles technicalpickles revised this gist Aug 5, 2009. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions factories.rb
    Original file line number Diff line number Diff line change
    @@ -3,12 +3,11 @@
    def attachment(name, path, content_type = nil)
    path_with_rails_root = "#{RAILS_ROOT}/#{path}"
    uploaded_file = if content_type
    ActionController::TestUploadedFile.new(path_with_rails_root, 'image/jpeg')
    ActionController::TestUploadedFile.new(path_with_rails_root, content_type)
    else
    ActionController::TestUploadedFile.new(path_with_rails_root)
    end

    add_attribute name, uploaded_file
    end

    end
    end
  5. @technicalpickles technicalpickles created this gist Aug 5, 2009.
    14 changes: 14 additions & 0 deletions factories.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    require 'action_controller/test_process'
    Factory.class_eval do
    def attachment(name, path, content_type = nil)
    path_with_rails_root = "#{RAILS_ROOT}/#{path}"
    uploaded_file = if content_type
    ActionController::TestUploadedFile.new(path_with_rails_root, 'image/jpeg')
    else
    ActionController::TestUploadedFile.new(path_with_rails_root)
    end

    add_attribute name, uploaded_file
    end

    end