Adds a macro for inserting thumbnails in formatted text (#3510).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10013 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -262,43 +262,44 @@ class AttachmentsControllerTest < ActionController::TestCase
|
||||
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
|
||||
|
||||
get :thumbnail, :id => 16
|
||||
assert_response :success
|
||||
assert_equal 'image/png', response.content_type
|
||||
end
|
||||
|
||||
def test_thumbnail_should_not_exceed_maximum_size
|
||||
Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800}
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
get :thumbnail, :id => 16, :size => 2000
|
||||
end
|
||||
|
||||
def test_thumbnail_should_round_size
|
||||
Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
|
||||
|
||||
@request.session[:user_id] = 2
|
||||
get :thumbnail, :id => 16, :size => 260
|
||||
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
|
||||
get :thumbnail, :id => 15
|
||||
assert_response 404
|
||||
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
|
||||
|
||||
get :thumbnail, :id => 16
|
||||
assert_response 404
|
||||
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
|
||||
get :thumbnail, :id => 16
|
||||
assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
|
||||
end
|
||||
else
|
||||
puts '(ImageMagick convert not available)'
|
||||
|
||||
@@ -49,6 +49,10 @@ class RoutingAttachmentsTest < ActionController::IntegrationTest
|
||||
{ :method => 'get', :path => "/attachments/thumbnail/1" },
|
||||
{ :controller => 'attachments', :action => 'thumbnail', :id => '1' }
|
||||
)
|
||||
assert_routing(
|
||||
{ :method => 'get', :path => "/attachments/thumbnail/1/200" },
|
||||
{ :controller => 'attachments', :action => 'thumbnail', :id => '1', :size => '200' }
|
||||
)
|
||||
assert_routing(
|
||||
{ :method => 'delete', :path => "/attachments/1" },
|
||||
{ :controller => 'attachments', :action => 'destroy', :id => '1' }
|
||||
|
||||
@@ -119,4 +119,24 @@ class Redmine::WikiFormatting::MacrosTest < ActionView::TestCase
|
||||
def test_macro_child_pages_without_wiki_page_should_fail
|
||||
assert_match /can be called from wiki pages only/, textilizable("{{child_pages}}")
|
||||
end
|
||||
|
||||
def test_macro_thumbnail
|
||||
assert_equal '<p><a href="/attachments/17" class="thumbnail" title="testfile.PNG"><img alt="testfile.PNG" src="/attachments/thumbnail/17" /></a></p>',
|
||||
textilizable("{{thumbnail(testfile.png)}}", :object => Issue.find(14))
|
||||
end
|
||||
|
||||
def test_macro_thumbnail_with_size
|
||||
assert_equal '<p><a href="/attachments/17" class="thumbnail" title="testfile.PNG"><img alt="testfile.PNG" src="/attachments/thumbnail/17/200" /></a></p>',
|
||||
textilizable("{{thumbnail(testfile.png, size=200)}}", :object => Issue.find(14))
|
||||
end
|
||||
|
||||
def test_macro_thumbnail_with_title
|
||||
assert_equal '<p><a href="/attachments/17" class="thumbnail" title="Cool image"><img alt="testfile.PNG" src="/attachments/thumbnail/17" /></a></p>',
|
||||
textilizable("{{thumbnail(testfile.png, title=Cool image)}}", :object => Issue.find(14))
|
||||
end
|
||||
|
||||
def test_macro_thumbnail_with_invalid_filename_should_fail
|
||||
assert_include 'test.png not found',
|
||||
textilizable("{{thumbnail(test.png)}}", :object => Issue.find(14))
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user