diff options
| author | hukl <contact@smyck.org> | 2009-04-24 11:43:08 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-04-25 14:55:27 +0200 |
| commit | cf1b60e0cfa7d1a8f4a80d686649cc12e73a634e (patch) | |
| tree | b68bd845d290ce968892c4532bcff52083925834 /vendor/plugins/paperclip/test/iostream_test.rb | |
| parent | b2b78c06074046bd73cc3408a29386a976f0469c (diff) | |
Integrated basic Asset upload functionality. You can upload files now and use their url in pages.
Diffstat (limited to 'vendor/plugins/paperclip/test/iostream_test.rb')
| -rw-r--r-- | vendor/plugins/paperclip/test/iostream_test.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/vendor/plugins/paperclip/test/iostream_test.rb b/vendor/plugins/paperclip/test/iostream_test.rb new file mode 100644 index 0000000..97030b5 --- /dev/null +++ b/vendor/plugins/paperclip/test/iostream_test.rb | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | require 'test/helper' | ||
| 2 | |||
| 3 | class IOStreamTest < Test::Unit::TestCase | ||
| 4 | context "IOStream" do | ||
| 5 | should "be included in IO, File, Tempfile, and StringIO" do | ||
| 6 | [IO, File, Tempfile, StringIO].each do |klass| | ||
| 7 | assert klass.included_modules.include?(IOStream), "Not in #{klass}" | ||
| 8 | end | ||
| 9 | end | ||
| 10 | end | ||
| 11 | |||
| 12 | context "A file" do | ||
| 13 | setup do | ||
| 14 | @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb') | ||
| 15 | end | ||
| 16 | |||
| 17 | teardown { @file.close } | ||
| 18 | |||
| 19 | context "that is sent #stream_to" do | ||
| 20 | |||
| 21 | context "and given a String" do | ||
| 22 | setup do | ||
| 23 | FileUtils.mkdir_p(File.join(ROOT, 'tmp')) | ||
| 24 | assert @result = @file.stream_to(File.join(ROOT, 'tmp', 'iostream.string.test')) | ||
| 25 | end | ||
| 26 | |||
| 27 | should "return a File" do | ||
| 28 | assert @result.is_a?(File) | ||
| 29 | end | ||
| 30 | |||
| 31 | should "contain the same data as the original file" do | ||
| 32 | @file.rewind; @result.rewind | ||
| 33 | assert_equal @file.read, @result.read | ||
| 34 | end | ||
| 35 | end | ||
| 36 | |||
| 37 | context "and given a Tempfile" do | ||
| 38 | setup do | ||
| 39 | tempfile = Tempfile.new('iostream.test') | ||
| 40 | tempfile.binmode | ||
| 41 | assert @result = @file.stream_to(tempfile) | ||
| 42 | end | ||
| 43 | |||
| 44 | should "return a Tempfile" do | ||
| 45 | assert @result.is_a?(Tempfile) | ||
| 46 | end | ||
| 47 | |||
| 48 | should "contain the same data as the original file" do | ||
| 49 | @file.rewind; @result.rewind | ||
| 50 | assert_equal @file.read, @result.read | ||
| 51 | end | ||
| 52 | end | ||
| 53 | |||
| 54 | end | ||
| 55 | |||
| 56 | context "that is sent #to_tempfile" do | ||
| 57 | setup do | ||
| 58 | assert @tempfile = @file.to_tempfile | ||
| 59 | end | ||
| 60 | |||
| 61 | should "convert it to a Tempfile" do | ||
| 62 | assert @tempfile.is_a?(Tempfile) | ||
| 63 | end | ||
| 64 | |||
| 65 | should "have the Tempfile contain the same data as the file" do | ||
| 66 | @file.rewind; @tempfile.rewind | ||
| 67 | assert_equal @file.read, @tempfile.read | ||
| 68 | end | ||
| 69 | end | ||
| 70 | end | ||
| 71 | end | ||
