Project

General

Profile

Actions

Patch #13688

closed

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

Added by Stanislav German-Evtushenko almost 11 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Attachments
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

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

Actions #1

Updated by Stanislav German-Evtushenko almost 11 years ago

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
    ...
Actions #2

Updated by Toshi MARUYAMA almost 11 years ago

  • Category set to Attachments
Actions #3

Updated by Jens Krämer over 5 years ago

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

Actions #4

Updated by Go MAEDA over 5 years ago

  • Target version set to Candidate for next major release
Actions #5

Updated by Go MAEDA over 5 years ago

  • 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

Actions #6

Updated by Marius BĂLTEANU about 5 years ago

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.
Actions #7

Updated by Go MAEDA about 5 years ago

  • 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.

Actions #8

Updated by Go MAEDA about 5 years ago

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

Committed the patch. Thank you for your contribution.

Actions #9

Updated by Marius BĂLTEANU about 5 years ago

  • 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}
Actions #10

Updated by Go MAEDA about 5 years ago

  • Status changed from Reopened to Closed

Marius BALTEANU wrote:

To fix the tests:

[...]

Committed. Thanks.

Actions

Also available in: Atom PDF