Project

General

Profile

Actions

Patch #13688

closed

Chosen thumbnail has to be bigger than requested one and not smaller

Patch #13688: Chosen thumbnail has to be bigger than requested one and not smaller

Added by Stanislav German-Evtushenko over 13 years ago. Updated almost 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Attachments
Target version:

Description

Currently thumbnail request with a size of 99 will provide an image of 50px.
Currently thumbnail request with a size of 149 will provide an image of 100px.
And one exception: thumbnail request with a size of 49 and less will provide an image of 100px.

Provided image has to be bigger then requested and not smaller, for example:
request from 1 to 50 -> 50px
from 51 to 100 -> 100px
from 101 to 150 -> 150px
etc

small patch that makes this change is attached


Files

Updated by Stanislav German-Evtushenko over 13 years ago Actions #1

Before patch applied:
  • from 0 to 49 -> 100px
  • from 50 to 99 -> 50px
  • from 100 to 149 -> 100px
  • from 140 to 199 -> 150px
  • ...
After patch applied:
  • 0 -> 100px
  • from 1 to 50 -> 50px
  • from 51 to 100 -> 100px
  • from 101 to 150 -> 150px
    from 151 to 200 -> 200px
    ...

Updated by Toshi MARUYAMA over 13 years ago Actions #2

  • Category set to Attachments

Updated by Jens Krämer almost 8 years ago Actions #3

Here's an alternative patch using Float#ceil. Also adds a corresponding test case.

Updated by Go MAEDA almost 8 years ago Actions #4

  • Target version set to Candidate for next major release

Updated by Go MAEDA almost 8 years ago Actions #5

  • Status changed from New to Needs feedback

The following error occurred while running tests. Jens, could you check the patch?

Failure:
AttachmentsControllerTest#test_thumbnail_should_round_size [/home/ubuntu/redmine-trunk/app/models/attachment.rb:222]:
unexpected invocation: Redmine::Thumbnail.generate("/home/ubuntu/redmine-trunk/test/fixtures/files/2010/11/101123161450_testfile_1.png", "/home/ubuntu/redmine-trunk/tmp/thumbnails/16_8e0294de2441577c529f170b6fb8f638_300.thumb", 300)
unsatisfied expectations:
- expected exactly once, not yet invoked: Redmine::Thumbnail.generate()

bin/rails test test/functional/attachments_controller_test.rb:409

This is my environment:

Environment:
  Redmine version                4.0.0.devel.17734
  Ruby version                   2.6.0-p-1 (2018-12-06) [x86_64-linux]
  Rails version                  5.2.2
  Environment                    development
  Database adapter               SQLite
  Mailer queue                   ActiveJob::QueueAdapters::AsyncAdapter
  Mailer delivery                smtp
SCM:
  Subversion                     1.9.3
  Mercurial                      3.7.3
  Cvs                            1.12.13
  Bazaar                         2.7.0
  Git                            2.7.4
  Filesystem
Redmine plugins:
  no plugin installed

Updated by Marius BĂLTEANU almost 8 years ago Actions #6

Applying the below patch on top over Jens patch fixes the test.

diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb
index 4bab579..bccb2c6 100644
--- a/test/unit/attachment_test.rb
+++ b/test/unit/attachment_test.rb
@@ -494,7 +494,7 @@ class AttachmentTest < ActiveSupport::TestCase
         [101, 150],
       ].each do |size, generated_size|
         thumbnail = attachment.thumbnail(size: size)
-        assert_equal "16_8e0294de2441577c529f170b6fb8f638_#{generated_size}.thumb",
+        assert_equal "8e0294de2441577c529f170b6fb8f638_2654_#{generated_size}.thumb",
           File.basename(thumbnail)
       end
     end
The thumbnail format is #{digest}_#{filesize}_#{size}.thumb where:
  • digest is 8e0294de2441577c529f170b6fb8f638
  • filesize is 2654
  • size is the generated size which changes during the test.

Updated by Go MAEDA almost 8 years ago Actions #7

  • Status changed from Needs feedback to New
  • Target version changed from Candidate for next major release to 4.1.0

Confirmed that the test passes after applying the patch written by Marius. Setting the target version to 4.1.0.

Updated by Go MAEDA almost 8 years ago Actions #8

  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Committed the patch. Thank you for your contribution.

Updated by Marius BĂLTEANU almost 8 years ago Actions #9

  • Status changed from Closed to Reopened

To fix the tests:

diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb
index cf7e961..faaf462 100644
--- a/test/functional/attachments_controller_test.rb
+++ b/test/functional/attachments_controller_test.rb
@@ -407,7 +407,7 @@ class AttachmentsControllerTest < Redmine::ControllerTest
     end

     def test_thumbnail_should_round_size
-      Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
+      Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 300}

Updated by Go MAEDA almost 8 years ago Actions #10

  • Status changed from Reopened to Closed

Marius BALTEANU wrote:

To fix the tests:

[...]

Committed. Thanks.

Actions

Also available in: PDF Atom