From 6080e3a2c06a44d8972e186dda50e7ea89de03d8 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 18 Dec 2018 14:55:09 -0500 Subject: [PATCH] FIX: Broken spec --- app/models/optimized_image.rb | 15 ++++++++++++++- spec/models/upload_spec.rb | 1 - 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rb index a80103c7b44..01f870baa6b 100644 --- a/app/models/optimized_image.rb +++ b/app/models/optimized_image.rb @@ -174,7 +174,20 @@ class OptimizedImage < ActiveRecord::Base IM_DECODERS ||= /\A(jpe?g|png|tiff?|bmp|ico|gif)\z/i def self.prepend_decoder!(path, ext_path = nil, opts = nil) - extension = File.extname((opts && opts[:filename]) || path || ext_path)[1..-1] + opts ||= {} + + # This logic is a little messy but the result of using mocks for most + # of the image tests. The idea here is you shouldn't trust the "original" + # path of a file to figure out its extension. However, in certain cases + # such as generating the loading upload thumbnail, we force the format, + # and this allows us to use the forced format in that case. + extension = nil + if (opts[:format] && path != ext_path) + extension = File.extname(path)[1..-1] + else + extension = File.extname(opts[:filename] || ext_path || path)[1..-1] + end + raise Discourse::InvalidAccess if !extension || !extension.match?(IM_DECODERS) "#{extension}:#{path}" end diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index 6e64ee82b62..aba1b21c02d 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -43,7 +43,6 @@ describe Upload do upload.reload expect(upload.optimized_images.count).to eq(1) end - end it "can reconstruct dimensions on demand" do