root/vendor/file-column-0.3.1/test/abstract_unit.rb

Revision 2, 1.3 kB (checked in by falcon, 17 years ago)

added plugins

  • Property svn:executable set to *
Line 
1require 'test/unit'
2require 'rubygems'
3require_gem 'activesupport'
4require_gem 'activerecord'
5require 'connection'
6require 'stringio'
7
8RAILS_ROOT = File.dirname(__FILE__)
9
10$: << "../lib"
11
12require 'file_column.rb'
13
14# do not use the file executable normally in our tests as
15# it may not be present on the machine we are running on
16FileColumn::ClassMethods::DEFAULT_OPTIONS = 
17  FileColumn::ClassMethods::DEFAULT_OPTIONS.merge({:file_exec => nil})
18
19class ActiveRecord::Base
20    include FileColumn
21end
22
23
24class Test::Unit::TestCase
25  private
26 
27  def uploaded_file(path, content_type, filename, type=:tempfile)
28    if type == :tempfile
29      t = Tempfile.new(File.basename(filename))
30      FileUtils.copy_file(path, t.path)
31    else
32      if path
33        t = StringIO.new(IO.read(path))
34      else
35        t = StringIO.new
36      end
37    end
38    (class << t; self; end).class_eval do
39      alias local_path path if type == :tempfile
40      define_method(:local_path) { "" } if type == :stringio
41      define_method(:original_filename) {filename}
42      define_method(:content_type) {content_type}
43    end
44    return t
45  end
46
47  def upload(basename, content_type="image/jpeg")
48    uploaded_file(file_path(basename), content_type, basename)
49  end
50
51  def file_path(filename)
52    File.expand_path("#{File.dirname(__FILE__)}/fixtures/#{filename}")
53  end
54
55end
Note: See TracBrowser for help on using the browser.