diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rb index 137679455..5df84700e 100644 --- a/app/models/optimized_image.rb +++ b/app/models/optimized_image.rb @@ -36,7 +36,7 @@ class OptimizedImage < ActiveRecord::Base FileUtils.cp(original_path, temp_path) resized = true else - resized = resize(original_path, temp_path, width, height) + resized = resize(original_path, temp_path, width, height, opts[:allow_animation]) end if resized @@ -78,8 +78,8 @@ class OptimizedImage < ActiveRecord::Base end end - def self.resize(from, to, width, height) - from << "[0]" unless opts[:allow_animation] + def self.resize(from, to, width, height, allow_animation=false) + from << "[0]" unless allow_animation # NOTE: ORDER is important! instructions = %W{ #{from} diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index b58bc3379..57af1276d 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -181,9 +181,9 @@ class CookedPostProcessor informations = "#{original_width}x#{original_height}" informations << " #{number_to_human_size(upload.filesize)}" if upload - a["title"] = filename + a["title"] = img["title"] || filename - meta.add_child create_span_node("filename", filename) + meta.add_child create_span_node("filename", img["title"] || filename) meta.add_child create_span_node("informations", informations) meta.add_child create_span_node("expand") end diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index fd8ba3a73..ae90bf356 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -98,6 +98,33 @@ describe CookedPostProcessor do end + context "with title" do + + let(:upload) { Fabricate(:upload) } + let(:post) { build(:post_with_large_image_and_title) } + let(:cpp) { CookedPostProcessor.new(post) } + + before do + SiteSetting.max_image_height = 2000 + SiteSetting.create_thumbnails = true + + Upload.expects(:get_from_url).returns(upload) + FastImage.stubs(:size).returns([1000, 2000]) + + # hmmm this should be done in a cleaner way + OptimizedImage.expects(:resize).returns(true) + end + + it "generates overlay information" do + cpp.post_process_images + cpp.html.should match_html '' + cpp.should be_dirty + end + + end + context "topic image" do let(:topic) { build(:topic, id: 1) } diff --git a/spec/fabricators/post_fabricator.rb b/spec/fabricators/post_fabricator.rb index 2ff3bb792..cab02e02e 100644 --- a/spec/fabricators/post_fabricator.rb +++ b/spec/fabricators/post_fabricator.rb @@ -76,6 +76,10 @@ Fabricator(:post_with_large_image, from: :post) do cooked '' end +Fabricator(:post_with_large_image_and_title, from: :post) do + cooked '' +end + Fabricator(:post_with_uploads, from: :post) do cooked ' Link