Displays thumbnails of attached images of the issue view (#1006).

This behaviour can be turned on/off in Settings -> Display (off by default). Thumbnail size can be configured there too.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9933 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2012-07-07 13:48:07 +00:00
parent b0bd506201
commit a0c495b953
20 changed files with 253 additions and 7 deletions

View File

@@ -252,12 +252,58 @@ class AttachmentsControllerTest < ActionController::TestCase
set_tmp_attachments_directory
end
def test_anonymous_on_private_private
def test_download_should_be_denied_without_permission
get :download, :id => 7
assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
set_tmp_attachments_directory
end
if convert_installed?
def test_thumbnail
Attachment.clear_thumbnails
@request.session[:user_id] = 2
with_settings :thumbnails_enabled => '1' do
get :thumbnail, :id => 16
assert_response :success
assert_equal 'image/png', response.content_type
end
end
def test_thumbnail_should_return_404_for_non_image_attachment
@request.session[:user_id] = 2
with_settings :thumbnails_enabled => '1' do
get :thumbnail, :id => 15
assert_response 404
end
end
def test_thumbnail_should_return_404_if_thumbnails_not_enabled
@request.session[:user_id] = 2
with_settings :thumbnails_enabled => '0' do
get :thumbnail, :id => 16
assert_response 404
end
end
def test_thumbnail_should_return_404_if_thumbnail_generation_failed
Attachment.any_instance.stubs(:thumbnail).returns(nil)
@request.session[:user_id] = 2
with_settings :thumbnails_enabled => '1' do
get :thumbnail, :id => 16
assert_response 404
end
end
def test_thumbnail_should_be_denied_without_permission
with_settings :thumbnails_enabled => '1' do
get :thumbnail, :id => 16
assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
end
end
else
puts '(ImageMagick convert not available)'
end
def test_destroy_issue_attachment
set_tmp_attachments_directory
issue = Issue.find(3)

View File

@@ -1155,7 +1155,33 @@ class IssuesControllerTest < ActionController::TestCase
end
end
end
def test_show_with_thumbnails_enabled_should_display_thumbnails
@request.session[:user_id] = 2
with_settings :thumbnails_enabled => '1' do
get :show, :id => 14
assert_response :success
end
assert_select 'div.thumbnails' do
assert_select 'a[href=/attachments/16/testfile.png]' do
assert_select 'img[src=/attachments/thumbnail/16]'
end
end
end
def test_show_with_thumbnails_disabled_should_not_display_thumbnails
@request.session[:user_id] = 2
with_settings :thumbnails_enabled => '0' do
get :show, :id => 14
assert_response :success
end
assert_select 'div.thumbnails', 0
end
def test_show_with_multi_custom_field
field = CustomField.find(1)
field.update_attribute :multiple, true

View File

@@ -45,6 +45,10 @@ class RoutingAttachmentsTest < ActionController::IntegrationTest
{ :controller => 'attachments', :action => 'download', :id => '1',
:filename => 'filename.ext' }
)
assert_routing(
{ :method => 'get', :path => "/attachments/thumbnail/1" },
{ :controller => 'attachments', :action => 'thumbnail', :id => '1' }
)
assert_routing(
{ :method => 'delete', :path => "/attachments/1" },
{ :controller => 'attachments', :action => 'destroy', :id => '1' }

View File

@@ -128,6 +128,13 @@ class ActiveSupport::TestCase
return nil
end
def self.convert_installed?
bin = Redmine::Configuration['imagemagick_convert_command'] || 'convert'
system("#{bin} -version")
rescue
false
end
# Returns the path to the test +vendor+ repository
def self.repository_path(vendor)
Rails.root.join("tmp/test/#{vendor.downcase}_repository").to_s

View File

@@ -214,4 +214,28 @@ class AttachmentTest < ActiveSupport::TestCase
set_tmp_attachments_directory
end
def test_thumbnailable_should_be_true_for_images
assert_equal true, Attachment.new(:filename => 'test.jpg').thumbnailable?
end
def test_thumbnailable_should_be_true_for_non_images
assert_equal false, Attachment.new(:filename => 'test.txt').thumbnailable?
end
if convert_installed?
def test_thumbnail_should_generate_the_thumbnail
set_fixtures_attachments_directory
attachment = Attachment.find(16)
Attachment.clear_thumbnails
assert_difference "Dir.glob(File.join(Attachment.thumbnails_storage_path, '*.thumb')).size" do
thumbnail = attachment.thumbnail
assert_equal "16_8e0294de2441577c529f170b6fb8f638_100.thumb", File.basename(thumbnail)
assert File.exists?(thumbnail)
end
end
else
puts '(ImageMagick convert not available)'
end
end