Commit b4c854e1d4b4430a2c1eba25005342a55325b3e6
1 parent
a8a8780b
Exists in
master
and in
28 other branches
Move title to name on uploaded files
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,7 +2,6 @@ module CommentHelper | ||
| 2 | 2 | ||
| 3 | def article_title(article, args = {}) | 3 | def article_title(article, args = {}) |
| 4 | title = article.title | 4 | title = article.title |
| 5 | - title = article.display_title if article.kind_of?(UploadedFile) && article.image? | ||
| 6 | title = content_tag('h1', h(title), :class => 'title') | 5 | title = content_tag('h1', h(title), :class => 'title') |
| 7 | if article.belongs_to_blog? | 6 | if article.belongs_to_blog? |
| 8 | unless args[:no_link] | 7 | unless args[:no_link] |
app/helpers/content_viewer_helper.rb
| @@ -14,8 +14,7 @@ module ContentViewerHelper | @@ -14,8 +14,7 @@ module ContentViewerHelper | ||
| 14 | end | 14 | end |
| 15 | 15 | ||
| 16 | def article_title(article, args = {}) | 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 | title = content_tag('h1', h(title), :class => 'title') | 18 | title = content_tag('h1', h(title), :class => 'title') |
| 20 | if article.belongs_to_blog? || article.belongs_to_forum? | 19 | if article.belongs_to_blog? || article.belongs_to_forum? |
| 21 | unless args[:no_link] | 20 | unless args[:no_link] |
app/models/uploaded_file.rb
| @@ -12,15 +12,12 @@ class UploadedFile < Article | @@ -12,15 +12,12 @@ class UploadedFile < Article | ||
| 12 | 12 | ||
| 13 | include ShortFilename | 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 | end | 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 | sanitize_filename | 22 | sanitize_filename |
| 26 | 23 | ||
| @@ -32,10 +29,6 @@ class UploadedFile < Article | @@ -32,10 +29,6 @@ class UploadedFile < Article | ||
| 32 | self.image? ? self.full_filename(:display).gsub(File.join(RAILS_ROOT, 'public'), '') : nil | 29 | self.image? ? self.full_filename(:display).gsub(File.join(RAILS_ROOT, 'public'), '') : nil |
| 33 | end | 30 | end |
| 34 | 31 | ||
| 35 | - def display_title | ||
| 36 | - title.blank? ? name : title | ||
| 37 | - end | ||
| 38 | - | ||
| 39 | def first_paragraph | 32 | def first_paragraph |
| 40 | '' | 33 | '' |
| 41 | end | 34 | end |
db/migrate/20140221142304_move_title_virtual_field_to_name_in_uploaded_file.rb
0 → 100644
| @@ -0,0 +1,12 @@ | @@ -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,24 +119,13 @@ class UploadedFileTest < ActiveSupport::TestCase | ||
| 119 | assert_equal 'my title', UploadedFile.new(:title => 'my title').title | 119 | assert_equal 'my title', UploadedFile.new(:title => 'my title').title |
| 120 | end | 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 | should 'always provide a display title' do | 122 | should 'always provide a display title' do |
| 134 | upload = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | 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 | upload.title = 'My text file' | 125 | upload.title = 'My text file' |
| 137 | - assert_equal 'My text file', upload.display_title | 126 | + assert_equal 'My text file', upload.title |
| 138 | upload.title = '' | 127 | upload.title = '' |
| 139 | - assert_equal 'test.txt', upload.display_title | 128 | + assert_equal 'test.txt', upload.title |
| 140 | end | 129 | end |
| 141 | 130 | ||
| 142 | should 'use name as title by default' do | 131 | should 'use name as title by default' do |