Commit 85a349c76fce607372bcb91bbf481256fbdc2392
1 parent
2fbcd1d3
Exists in
master
and in
29 other branches
Fix bug introduced by "Displaying image title at <title> tag"
(ActionItem1416)
Showing
6 changed files
with
40 additions
and
20 deletions
Show diff stats
app/helpers/folder_helper.rb
@@ -69,11 +69,4 @@ module FolderHelper | @@ -69,11 +69,4 @@ module FolderHelper | ||
69 | _('Edit folder') | 69 | _('Edit folder') |
70 | end | 70 | end |
71 | 71 | ||
72 | - def short_filename(filename, limit_chars = 43) | ||
73 | - return filename if filename.size <= limit_chars | ||
74 | - extname = File.extname(filename) | ||
75 | - basename = File.basename(filename,extname) | ||
76 | - str_complement = '(...)' | ||
77 | - return basename[0..(limit_chars - extname.size - str_complement.size - 1)] + str_complement + extname | ||
78 | - end | ||
79 | end | 72 | end |
app/models/uploaded_file.rb
@@ -4,9 +4,11 @@ | @@ -4,9 +4,11 @@ | ||
4 | # of the file itself is kept. (FIXME?) | 4 | # of the file itself is kept. (FIXME?) |
5 | class UploadedFile < Article | 5 | class UploadedFile < Article |
6 | 6 | ||
7 | + include Noosfero::Filenames | ||
8 | + | ||
7 | settings_items :title, :type => 'string' | 9 | settings_items :title, :type => 'string' |
8 | def title_with_default | 10 | def title_with_default |
9 | - title_without_default || name | 11 | + title_without_default || short_filename(name, 60) |
10 | end | 12 | end |
11 | alias_method_chain :title, :default | 13 | alias_method_chain :title, :default |
12 | 14 |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +module Noosfero::Filenames | ||
2 | + | ||
3 | + def short_filename(filename, limit_chars = 43) | ||
4 | + return filename if filename.size <= limit_chars | ||
5 | + extname = File.extname(filename) | ||
6 | + basename = File.basename(filename,extname) | ||
7 | + str_complement = '(...)' | ||
8 | + return basename[0..(limit_chars - extname.size - str_complement.size - 1)] + str_complement + extname | ||
9 | + end | ||
10 | + | ||
11 | +end |
test/unit/application_helper_test.rb
@@ -567,18 +567,6 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -567,18 +567,6 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
567 | assert_equal environment.theme, current_theme | 567 | assert_equal environment.theme, current_theme |
568 | end | 568 | end |
569 | 569 | ||
570 | - should 'trunc to 15 chars the big filename' do | ||
571 | - assert_equal 'AGENDA(...).mp3', short_filename('AGENDA_CULTURA_-_FESTA_DE_VAQUEIROS_PONTO_DE_SERRA_PRETA_BAIXA.mp3',15) | ||
572 | - end | ||
573 | - | ||
574 | - should 'trunc to default limit the big filename' do | ||
575 | - assert_equal 'AGENDA_CULTURA_-_FESTA_DE_VAQUEIRO(...).mp3', short_filename('AGENDA_CULTURA_-_FESTA_DE_VAQUEIROS_PONTO_DE_SERRA_PRETA_BAIXA.mp3') | ||
576 | - end | ||
577 | - | ||
578 | - should 'does not trunc short filename' do | ||
579 | - assert_equal 'filename.mp3', short_filename('filename.mp3') | ||
580 | - end | ||
581 | - | ||
582 | protected | 570 | protected |
583 | 571 | ||
584 | def url_for(args = {}) | 572 | def url_for(args = {}) |
@@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class NoosferoFilenamesTest < Test::Unit::TestCase | ||
4 | + | ||
5 | + include Noosfero::Filenames | ||
6 | + | ||
7 | + should 'trunc to 15 chars the big filename' do | ||
8 | + assert_equal 'AGENDA(...).mp3', short_filename('AGENDA_CULTURA_-_FESTA_DE_VAQUEIROS_PONTO_DE_SERRA_PRETA_BAIXA.mp3',15) | ||
9 | + end | ||
10 | + | ||
11 | + should 'trunc to default limit the big filename' do | ||
12 | + assert_equal 'AGENDA_CULTURA_-_FESTA_DE_VAQUEIRO(...).mp3', short_filename('AGENDA_CULTURA_-_FESTA_DE_VAQUEIROS_PONTO_DE_SERRA_PRETA_BAIXA.mp3') | ||
13 | + end | ||
14 | + | ||
15 | + should 'does not trunc short filename' do | ||
16 | + assert_equal 'filename.mp3', short_filename('filename.mp3') | ||
17 | + end | ||
18 | + | ||
19 | +end | ||
20 | + |
test/unit/uploaded_file_test.rb
@@ -150,4 +150,10 @@ class UploadedFileTest < Test::Unit::TestCase | @@ -150,4 +150,10 @@ class UploadedFileTest < Test::Unit::TestCase | ||
150 | assert_equal 'test.txt', upload.title | 150 | assert_equal 'test.txt', upload.title |
151 | end | 151 | end |
152 | 152 | ||
153 | + should 'use name as title by default but cut down the title' do | ||
154 | + upload = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/AGENDA_CULTURA_-_FESTA_DE_VAQUEIROS_PONTO_DE_SERRA_PRETA_BAIXA.txt')) | ||
155 | + upload.valid? | ||
156 | + assert_nil upload.errors[:title] | ||
157 | + end | ||
158 | + | ||
153 | end | 159 | end |