Commit b6679024cf4e85f4b460612f1f379c8d0360a587
Exists in
master
and in
29 other branches
Merge branch 'ai2979' into 'stable'
Order images in galleries by image name http://noosfero.org/Development/ActionItem2979
Showing
5 changed files
with
21 additions
and
29 deletions
Show diff stats
app/helpers/comment_helper.rb
... | ... | @@ -2,7 +2,6 @@ module CommentHelper |
2 | 2 | |
3 | 3 | def article_title(article, args = {}) |
4 | 4 | title = article.title |
5 | - title = article.display_title if article.kind_of?(UploadedFile) && article.image? | |
6 | 5 | title = content_tag('h1', h(title), :class => 'title') |
7 | 6 | if article.belongs_to_blog? |
8 | 7 | unless args[:no_link] | ... | ... |
app/helpers/content_viewer_helper.rb
... | ... | @@ -14,8 +14,7 @@ module ContentViewerHelper |
14 | 14 | end |
15 | 15 | |
16 | 16 | def article_title(article, args = {}) |
17 | - title = article.display_title if article.kind_of?(UploadedFile) && article.image? | |
18 | - title = article.title if title.blank? | |
17 | + title = article.title | |
19 | 18 | title = content_tag('h1', h(title), :class => 'title') |
20 | 19 | if article.belongs_to_blog? || article.belongs_to_forum? |
21 | 20 | unless args[:no_link] | ... | ... |
app/models/uploaded_file.rb
... | ... | @@ -12,15 +12,12 @@ class UploadedFile < Article |
12 | 12 | |
13 | 13 | include ShortFilename |
14 | 14 | |
15 | - settings_items :title, :type => 'string' | |
16 | - xss_terminate :only => [ :title ] | |
17 | - | |
18 | - def title_with_default | |
19 | - title_without_default || short_filename(name, 60) | |
15 | + def title | |
16 | + if self.name.present? then self.name else self.filename end | |
17 | + end | |
18 | + def title= value | |
19 | + self.name = value | |
20 | 20 | end |
21 | - alias_method_chain :title, :default | |
22 | - | |
23 | - validates_size_of :title, :maximum => 60, :if => (lambda { |file| !file.title.blank? }) | |
24 | 21 | |
25 | 22 | sanitize_filename |
26 | 23 | |
... | ... | @@ -32,10 +29,6 @@ class UploadedFile < Article |
32 | 29 | self.image? ? self.full_filename(:display).gsub(File.join(RAILS_ROOT, 'public'), '') : nil |
33 | 30 | end |
34 | 31 | |
35 | - def display_title | |
36 | - title.blank? ? name : title | |
37 | - end | |
38 | - | |
39 | 32 | def first_paragraph |
40 | 33 | '' |
41 | 34 | end | ... | ... |
db/migrate/20140221142304_move_title_virtual_field_to_name_in_uploaded_file.rb
0 → 100644
... | ... | @@ -0,0 +1,12 @@ |
1 | +class MoveTitleVirtualFieldToNameInUploadedFile < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + UploadedFile.find_each do |uploaded_file| | |
4 | + uploaded_file.name = uploaded_file.setting.delete :title | |
5 | + uploaded_file.send :update_without_callbacks | |
6 | + end | |
7 | + end | |
8 | + | |
9 | + def self.down | |
10 | + say "this migration can't be reverted" | |
11 | + end | |
12 | +end | ... | ... |
test/unit/uploaded_file_test.rb
... | ... | @@ -119,24 +119,13 @@ class UploadedFileTest < ActiveSupport::TestCase |
119 | 119 | assert_equal 'my title', UploadedFile.new(:title => 'my title').title |
120 | 120 | end |
121 | 121 | |
122 | - should 'limit title to 140 characters' do | |
123 | - upload = UploadedFile.new | |
124 | - | |
125 | - upload.title = '+' * 61; upload.valid? | |
126 | - assert upload.errors[:title] | |
127 | - | |
128 | - upload.title = '+' * 60; upload.valid? | |
129 | - assert !upload.errors[:title] | |
130 | - | |
131 | - end | |
132 | - | |
133 | 122 | should 'always provide a display title' do |
134 | 123 | upload = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) |
135 | - assert_equal 'test.txt', upload.display_title | |
124 | + assert_equal 'test.txt', upload.title | |
136 | 125 | upload.title = 'My text file' |
137 | - assert_equal 'My text file', upload.display_title | |
126 | + assert_equal 'My text file', upload.title | |
138 | 127 | upload.title = '' |
139 | - assert_equal 'test.txt', upload.display_title | |
128 | + assert_equal 'test.txt', upload.title | |
140 | 129 | end |
141 | 130 | |
142 | 131 | should 'use name as title by default' do | ... | ... |