|
Revision 2, 1.3 kB
(checked in by falcon, 17 years ago)
|
|
added plugins
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | require 'test/unit' |
|---|
| 2 | require 'rubygems' |
|---|
| 3 | require_gem 'activesupport' |
|---|
| 4 | require_gem 'activerecord' |
|---|
| 5 | require 'connection' |
|---|
| 6 | require 'stringio' |
|---|
| 7 | |
|---|
| 8 | RAILS_ROOT = File.dirname(__FILE__) |
|---|
| 9 | |
|---|
| 10 | $: << "../lib" |
|---|
| 11 | |
|---|
| 12 | require '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 |
|---|
| 16 | FileColumn::ClassMethods::DEFAULT_OPTIONS = |
|---|
| 17 | FileColumn::ClassMethods::DEFAULT_OPTIONS.merge({:file_exec => nil}) |
|---|
| 18 | |
|---|
| 19 | class ActiveRecord::Base |
|---|
| 20 | include FileColumn |
|---|
| 21 | end |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | class 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 | |
|---|
| 55 | end |
|---|