summaryrefslogtreecommitdiffhomepage
path: root/test/drawing/tc_pic.rb
diff options
context:
space:
mode:
authormarc <[email protected]>2015-07-03 16:44:45 +0200
committermarc <[email protected]>2015-07-03 16:44:45 +0200
commitc7c7937dcde9a94f2e5ee0549451b34e410803e0 (patch)
treed06ccd49055e1474891a6b3d3d190e457e7e2304 /test/drawing/tc_pic.rb
parent1bec39cebaef6a98481f52587ecc0483b4defc08 (diff)
downloadcaxlsx-c7c7937dcde9a94f2e5ee0549451b34e410803e0.tar.gz
caxlsx-c7c7937dcde9a94f2e5ee0549451b34e410803e0.zip
Validates whether an image is acceptable through mime type
image/jpeg, image/png & image/gif are considered the allowed mime types for an image. mimemagic gem is added as dependency in order to do the checking. Added tests to check against three supported mime types. A fake jpg fixture (created with 'touch' command) has been added to test that extension is no longer used.
Diffstat (limited to 'test/drawing/tc_pic.rb')
-rw-r--r--test/drawing/tc_pic.rb14
1 files changed, 9 insertions, 5 deletions
diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb
index 3cea49c0..066d9962 100644
--- a/test/drawing/tc_pic.rb
+++ b/test/drawing/tc_pic.rb
@@ -5,7 +5,10 @@ class TestPic < Test::Unit::TestCase
def setup
@p = Axlsx::Package.new
ws = @p.workbook.add_worksheet
- @test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
+ @test_img = @test_img_jpg = File.dirname(__FILE__) + "/../../examples/image1.jpeg"
+ @test_img_png = File.dirname(__FILE__) + "/../../examples/image1.png"
+ @test_img_gif = File.dirname(__FILE__) + "/../../examples/image1.gif"
+ @test_img_fake = File.dirname(__FILE__) + "/../../examples/image1_fake.jpg"
@test_img_up = File.dirname(__FILE__) + "/../../examples/IMAGE1UP.JPEG"
@image = ws.add_image :image_src => @test_img, :hyperlink => 'https://github.com/randym', :tooltip => "What's up doc?"
end
@@ -70,11 +73,12 @@ class TestPic < Test::Unit::TestCase
end
def test_image_src
- assert_raise(ArgumentError) { @image.image_src = 49 }
- assert_raise(ArgumentError) { @image.image_src = 'Unknown' }
assert_raise(ArgumentError) { @image.image_src = __FILE__ }
- assert_nothing_raised { @image.image_src = @test_img }
- assert_equal(@image.image_src, @test_img)
+ assert_raise(ArgumentError) { @image.image_src = @test_img_fake }
+ assert_nothing_raised { @image.image_src = @test_img_gif }
+ assert_nothing_raised { @image.image_src = @test_img_png }
+ assert_nothing_raised { @image.image_src = @test_img_jpg }
+ assert_equal(@image.image_src, @test_img_jpg)
end
def test_image_src_downcase