diff --git a/app/models/topic.rb b/app/models/topic.rb index d78533fcd8b..c47d457fe5d 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -52,7 +52,7 @@ class Topic < ActiveRecord::Base def thumbnail_info(enqueue_if_missing: false, extra_sizes: []) return nil unless original = image_upload - return nil unless original.filesize < SiteSetting.max_image_size_kb + return nil unless original.filesize < SiteSetting.max_image_size_kb.kilobytes return nil unless original.read_attribute(:width) && original.read_attribute(:height) infos = [] @@ -95,7 +95,7 @@ class Topic < ActiveRecord::Base def generate_thumbnails!(extra_sizes: []) return nil unless SiteSetting.create_thumbnails return nil unless original = image_upload - return nil unless original.filesize < SiteSetting.max_image_size_kb + return nil unless original.filesize < SiteSetting.max_image_size_kb.kilobytes return nil unless original.width && original.height extra_sizes = [] unless extra_sizes.kind_of?(Array) @@ -113,7 +113,7 @@ class Topic < ActiveRecord::Base if thumbnail.nil? && image_upload && SiteSetting.create_thumbnails && - image_upload.filesize < SiteSetting.max_image_size_kb && + image_upload.filesize < SiteSetting.max_image_size_kb.kilobytes && enqueue_if_missing && Discourse.redis.set(thumbnail_job_redis_key([]), 1, nx: true, ex: 1.minute) Jobs.enqueue(:generate_topic_thumbnails, { topic_id: id }) diff --git a/spec/models/topic_thumbnail_spec.rb b/spec/models/topic_thumbnail_spec.rb index 92481241c4a..ab7ff72467f 100644 --- a/spec/models/topic_thumbnail_spec.rb +++ b/spec/models/topic_thumbnail_spec.rb @@ -4,10 +4,10 @@ require 'rails_helper' describe "TopicThumbnail" do let(:upload1) { Fabricate(:image_upload, width: 5000, height: 5000) } let(:topic) { Fabricate(:topic, image_upload: upload1) } - - let(:upload2) { Fabricate(:image_upload, width: 5000, height: 5000, filesize: 8000) } + let(:upload2) { Fabricate(:image_upload, width: 5000, height: 5000) } let(:topic2) { Fabricate(:topic, image_upload: upload2) } + before do SiteSetting.create_thumbnails = true topic.generate_thumbnails!(extra_sizes: nil) @@ -19,6 +19,7 @@ describe "TopicThumbnail" do end it "does not enque job if original image is too large" do + upload2.filesize = SiteSetting.max_image_size_kb.kilobytes + 1 SiteSetting.create_thumbnails = true topic2.generate_thumbnails!(extra_sizes: nil)