diff --git a/Gemfile b/Gemfile index 68b608248..afb3dfb7f 100644 --- a/Gemfile +++ b/Gemfile @@ -40,7 +40,7 @@ gem 'bcrypt-ruby', :require => "bcrypt" gem 'aws-s3', :require => "aws/s3" gem 'awesome_print' gem 'statistics2' -gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git" +gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes" group :production do gem 'unicorn', :platforms => :ruby diff --git a/Gemfile.lock b/Gemfile.lock index e4aceb911..05e3541bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -25,7 +25,8 @@ GIT GIT remote: https://github.com/r888888888/ruby-imagespec.git - revision: 41859ac5808cd64f2385082171ee2cc9f80bfcd1 + revision: 2dab9811f4abb4fbaeea66feb42e388ba545b2d8 + branch: exif-fixes specs: ruby-imagespec (0.3.1) diff --git a/test/factories/upload.rb b/test/factories/upload.rb index 7aa0b5f43..ca7071479 100644 --- a/test/factories/upload.rb +++ b/test/factories/upload.rb @@ -22,6 +22,22 @@ FactoryGirl.define do end end + factory(:exif_jpg_upload) do + content_type "image/jpeg" + file_path do + FileUtils.cp("#{Rails.root}/test/files/test-exif-small.jpg", "#{Rails.root}/tmp") + "#{Rails.root}/tmp/test-exif-small.jpg" + end + end + + factory(:blank_jpg_upload) do + content_type "image/jpeg" + file_path do + FileUtils.cp("#{Rails.root}/test/files/test-blank.jpg", "#{Rails.root}/tmp") + "#{Rails.root}/tmp/test-blank.jpg" + end + end + factory(:large_jpg_upload) do file_ext "jpg" content_type "image/jpeg" diff --git a/test/files/test-blank.jpg b/test/files/test-blank.jpg new file mode 100644 index 000000000..05ba89580 Binary files /dev/null and b/test/files/test-blank.jpg differ diff --git a/test/files/test-exif-small.jpg b/test/files/test-exif-small.jpg new file mode 100644 index 000000000..7169cd4d1 Binary files /dev/null and b/test/files/test-exif-small.jpg differ diff --git a/test/unit/upload_test.rb b/test/unit/upload_test.rb index a8324810a..831ed739f 100644 --- a/test/unit/upload_test.rb +++ b/test/unit/upload_test.rb @@ -69,13 +69,27 @@ class UploadTest < ActiveSupport::TestCase assert_equal(756, @upload.image_height) end - should "discover the dimensions for a JPG" do + should "discover the dimensions for a JPG with JFIF data" do @upload = FactoryGirl.create(:jpg_upload) assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)} assert_equal(500, @upload.image_width) assert_equal(335, @upload.image_height) end + should "discover the dimensions for a JPG with EXIF data" do + @upload = FactoryGirl.create(:exif_jpg_upload) + assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)} + assert_equal(529, @upload.image_width) + assert_equal(600, @upload.image_height) + end + + should "discover the dimensions for a JPG with no header data" do + @upload = FactoryGirl.create(:blank_jpg_upload) + assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)} + assert_equal(668, @upload.image_width) + assert_equal(996, @upload.image_height) + end + should "discover the dimensions for a PNG" do @upload = FactoryGirl.create(:png_upload) assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)}