Commit 34e20505febcaece8d34a9a2c86cda2d129a5940
Exists in
master
and in
29 other branches
Merge branch 'stable'
Showing
7 changed files
with
55 additions
and
21 deletions
Show diff stats
app/helpers/folder_helper.rb
1 | module FolderHelper | 1 | module FolderHelper |
2 | 2 | ||
3 | + include Noosfero::Filenames | ||
4 | + | ||
3 | def list_articles(articles, recursive = false) | 5 | def list_articles(articles, recursive = false) |
4 | if !articles.blank? | 6 | if !articles.blank? |
5 | content_tag( | 7 | content_tag( |
@@ -69,11 +71,4 @@ module FolderHelper | @@ -69,11 +71,4 @@ module FolderHelper | ||
69 | _('Edit folder') | 71 | _('Edit folder') |
70 | end | 72 | end |
71 | 73 | ||
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 | 74 | 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 |
lib/tasks/test.rake
1 | -task :default => [:test, :cucumber, :selenium] | 1 | +Rake::Task[:test].clear |
2 | + | ||
3 | +task :test do | ||
4 | + errors = %w(test:units test:functionals test:integration cucumber selenium).collect do |task| | ||
5 | + begin | ||
6 | + Rake::Task[task].invoke | ||
7 | + nil | ||
8 | + rescue => e | ||
9 | + task | ||
10 | + end | ||
11 | + end.compact | ||
12 | + abort "Errors running #{errors.to_sentence}!" if errors.any? | ||
13 | +end | ||
2 | 14 | ||
3 | desc 'Runs Seleniun acceptance tests' | 15 | desc 'Runs Seleniun acceptance tests' |
4 | task :selenium do | 16 | task :selenium do |
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 |