mms2r 1.1.8 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/mms2r.rb +1 -1
- data/lib/mms2r/media.rb +8 -4
- data/test/test_mms2r_media.rb +29 -0
- metadata +1 -1
data/History.txt
CHANGED
data/lib/mms2r.rb
CHANGED
data/lib/mms2r/media.rb
CHANGED
@@ -403,9 +403,7 @@ module MMS2R
|
|
403
403
|
# Helper to add a file to the media hash.
|
404
404
|
|
405
405
|
def add_file(type, file)
|
406
|
-
|
407
|
-
@media[type] = Array.new
|
408
|
-
end
|
406
|
+
@media[type] = [] unless @media[type]
|
409
407
|
@media[type] << file
|
410
408
|
end
|
411
409
|
|
@@ -549,8 +547,9 @@ module MMS2R
|
|
549
547
|
return nil if files.empty?
|
550
548
|
|
551
549
|
#get the largest file
|
552
|
-
file = nil # explicitly declare the file and
|
550
|
+
file = nil # explicitly declare the file and size
|
553
551
|
size = 0
|
552
|
+
mime_type = nil
|
554
553
|
|
555
554
|
files.each do |f|
|
556
555
|
# this will safely evaluate since we wouldn't be looking at
|
@@ -558,6 +557,11 @@ module MMS2R
|
|
558
557
|
if File.size(f) > size
|
559
558
|
size = File.size(f)
|
560
559
|
file = File.new(f)
|
560
|
+
# media is hash of types to arrays of file names
|
561
|
+
# detect on the hash returns an array, the 0th element is
|
562
|
+
# the mime type of the file that was found in the files array
|
563
|
+
# i.e. {'text/foo' => ['/foo/bar.txt', '/hello/world.txt']}
|
564
|
+
mime_type = media.detect{|k,v| v.detect{|fl| fl == f}}[0] rescue nil
|
561
565
|
end
|
562
566
|
end
|
563
567
|
|
data/test/test_mms2r_media.rb
CHANGED
@@ -374,6 +374,35 @@ class MMS2R::MediaTest < Test::Unit::TestCase
|
|
374
374
|
mms.purge
|
375
375
|
end
|
376
376
|
|
377
|
+
def test_get_attachment_should_return_duck_typed_file
|
378
|
+
|
379
|
+
mail = TMail::Mail.parse(load_mail('simple_image.mail').join)
|
380
|
+
mms = MMS2R::Media.create(mail)
|
381
|
+
mms.process
|
382
|
+
|
383
|
+
file_size = 43
|
384
|
+
base_name = 'spacer.gif'
|
385
|
+
mime_type = 'image/gif'
|
386
|
+
|
387
|
+
test = mms.media[mime_type].first
|
388
|
+
assert_not_nil test
|
389
|
+
assert_file_size test, file_size
|
390
|
+
assert File::exist?(test), "file #{test} does not exist"
|
391
|
+
assert_equal base_name, File.basename(test), "file #{test} does not exist as #{base_name}"
|
392
|
+
|
393
|
+
# get_media calls get_attachment and
|
394
|
+
# get_attachment should return a file that has some duck sauce for
|
395
|
+
# act_as_attachment and attachment_fu
|
396
|
+
file = mms.get_media
|
397
|
+
assert_not_nil file, "file #{file} does not exist"
|
398
|
+
assert_equal test, file.local_path
|
399
|
+
assert_equal base_name, file.original_filename
|
400
|
+
assert_equal file_size, file.size
|
401
|
+
assert_equal mime_type, file.content_type
|
402
|
+
|
403
|
+
mms.purge
|
404
|
+
end
|
405
|
+
|
377
406
|
def test_yaml_file_name
|
378
407
|
assert_equal 'mms2r_my_cingular_media_subject.yml', MMS2R::Media.yaml_file_name(MMS2R::MyCingularMedia,:subject)
|
379
408
|
assert_equal 'mms2r_t_mobile_media_subject.yml', MMS2R::Media.yaml_file_name(MMS2R::TMobileMedia,:subject)
|