attachments 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Binary file
data/test/helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'rubygems'
2
4
  require 'test/unit'
3
5
  require 'shoulda'
@@ -1,44 +1,91 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'helper'
2
4
  require 'iconv'
3
5
 
4
6
  class TestAttachments < Test::Unit::TestCase
5
- def setup
6
- @extract = Attachments::Extract.new [ "text/plain" ]
7
- @extract.parse "./test/data/mail_0001.eml"
8
- end
7
+ context "Parse test cases without crashes" do
8
+ setup do
9
+ @extract = Attachments::Extract.new [ "text/plain", "image/jpeg" ]
10
+ end
9
11
 
10
- def teardown
11
- @extract.close
12
- end
12
+ teardown do
13
+ @extract.close
14
+ end
13
15
 
14
- should "extract a part mail_001" do
15
- assert_equal(@extract.files.length, 1)
16
- end
16
+ should "parse text/plain + text/html" do
17
+ assert_nothing_raised do
18
+ @extract.parse "./test/data/mail_0001.eml"
19
+ end
20
+ end
17
21
 
18
- should "extract part of type text/plain" do
19
- assert_equal(@extract.files[0][:mime_type], "text/plain")
22
+ should "parse text/plain with UTF-8 and image/jpeg" do
23
+ assert_nothing_raised do
24
+ @extract.parse "./test/data/mail_0002.eml"
25
+ end
26
+ end
20
27
  end
21
28
 
22
- should "create files from the attachments" do
23
- @extract.files.each do |f|
24
- assert File::exists?(f[:tmpfile])
25
- puts f.inspect
29
+
30
+ context "Just text text/plain and text/html" do
31
+ setup do
32
+ @extract = Attachments::Extract.new [ "text/plain" ]
33
+ @extract.parse "./test/data/mail_0001.eml"
34
+ end
35
+
36
+ teardown do
37
+ @extract.close
38
+ end
39
+
40
+ should "extract a part mail_001" do
41
+ assert_equal(@extract.files.length, 1)
26
42
  end
27
- end
28
43
 
29
- should "remove tmp files on close" do
30
- tmpfile = @extract.files[0][:tmpfile]
31
- @extract.close
32
- assert !File::exists?(tmpfile)
44
+ should "extract part of type text/plain" do
45
+ assert_equal(@extract.files[0][:mime_type], "text/plain")
46
+ end
47
+
48
+ should "create files from the attachments" do
49
+ @extract.files.each do |f|
50
+ assert File::exists?(f[:tmpfile])
51
+ puts f.inspect
52
+ end
53
+ end
54
+
55
+ should "remove tmp files on close" do
56
+ tmpfile = @extract.files[0][:tmpfile]
57
+ @extract.close
58
+ assert !File::exists?(tmpfile)
59
+ end
60
+
61
+
62
+ should "save as text/plain as utf-8" do
63
+ tmpfile = @extract.files[0][:tmpfile]
64
+ m = File.read(tmpfile)
65
+ assert_nothing_raised do
66
+ # Provoke an exception if not valid utf-8
67
+ Iconv.conv("ISO-8859-1", "utf-8", m)
68
+ end
69
+ end
33
70
  end
34
71
 
72
+ context "UTF-8 and text/plain and image attachment" do
73
+ setup do
74
+ @extract = Attachments::Extract.new [ "text/plain", "image/jpeg" ]
75
+ @extract.parse "./test/data/mail_0002.eml"
76
+ end
35
77
 
36
- should "save as text/plain as utf-8" do
37
- tmpfile = @extract.files[0][:tmpfile]
38
- m = File.read(tmpfile)
39
- assert_nothing_raised do
40
- # Provoke an exception if not valid utf-8
41
- Iconv.conv("ISO-8859-1", "utf-8", m)
78
+ teardown do
79
+ @extract.close
80
+ end
81
+
82
+
83
+ should "not modify image" do
84
+ tmpfile = @extract.files[1][:tmpfile]
85
+
86
+ isIdentical = FileUtils::compare_file(tmpfile, "test/data/mail_0002.jpg")
87
+ assert(isIdentical)
42
88
  end
43
89
  end
44
90
  end
91
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attachments
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rune Myrland
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-14 00:00:00 +02:00
18
+ date: 2010-08-16 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -70,6 +70,8 @@ files:
70
70
  - lib/attachments/extract.rb
71
71
  - lib/attachments/filemagic.rb
72
72
  - test/data/mail_0001.eml
73
+ - test/data/mail_0002.eml
74
+ - test/data/mail_0002.jpg
73
75
  - test/helper.rb
74
76
  - test/test_attachments.rb
75
77
  has_rdoc: true